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); }
/** * 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 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); }
public void position(long p) throws IOException { if (p > Integer.MAX_VALUE) { throw new IOException("File too large."); } int charPos = (int)p; Piece piece = table.pieceFor(charPos); if (piece == null) { throw new IOException("Illegal position: " + p); } unicode = piece.isUnicode(); limit = piece.getCharPosLimit(); int ofs = charPos - piece.getCharPosStart(); this.charPos = charPos; doc.position(piece.getFilePos() + ofs); } }
SeekInputStream mainStream = main.open(); mainStream.position(10); int flags = Endian.littleChar(mainStream); boolean complex = (flags & 0x0004) == 0x0004; mainStream.position(24); int fcMin = Endian.littleInt(mainStream); int fcMax = Endian.littleInt(mainStream); mainStream.position(76); int cppText = Endian.littleInt(mainStream); mainStream.position(418); int fcClx = Endian.littleInt(mainStream); int fcSz = Endian.littleInt(mainStream);
/** * Wraps the raw table stream. This is used to create the charPos and * filePos streams. The streams that this method returns are "safe", * meaning that the charPos and filePos position() fields never clobber * each other. They are buffered, meaning that up to <i>n</i> elements * can be read before the disk is accessed again. And they are "origined", * meaning result.position(0) actually positions the stream at the * beginning of the piece table array, not the beginning of the file. * * @param input the stream to wrap * @param pos the origin for the returned stream * @param cache the number of bytes for the returned stream to buffer * @return the wrapped stream * @throws IOException if an IO error occurs */ private SeekInputStream wrap(SeekInputStream input, long pos, int cache) throws IOException { input.position(pos); SeekInputStream r = new SafeSeekInputStream(input); r = new OriginSeekInputStream(r, pos); r = new BufferedSeekInputStream(r, cache); return r; }
private void seekIfNecessary() throws IOException { if (doc == null) { throw new IOException("Stream closed."); } if (charPos >= table.getMaxCharPos()) { return; } if (charPos < limit) { return; } Piece piece = table.next(); unicode = piece.isUnicode(); limit = piece.getCharPosLimit(); doc.position(piece.getFilePos()); }
input.position(filePos);
/** * Returns the stream's current position. * * @return the current position */ public long position() throws IOException { return input.position() - buffer.length + offset; }
/** * Constructor. The given stream will be positioned to 0 so that an * accurate position can be tracked. * * @param input the underlying input stream * @throws IOException if an IO error occurs */ public SafeSeekInputStream(SeekInputStream input) throws IOException { this.input = input; this.expected = input.position(); }
/** * Constructor. * * @param input the underlying stream * @param origin the origin position * @throws IOException if an IO error occurs */ public OriginSeekInputStream(SeekInputStream input, long origin) throws IOException { this.input = input; this.origin = origin; input.position(origin); }
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); }
/** * Resets this stream to its marked position. * * @throws IOException if there is no mark, or if an IO error occurs */ public void reset() throws IOException { if (mark < 0) { throw new IOException("No mark."); } position(mark); }