Resize ANTLRInputStream.data after reading a file with fewer characters than bytes

This commit is contained in:
Sam Harwell 2013-06-01 19:00:18 -05:00
parent eeda06b698
commit 9d11817667
1 changed files with 5 additions and 1 deletions

View File

@ -33,6 +33,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
/** This is an ANTLRInputStream that is loaded from a file
* all at once when you construct the object. This is a special case
@ -69,7 +70,10 @@ public class ANTLRFileStream extends ANTLRInputStream {
}
try {
data = new char[size];
super.n = isr.read(data);
n = isr.read(data);
if (n < data.length) {
data = Arrays.copyOf(data, n);
}
}
finally {
isr.close();