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.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();