public Buffer(String fileName) { try { file = new RandomAccessFile(fileName, "r"); fileLen = (int) file.length(); bufLen = Math.min(fileLen, MAX_BUFFER_LENGTH); buf = new byte[bufLen]; bufStart = Integer.MAX_VALUE; // nothing in buffer so far if (fileLen > 0) setPos(0); // setup buffer to position 0 (start) else bufPos = 0; // index 0 is already after the file, thus setPos(0) is invalid if (bufLen == fileLen) Close(); } catch (IOException e) { throw new FatalError("Could not open file " + fileName); } }
public Buffer(String fileName) { try { file = new RandomAccessFile(fileName, "r"); fileLen = (int) file.length(); bufLen = Math.min(fileLen, MAX_BUFFER_LENGTH); buf = new byte[bufLen]; bufStart = Integer.MAX_VALUE; // nothing in buffer so far if (fileLen > 0) setPos(0); // setup buffer to position 0 (start) else bufPos = 0; // index 0 is already after the file, thus setPos(0) is invalid if (bufLen == fileLen) Close(); } catch (IOException e) { throw new FatalError("Could not open file " + fileName); } }
public int Peek() { int curPos = getPos(); int ch = Read(); setPos(curPos); return ch; }
private void SetScannerBehindT() { buffer.setPos(t.pos); NextCh(); line = t.line; col = t.col; charPos = t.charPos; for (int i = 0; i < tlen; i++) NextCh(); }
public int Peek() { int curPos = getPos(); int ch = Read(); setPos(curPos); return ch; }
private void SetScannerBehindT() { buffer.setPos(t.pos); NextCh(); line = t.line; col = t.col; charPos = t.charPos; for (int i = 0; i < tlen; i++) NextCh(); }
public int Read() { if (bufPos < bufLen) { return buf[bufPos++] & 0xff; // mask out sign bits } else if (getPos() < fileLen) { setPos(getPos()); // shift buffer start to pos return buf[bufPos++] & 0xff; // mask out sign bits } else if (stream != null && ReadNextStreamChunk() > 0) { return buf[bufPos++] & 0xff; // mask out sign bits } else { return EOF; } }
public int Read() { if (bufPos < bufLen) { return buf[bufPos++] & 0xff; // mask out sign bits } else if (getPos() < fileLen) { setPos(getPos()); // shift buffer start to pos return buf[bufPos++] & 0xff; // mask out sign bits } else if (stream != null && ReadNextStreamChunk() > 0) { return buf[bufPos++] & 0xff; // mask out sign bits } else { return EOF; } }