forked from jasder/antlr
Resize ANTLRInputStream.data after reading a file with fewer characters than bytes
This commit is contained in:
parent
eeda06b698
commit
9d11817667
|
@ -33,6 +33,7 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/** This is an ANTLRInputStream that is loaded from a file
|
/** This is an ANTLRInputStream that is loaded from a file
|
||||||
* all at once when you construct the object. This is a special case
|
* all at once when you construct the object. This is a special case
|
||||||
|
@ -69,7 +70,10 @@ public class ANTLRFileStream extends ANTLRInputStream {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
data = new char[size];
|
data = new char[size];
|
||||||
super.n = isr.read(data);
|
n = isr.read(data);
|
||||||
|
if (n < data.length) {
|
||||||
|
data = Arrays.copyOf(data, n);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
isr.close();
|
isr.close();
|
||||||
|
|
Loading…
Reference in New Issue