1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.archive.util;
24
25 /***
26 * CharSequence that noticed thread interrupts -- as might be necessary
27 * to recover from a loose regex on unexpected challenging input.
28 *
29 * @author gojomo
30 */
31 public class InterruptibleCharSequence implements CharSequence {
32 CharSequence inner;
33
34
35 public InterruptibleCharSequence(CharSequence inner) {
36 super();
37 this.inner = inner;
38 }
39
40 public char charAt(int index) {
41 if (Thread.interrupted()) {
42 throw new RuntimeException(new InterruptedException());
43 }
44
45 return inner.charAt(index);
46 }
47
48 public int length() {
49 return inner.length();
50 }
51
52 public CharSequence subSequence(int start, int end) {
53 return new InterruptibleCharSequence(inner.subSequence(start, end));
54 }
55
56 @Override
57 public String toString() {
58 return inner.toString();
59 }
60 }