/** * 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 long length() { return source.length(); }
/** * 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; }
@Override public long length() { synchronized (lockObj) { return source.length(); } }
/** * 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; }
/** * Constructs a new OffsetRandomAccessSource that extends to the end of the underlying source * @param source the source * @param offset the amount of the offset to use */ public WindowRandomAccessSource(IRandomAccessSource source, long offset) { this(source, offset, source.length() - offset); }
@Override public long length() { synchronized (lockObj) { return source.length(); } }
/** * 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 long length() { return source.length(); }
/** * {@inheritDoc} */ public long length() { return source.length(); }
/** * {@inheritDoc} */ public long length() { return source.length(); }
/** * Constructs a new OffsetRandomAccessSource that extends to the end of the underlying source * @param source the source * @param offset the amount of the offset to use */ public WindowRandomAccessSource(IRandomAccessSource source, long offset) { this(source, offset, source.length() - offset); }
/** * Constructs a new OffsetRandomAccessSource * @param source the source */ public GetBufferedRandomAccessSource(IRandomAccessSource source) { this.source = source; this.getBuffer = new byte[(int)Math.min(Math.max(source.length()/4, 1), 4096)]; this.getBufferStart = -1; this.getBufferEnd = -1; }
/** * Constructs a new OffsetRandomAccessSource * @param source the source */ public GetBufferedRandomAccessSource(IRandomAccessSource source) { this.source = source; this.getBuffer = new byte[(int)Math.min(Math.max(source.length()/4, 1), 4096)]; this.getBufferStart = -1; this.getBufferEnd = -1; }
/** * Constructs a new {@link GroupedRandomAccessSource} based on the specified set of sources * @param sources the sources used to build this group */ public GroupedRandomAccessSource(IRandomAccessSource[] sources) throws java.io.IOException { this.sources = new SourceEntry[sources.length]; long totalSize = 0; for(int i = 0; i < sources.length; i++){ this.sources[i] = new SourceEntry(i, sources[i], totalSize); totalSize += sources[i].length(); } size = totalSize; currentSourceEntry = this.sources[sources.length-1]; sourceInUse(currentSourceEntry.source); }
/** * Constructs a new {@link GroupedRandomAccessSource} based on the specified set of sources * @param sources the sources used to build this group */ public GroupedRandomAccessSource(IRandomAccessSource[] sources) throws java.io.IOException { this.sources = new SourceEntry[sources.length]; long totalSize = 0; for(int i = 0; i < sources.length; i++){ this.sources[i] = new SourceEntry(i, sources[i], totalSize); totalSize += sources[i].length(); } size = totalSize; currentSourceEntry = this.sources[sources.length-1]; sourceInUse(currentSourceEntry.source); }
/** * {@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; }