string stream extract - simplify file reads

This commit is contained in:
adam-m 2012-08-01 14:49:46 -04:00
parent f78dfc09df
commit 8a007e8fe1

View File

@ -106,23 +106,24 @@ public class AbstractFileStringIntStream extends InputStream {
try { try {
//convert more strings, store in buffer //convert more strings, store in buffer
long toRead = 0; long toRead = 0;
int shiftSize = 0; //int shiftSize = 0;
if (lastExtractResult != null && lastExtractResult.getTextLength() != 0
&& (shiftSize = FILE_BUF_SIZE - lastExtractResult.getFirstUnprocessedOff()) > 0) { //if (lastExtractResult != null && lastExtractResult.getTextLength() != 0
//a string previously extracted // && (shiftSize = FILE_BUF_SIZE - lastExtractResult.getFirstUnprocessedOff()) > 0) {
//shift the fileReadBuff past last bytes extracted ////a string previously extracted
//read only what's needed to fill the buffer ////shift the fileReadBuff past last bytes extracted
//to avoid losing chars and breaking or corrupting potential strings - preserve byte stream continuity ////read only what's needed to fill the buffer
byte[] temp = new byte[shiftSize]; ////to avoid loosing chars and breaking or corrupting potential strings - preserve byte stream continuity
System.arraycopy(fileReadBuff, lastExtractResult.getFirstUnprocessedOff(), //byte[] temp = new byte[shiftSize];
temp, 0, shiftSize); //System.arraycopy(fileReadBuff, lastExtractResult.getFirstUnprocessedOff(),
System.arraycopy(temp, 0, fileReadBuff, 0, shiftSize); // temp, 0, shiftSize);
toRead = Math.min(lastExtractResult.getFirstUnprocessedOff(), fileSize - fileReadOffset); //System.arraycopy(temp, 0, fileReadBuff, 0, shiftSize);
lastExtractResult = null; //toRead = Math.min(lastExtractResult.getFirstUnprocessedOff(), fileSize - fileReadOffset);
} else { //lastExtractResult = null;
//} else {
//fill up entire fileReadBuff fresh //fill up entire fileReadBuff fresh
toRead = Math.min(FILE_BUF_SIZE, fileSize - fileReadOffset); toRead = Math.min(FILE_BUF_SIZE, fileSize - fileReadOffset);
} //}
int read = content.read(fileReadBuff, fileReadOffset, toRead); int read = content.read(fileReadBuff, fileReadOffset, toRead);
if (read == -1 || read == 0) { if (read == -1 || read == 0) {
fileEOF = true; fileEOF = true;