1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
package com.stevesoft.pat.wrap; |
9 |
|
|
10 |
|
import jalview.util.MessageManager; |
11 |
|
|
12 |
|
import java.io.IOException; |
13 |
|
import java.io.RandomAccessFile; |
14 |
|
|
15 |
|
import com.stevesoft.pat.BasicStringBufferLike; |
16 |
|
import com.stevesoft.pat.Regex; |
17 |
|
import com.stevesoft.pat.StringLike; |
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
|
|
| 0% |
Uncovered Elements: 83 (83) |
Complexity: 28 |
Complexity Density: 0.57 |
|
23 |
|
public class RandomAccessFileWrap implements StringLike |
24 |
|
{ |
25 |
|
|
26 |
|
long offset = 0; |
27 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
28 |
0 |
public void setOffset(long o)... |
29 |
|
{ |
30 |
0 |
offset = o; |
31 |
0 |
i0 = iend = 0; |
32 |
|
} |
33 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
34 |
0 |
public long getOffset()... |
35 |
|
{ |
36 |
0 |
return offset; |
37 |
|
} |
38 |
|
|
39 |
|
RandomAccessFile raf; |
40 |
|
|
41 |
|
int i0 = 0, iend = 0; |
42 |
|
|
43 |
|
byte[] buf = new byte[1024]; |
44 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
45 |
0 |
public int getBufferSize()... |
46 |
|
{ |
47 |
0 |
return buf.length; |
48 |
|
} |
49 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
50 |
0 |
public void setBufferSize(int bs)... |
51 |
|
{ |
52 |
0 |
buf = new byte[bs]; |
53 |
0 |
i0 = iend = 0; |
54 |
|
} |
55 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
0 |
public RandomAccessFileWrap(String file) throws IOException... |
57 |
|
{ |
58 |
0 |
this.raf = new RandomAccessFile(file, "r"); |
59 |
|
} |
60 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
0 |
public RandomAccessFileWrap(RandomAccessFile raf)... |
62 |
|
{ |
63 |
0 |
this.raf = raf; |
64 |
|
} |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 7 |
Complexity Density: 0.64 |
|
66 |
0 |
@Override... |
67 |
|
public char charAt(int i) |
68 |
|
{ |
69 |
0 |
if (i >= i0 && i < iend) |
70 |
|
{ |
71 |
0 |
return (char) buf[i - i0]; |
72 |
|
} |
73 |
|
|
74 |
0 |
try |
75 |
|
{ |
76 |
0 |
i0 = i - 5; |
77 |
|
|
78 |
0 |
if (i0 < 0) |
79 |
|
{ |
80 |
0 |
i0 = 0; |
81 |
|
} |
82 |
0 |
raf.seek(i0 + offset); |
83 |
0 |
iend = i0 + raf.read(buf, 0, buf.length); |
84 |
|
|
85 |
0 |
if (i >= i0 && i < iend) |
86 |
|
{ |
87 |
0 |
return (char) buf[i - i0]; |
88 |
|
} |
89 |
|
} catch (Throwable t) |
90 |
|
{ |
91 |
|
} |
92 |
|
|
93 |
0 |
throw new ArrayIndexOutOfBoundsException(MessageManager |
94 |
|
.formatMessage("exception.out_of_bounds_for_file", new String[] |
95 |
|
{ Integer.valueOf(i).toString(), Integer.valueOf(i0).toString(), |
96 |
|
Integer.valueOf(iend).toString() })); |
97 |
|
} |
98 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
99 |
0 |
@Override... |
100 |
|
public String toString() |
101 |
|
{ |
102 |
0 |
throw new Error(MessageManager.getString("error.not_implemented")); |
103 |
|
} |
104 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
105 |
0 |
@Override... |
106 |
|
public int length() |
107 |
|
{ |
108 |
0 |
try |
109 |
|
{ |
110 |
0 |
long len = raf.length() - offset; |
111 |
0 |
if (len > Integer.MAX_VALUE) |
112 |
|
{ |
113 |
0 |
return Integer.MAX_VALUE; |
114 |
|
} |
115 |
0 |
return (int) len; |
116 |
|
} catch (IOException ioe) |
117 |
|
{ |
118 |
0 |
return 0; |
119 |
|
} |
120 |
|
} |
121 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
122 |
0 |
@Override... |
123 |
|
public String substring(int i1, int i2) |
124 |
|
{ |
125 |
0 |
StringBuffer sb = new StringBuffer(); |
126 |
0 |
for (int i = i1; i < i2; i++) |
127 |
|
{ |
128 |
0 |
sb.append(charAt(i)); |
129 |
|
} |
130 |
0 |
return sb.toString(); |
131 |
|
} |
132 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
133 |
0 |
@Override... |
134 |
|
public Object unwrap() |
135 |
|
{ |
136 |
0 |
return raf; |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
@param |
143 |
|
@throws |
144 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 4 |
Complexity Density: 0.31 |
|
145 |
0 |
public static void main(String[] files) throws IOException... |
146 |
|
{ |
147 |
0 |
for (int i = 0; i < files.length; i++) |
148 |
|
{ |
149 |
0 |
RandomAccessFileWrap fw = new RandomAccessFileWrap( |
150 |
|
new RandomAccessFile(files[i], "r")); |
151 |
0 |
Regex r = new Regex("toString\\(\\) *(?@{})"); |
152 |
0 |
r.setGFlag(true); |
153 |
0 |
r.optimize(); |
154 |
0 |
System.out.print(files[i] + " "); |
155 |
0 |
int j = 0; |
156 |
0 |
do |
157 |
|
{ |
158 |
0 |
if (r.searchFrom(fw, j)) |
159 |
|
{ |
160 |
0 |
System.out.println("Matched at index: " + r.matchedFrom()); |
161 |
0 |
j = r.matchedTo(); |
162 |
|
} |
163 |
|
else |
164 |
|
{ |
165 |
0 |
System.out.println("not found"); |
166 |
|
} |
167 |
0 |
System.out.println(r.stringMatched()); |
168 |
0 |
} while (r.didMatch()); |
169 |
|
} |
170 |
|
} |
171 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
172 |
0 |
@Override... |
173 |
|
public BasicStringBufferLike newStringBufferLike() |
174 |
|
{ |
175 |
0 |
return new StringBufferWrap(); |
176 |
|
} |
177 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
178 |
0 |
@Override... |
179 |
|
public int indexOf(char c) |
180 |
|
{ |
181 |
0 |
for (int i = 0; i < length(); i++) |
182 |
|
{ |
183 |
0 |
if (charAt(i) == c) |
184 |
|
{ |
185 |
0 |
return i; |
186 |
|
} |
187 |
|
} |
188 |
0 |
return -1; |
189 |
|
} |
190 |
|
} |