/** * Does nothing - the underlying source is not closed */ public void close() throws java.io.IOException { source.close(); getBufferStart = -1; getBufferEnd = -1; } }
/** * {@inheritDoc} */ @Override public int read() throws java.io.IOException { return source.get(position++); } }
/** * Gets the total amount of bytes in the source. * * @return source's size. * @throws java.io.IOException */ public long length() throws java.io.IOException { return byteSource.length(); }
/** * {@inheritDoc} */ public int get(long position, byte[] bytes, int off, int len) throws java.io.IOException { SourceEntry entry = getSourceEntryForOffset(position); if (entry == null) // we have run out of data to read from return -1; long offN = entry.offsetN(position); int remaining = len; while(remaining > 0){ if (entry == null) // we have run out of data to read from break; if (offN > entry.source.length()) break; int count = entry.source.get(offN, bytes, off, remaining); if (count == -1) break; off += count; position += count; remaining -= count; offN = 0; entry = getSourceEntryForOffset(position); } return remaining == len ? -1 : len - remaining; }
/** * {@inheritDoc} */ public int get(long position, byte[] bytes, int off, int len) throws java.io.IOException { SourceEntry entry = getSourceEntryForOffset(position); if (entry == null) // we have run out of data to read from return -1; long offN = entry.offsetN(position); int remaining = len; while(remaining > 0){ if (entry == null) // we have run out of data to read from break; if (offN > entry.source.length()) break; int count = entry.source.get(offN, bytes, off, remaining); if (count == -1) break; off += count; position += count; remaining -= count; offN = 0; entry = getSourceEntryForOffset(position); } return remaining == len ? -1 : len - remaining; }
/** * {@inheritDoc} */ public int get(long position, byte[] bytes, int off, int len) throws java.io.IOException { return source.get(position, bytes, off, len); }
/** * Standard constructor * @param index the index * @param source the source * @param offset the offset of the source in the GroupedRandomAccessSource */ public SourceEntry(int index, IRandomAccessSource source, long offset) { this.index = index; this.source = source; this.firstByte = offset; this.lastByte = offset + source.length() - 1; }
/** * Closes the underlying source. * * @throws java.io.IOException */ public void close() throws java.io.IOException { isBack = false; byteSource.close(); }
/** * {@inheritDoc} */ @Override public int read(byte[] b, int off, int len) throws java.io.IOException { int count = source.get(position, b, off, len); position += count; return count; }
/** * {@inheritDoc} */ public long length() { return source.length(); }
@Override public void close() throws IOException { synchronized (lockObj) { source.close(); } } }
/** * {@inheritDoc} * Note that the position will be adjusted to read from the corrected location in the underlying source */ public int get(long position) throws java.io.IOException { if (position >= length) return -1; return source.get(offset + position); }
/** * Standard constructor * @param index the index * @param source the source * @param offset the offset of the source in the GroupedRandomAccessSource */ public SourceEntry(int index, IRandomAccessSource source, long offset) { this.index = index; this.source = source; this.firstByte = offset; this.lastByte = offset + source.length() - 1; }
/** * {@inheritDoc} */ public void close() throws java.io.IOException { source.close(); } }
@Override public int get(long position) throws IOException { synchronized (lockObj) { return source.get(position); } }
@Override public long length() { synchronized (lockObj) { return source.length(); } }
/** * Closes the underlying source. * * @throws java.io.IOException */ public void close() throws java.io.IOException { isBack = false; byteSource.close(); }
@Override public int get(long position, byte[] bytes, int off, int len) throws IOException { synchronized (lockObj) { return source.get(position, bytes, off, len); } }
/** * {@inheritDoc} */ public long length() { return source.length(); }
/** * {@inheritDoc} */ public void close() throws java.io.IOException { source.close(); } }