/** * {@inheritDoc} * The source that contains the byte at position is retrieved, the correct offset into that source computed, then the value * from that offset in the underlying source is returned. */ public int get(long position) throws java.io.IOException { SourceEntry entry = getSourceEntryForOffset(position); if (entry == null) // we have run out of data to read from return -1; return entry.source.get(entry.offsetN(position)); }
/** * Creates an independent view of this object (with it's own file pointer and push back queue). Closing the new object will not close this object. * Closing this object will have adverse effect on the view. * * @return the new view */ public RandomAccessFileOrArray createView() { ensureByteSourceIsThreadSafe(); return new RandomAccessFileOrArray(new IndependentRandomAccessSource(byteSource)); }
public IRandomAccessSource createRanged(IRandomAccessSource source, long[] ranges) throws java.io.IOException { IRandomAccessSource[] sources = new IRandomAccessSource[ranges.length/2]; for(int i = 0; i < ranges.length; i+=2){ sources[i/2] = new WindowRandomAccessSource(source, ranges[i], ranges[i+1]); } return new GroupedRandomAccessSource(sources); }
/** * Load data from URL. url must be not null. * Note, this method doesn't check if data or url is null. * @throws java.io.IOException */ void loadData() throws java.io.IOException { RandomAccessFileOrArray raf = new RandomAccessFileOrArray(new RandomAccessSourceFactory().createSource(url)); ByteArrayOutputStream stream = new ByteArrayOutputStream(); StreamUtil.transferBytes(raf, stream); raf.close(); data = stream.toByteArray(); }
public PdfTokenizer getLocation(String location) throws java.io.IOException { return new PdfTokenizer(new RandomAccessFileOrArray(new RandomAccessSourceFactory().createSource(data))); } }
public T writeInteger(int value) { try { ByteUtils.getIsoBytes(value, numBuffer.reset()); write(numBuffer.getInternalBuffer(), numBuffer.capacity() - numBuffer.size(), numBuffer.size()); return (T) this; } catch (java.io.IOException e) { throw new IOException(IOException.CannotWriteIntNumber, e); } }
/** * Provides the size of the opened file. * * @return The size of the opened file. * @throws IOException on error. */ public long getFileLength() throws IOException { return tokens.getSafeFile().length(); }
/** * Creates the view of the byte source of this object. Closing the view won't affect this object. * Closing source will have adverse effect on the view. * * @return the byte source view. */ public IRandomAccessSource createSourceView() { ensureByteSourceIsThreadSafe(); return new IndependentRandomAccessSource(byteSource); }
/** * {@inheritDoc} * For now, close the source that is no longer being used. In the future, we may implement an MRU that allows multiple pages to be opened at a time */ @Override protected void sourceReleased(IRandomAccessSource source) throws java.io.IOException { IRandomAccessSource old = mru.enqueue(source); if (old != null) old.close(); }
/** * Constructs a new {@link PagedChannelRandomAccessSource} based on the specified FileChannel, with a specific buffer size * @param channel the channel to use as the backing store * @param totalBufferSize total buffer size * @param maxOpenBuffers open buffers * @throws java.io.IOException if the channel cannot be opened or mapped */ public PagedChannelRandomAccessSource(FileChannel channel, int totalBufferSize, int maxOpenBuffers) throws java.io.IOException { super(buildSources(channel, totalBufferSize/maxOpenBuffers)); this.channel = channel; this.bufferSize = totalBufferSize/maxOpenBuffers; this.mru = new MRU<IRandomAccessSource>(maxOpenBuffers); }
/** * Load data from URL. url must be not null. * Note, this method doesn't check if data or url is null. * @throws java.io.IOException */ void loadData() throws java.io.IOException { RandomAccessFileOrArray raf = new RandomAccessFileOrArray(new RandomAccessSourceFactory().createSource(url)); ByteArrayOutputStream stream = new ByteArrayOutputStream(); StreamUtil.transferBytes(raf, stream); raf.close(); data = stream.toByteArray(); }
public PdfTokenizer getLocation(String location) throws java.io.IOException { return new PdfTokenizer(new RandomAccessFileOrArray(new RandomAccessSourceFactory().createSource(data))); } }
public T writeLong(long value) { try { ByteUtils.getIsoBytes(value, numBuffer.reset()); write(numBuffer.getInternalBuffer(), numBuffer.capacity() - numBuffer.size(), numBuffer.size()); return (T) this; } catch (java.io.IOException e) { throw new IOException(IOException.CannotWriteIntNumber, e); } }
/** * Creates an independent view of this object (with it's own file pointer and push back queue). Closing the new object will not close this object. * Closing this object will have adverse effect on the view. * * @return the new view */ public RandomAccessFileOrArray createView() { ensureByteSourceIsThreadSafe(); return new RandomAccessFileOrArray(new IndependentRandomAccessSource(byteSource)); }
public IRandomAccessSource createRanged(IRandomAccessSource source, long[] ranges) throws java.io.IOException { IRandomAccessSource[] sources = new IRandomAccessSource[ranges.length/2]; for(int i = 0; i < ranges.length; i+=2){ sources[i/2] = new WindowRandomAccessSource(source, ranges[i], ranges[i+1]); } return new GroupedRandomAccessSource(sources); }
/** * {@inheritDoc} * The source that contains the byte at position is retrieved, the correct offset into that source computed, then the value * from that offset in the underlying source is returned. */ public int get(long position) throws java.io.IOException { SourceEntry entry = getSourceEntryForOffset(position); if (entry == null) // we have run out of data to read from return -1; return entry.source.get(entry.offsetN(position)); }
/** * Creates the view of the byte source of this object. Closing the view won't affect this object. * Closing source will have adverse effect on the view. * * @return the byte source view. */ public IRandomAccessSource createSourceView() { ensureByteSourceIsThreadSafe(); return new IndependentRandomAccessSource(byteSource); }
/** * {@inheritDoc} * For now, close the source that is no longer being used. In the future, we may implement an MRU that allows multiple pages to be opened at a time */ @Override protected void sourceReleased(IRandomAccessSource source) throws java.io.IOException { IRandomAccessSource old = mru.enqueue(source); if (old != null) old.close(); }
public T writeLong(long value) { try { ByteUtils.getIsoBytes(value, numBuffer.reset()); write(numBuffer.getInternalBuffer(), numBuffer.capacity() - numBuffer.size(), numBuffer.size()); return (T) this; } catch (java.io.IOException e) { throw new IOException(IOException.CannotWriteIntNumber, e); } }
public T writeDouble(double value, boolean highPrecision) { try { ByteUtils.getIsoBytes(value, numBuffer.reset(), highPrecision); write(numBuffer.getInternalBuffer(), numBuffer.capacity() - numBuffer.size(), numBuffer.size()); return (T) this; } catch (java.io.IOException e) { throw new IOException(IOException.CannotWriteFloatNumber, e); } }