public void close() throws IOException { doc.close(); table = null; }
public int read() throws IOException { if (!ensureBuffer()) { return -1; } int r = raw.read(); position++; expectedRawPosition++; blockBytesRead++; return r; }
/** * Skips over any property information that may precede a piece table. * These property structures contain stylesheet information that applies * to the piece table. Since we're only interested in the text itself, * we just ignore this property stuff. (I suppose a third buffered * stream could be used to add style information to {@link Piece}, but * we don't need it.) * * @param input the input stream containing the piece table * @throws IOException if an IO error occurs */ private static void skipProperties(SeekInputStream input) throws IOException { int tag = input.read(); while (tag == 1) { int size = Endian.littleChar(input); while (size > 0) { size -= input.skip(size); } tag = input.read(); } if (tag != 2) { throw new IllegalStateException(); } }
@Override public long skip(long count) throws IOException { return input.skip(count); }
@Override public int available() throws IOException { return input.available(); }
/** * Skips over any property information that may precede a piece table. * These property structures contain stylesheet information that applies * to the piece table. Since we're only interested in the text itself, * we just ignore this property stuff. (I suppose a third buffered * stream could be used to add style information to {@link Piece}, but * we don't need it.) * * @param input the input stream containing the piece table * @throws IOException if an IO error occurs */ private static void skipProperties(SeekInputStream input) throws IOException { int tag = input.read(); while (tag == 1) { int size = Endian.littleChar(input); while (size > 0) { size -= input.skip(size); } tag = input.read(); } if (tag != 2) { throw new IllegalStateException(); } }
@Override public long skip(long count) throws IOException { return input.skip(count); }
@Override public int available() throws IOException { return input.available(); }
private void seek(long block, long rem) throws IOException { assert rem < BLOCK_SIZE; long pos = (block + 1) * BLOCK_SIZE + rem; blockBytesRead = (int)rem; expectedRawPosition = pos; raw.position(pos); }
public int read(byte[] b, int ofs, int len) throws IOException { if (!ensureBuffer()) { return 0; } int rem = BLOCK_SIZE - (int)(position % BLOCK_SIZE); len = Math.min(len, rem); int c = raw.read(b, ofs, len); position += c; expectedRawPosition += c; blockBytesRead++; return len; }
@Override public long skip(long count) throws IOException { return input.skip(count); }
@Override public int available() throws IOException { return input.available(); }
/** * Returns the BAT block with the given block number. * If the BAT block were previously cached, then the cached version * is returned. Otherwise, the file pointer is repositioned to * the start of the given block, and the 512 bytes are read and * stored in the cache. * * @param block the block number of the BAT block to return * @return the BAT block * @throws IOException */ private ByteBuffer getBATBlock(int block) throws IOException { ByteBuffer r = cache.get(block); if (r != null) { return r; } byte[] buf = new byte[BLOCK_SIZE]; input.position((block + 1) * BLOCK_SIZE); ArchiveUtils.readFully(input, buf); r = ByteBuffer.wrap(buf); r.order(ByteOrder.LITTLE_ENDIAN); cache.put(block, r); return r; }
public int read() throws IOException { seekIfNecessary(); if (doc == null) { throw new IOException("Stream closed."); } if (charPos >= table.getMaxCharPos()) { return -1; } int ch; if (unicode) { ch = Endian.littleChar(doc); } else { ch = Cp1252.decode(doc.read()); } charPos++; return ch; }
@Override public long skip(long c) throws IOException { ensure(); long r = input.skip(c); if (r > 0) { expected += r; } return r; }
public Entry getRoot() throws IOException { // Position to the first block of the entry list. int block = header.getEntriesStart(); input.position((block + 1) * BLOCK_SIZE); // The root entry is always entry #0. return new DefaultEntry(this, input, 0); }
@Override public int read(byte[] buf) throws IOException { return input.read(buf); }