Skip to content

Commit 729838e

Browse files
kmaderctrueden
authored andcommitted
IndexReader: add an optional stream label
This label can help facilitate debugging problems with the annotation processor more easily.
1 parent 084f2ba commit 729838e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/java/org/scijava/annotations/IndexReader.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,17 @@
6464
class IndexReader {
6565

6666
private final PushbackInputStream in;
67+
private final String originalISName;
6768

6869
IndexReader(final InputStream in) {
70+
this(in, "");
71+
}
72+
73+
IndexReader(final InputStream in, final String isName) {
6974
this.in =
7075
in instanceof PushbackInputStream ? (PushbackInputStream) in
7176
: new PushbackInputStream(new BufferedInputStream(in));
77+
this.originalISName = isName;
7278
}
7379

7480
public Object next() throws IOException {
@@ -155,7 +161,8 @@ else if (c < '0' || c > '9') {
155161
if (c == '"') {
156162
return readString();
157163
}
158-
throw new IOException("Unexpected char: '" + (char) c + "'");
164+
throw new IOException("Unexpected char: '" + (char) c + "'"+
165+
((originalISName.length()>0) ? " from "+originalISName : ""));
159166
}
160167

161168
public void close() throws IOException {
@@ -206,7 +213,7 @@ private int expect(char a, char b) throws IOException {
206213
return 1;
207214
}
208215
throw new IOException("Expected '" + a + "' or '" + b + "', got '" +
209-
(char) c + "'");
216+
(char) c + "'"+((originalISName.length()>0) ? " from "+originalISName : ""));
210217
}
211218

212219
private void expect(String match) throws IOException {
@@ -217,6 +224,7 @@ private void expect(String match) throws IOException {
217224

218225
private IndexReader() {
219226
this.in = null;
227+
this.originalISName="";
220228
}
221229

222230
static IndexReader getLegacyReader(final InputStream in) throws IOException {

0 commit comments

Comments
 (0)