/** * 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); }
/** * Creates a {@link IRandomAccessSource} based on memory mapping a file channel. * Unless you are explicitly working with a {@code FileChannel} already, it is better to use * {@link RandomAccessSourceFactory#createBestSource(String)}. * If the file is large, it will be opened using a paging strategy. * @param channel the name of the file or resource to create the {@link IRandomAccessSource} for * @return the newly created {@link IRandomAccessSource} */ public IRandomAccessSource createBestSource(FileChannel channel) throws java.io.IOException { if (channel.size() <= PagedChannelRandomAccessSource.DEFAULT_TOTAL_BUFSIZE){ // if less than the fully mapped usage of PagedFileChannelRandomAccessSource, just map the whole thing and be done with it return new GetBufferedRandomAccessSource(new FileChannelRandomAccessSource(channel)); } else { return new GetBufferedRandomAccessSource(new PagedChannelRandomAccessSource(channel)); } }
/** * Creates a {@link IRandomAccessSource} based on memory mapping a file channel. * Unless you are explicitly working with a {@code FileChannel} already, it is better to use * {@link RandomAccessSourceFactory#createBestSource(String)}. * If the file is large, it will be opened using a paging strategy. * @param channel the name of the file or resource to create the {@link IRandomAccessSource} for * @return the newly created {@link IRandomAccessSource} */ public IRandomAccessSource createBestSource(FileChannel channel) throws java.io.IOException { if (channel.size() <= PagedChannelRandomAccessSource.DEFAULT_TOTAL_BUFSIZE){ // if less than the fully mapped usage of PagedFileChannelRandomAccessSource, just map the whole thing and be done with it return new GetBufferedRandomAccessSource(new FileChannelRandomAccessSource(channel)); } else { return new GetBufferedRandomAccessSource(new PagedChannelRandomAccessSource(channel)); } }
/** * 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); }