@Override public long length() { ensureOpen(); return in.size(); }
@Override public String toString() { return String.format(Locale.ROOT, "%,d bytes, block size: %,d, blocks: %,d, position: %,d%s", size(), blockSize(), blocks.length, position(), offset == 0 ? "" : String.format(Locale.ROOT, " [offset: %,d]", offset)); }
@Override public byte readByte() throws EOFException { try { ByteBuffer block = blocks[blockIndex(pos)]; byte v = block.get(blockOffset(pos)); pos++; return v; } catch (IndexOutOfBoundsException e) { if (pos >= size()) { throw new EOFException(); } else { throw e; // Something is wrong. } } }
@Override public void readBytes(byte[] arr, int off, int len) throws EOFException { try { while (len > 0) { ByteBuffer block = blocks[blockIndex(pos)].duplicate(); block.position(blockOffset(pos)); int chunk = Math.min(len, block.remaining()); if (chunk == 0) { throw new EOFException(); } // Update pos early on for EOF detection, then try to get buffer content. pos += chunk; block.get(arr, off, chunk); len -= chunk; off += chunk; } } catch (BufferUnderflowException | ArrayIndexOutOfBoundsException e) { if (pos >= size()) { throw new EOFException(); } else { throw e; // Something is wrong. } } }
if (pos >= size()) { throw new EOFException(); } else {
@Override public IndexInput clone() { ensureOpen(); ByteBuffersIndexInput cloned = new ByteBuffersIndexInput(in.slice(0, in.size()), "(clone of) " + toString()); try { cloned.seek(getFilePointer()); } catch (IOException e) { throw new UncheckedIOException(e); } return cloned; }
@Override public long length() { ensureOpen(); return in.size(); }
@Override public String toString() { return String.format(Locale.ROOT, "%,d bytes, block size: %,d, blocks: %,d, position: %,d%s", size(), blockSize(), blocks.length, position(), offset == 0 ? "" : String.format(Locale.ROOT, " [offset: %,d]", offset)); }
@Override public byte readByte() throws EOFException { try { ByteBuffer block = blocks[blockIndex(pos)]; byte v = block.get(blockOffset(pos)); pos++; return v; } catch (IndexOutOfBoundsException e) { if (pos >= size()) { throw new EOFException(); } else { throw e; // Something is wrong. } } }
@Override public void readBytes(byte[] arr, int off, int len) throws EOFException { try { while (len > 0) { ByteBuffer block = blocks[blockIndex(pos)].duplicate(); block.position(blockOffset(pos)); int chunk = Math.min(len, block.remaining()); if (chunk == 0) { throw new EOFException(); } // Update pos early on for EOF detection, then try to get buffer content. pos += chunk; block.get(arr, off, chunk); len -= chunk; off += chunk; } } catch (BufferUnderflowException | ArrayIndexOutOfBoundsException e) { if (pos >= size()) { throw new EOFException(); } else { throw e; // Something is wrong. } } }
if (pos >= size()) { throw new EOFException(); } else {
@Override public IndexInput clone() { ensureOpen(); ByteBuffersIndexInput cloned = new ByteBuffersIndexInput(in.slice(0, in.size()), "(clone of) " + toString()); try { cloned.seek(getFilePointer()); } catch (IOException e) { throw new UncheckedIOException(e); } return cloned; }