public final class RandomAccessSourceFactory extends Object
RandomAccessSource
objects based on various types of sources
Constructor and Description |
---|
RandomAccessSourceFactory()
Creates a factory that will give preference to accessing the underling data source using memory mapped files
|
public RandomAccessSourceFactory()
public RandomAccessSourceFactory setForceRead(boolean forceRead)
forceRead
- true if the full content will be read, false otherwise
public RandomAccessSourceFactory setUsePlainRandomAccess(boolean usePlainRandomAccess)
RandomAccessFile
should be used as the primary data access mechanism
usePlainRandomAccess
- whether RandomAccessFile
should be used as the primary data access mechanism
public RandomAccessSourceFactory setExclusivelyLockFile(boolean exclusivelyLockFile)
public RandomAccessSource createSource(byte[] data)
RandomAccessSource
based on a byte array
data
- the byte array
RandomAccessSource
public RandomAccessSource createSource(RandomAccessFile raf) throws IOException
IOException
public RandomAccessSource createSource(URL url) throws IOException
RandomAccessSource
based on a URL. The data available at the URL is read into memory and used as the source for the RandomAccessSource
url
- the url to read from
RandomAccessSource
IOException
public RandomAccessSource createSource(InputStream is) throws IOException
RandomAccessSource
based on an InputStream
. The full content of the InputStream is read into memory and used as the source for the RandomAccessSource
is
- the stream to read from
RandomAccessSource
IOException
public RandomAccessSource createBestSource(String filename) throws IOException
RandomAccessSource
based on a filename string. If the filename describes a URL, a URL based source is created If the filename describes a file on disk, the contents may be read into memory (if forceRead is true), opened using memory mapped file channel (if usePlainRandomAccess is false), or opened using RandomAccessFile
access (if usePlainRandomAccess is true) This call will automatically failover to using RandomAccessFile
if the memory map operation fails
filename
- the name of the file or resource to create the RandomAccessSource
for
RandomAccessSource
IOException
public RandomAccessSource createBestSource(RandomAccessFile raf) throws IOException
RandomAccessSource
based on a RandomAccessFile. The source will be opened using memory mapped file channel (if usePlainRandomAccess is false), or opened using RandomAccessFile
access (if usePlainRandomAccess is true) This call will automatically failover to using RandomAccessFile
if the memory map operation fails If the source couldn't be opened, the RandomAccessFile will be closed
raf
- the RandomAccessFile to create a RandomAccessSource
for
RandomAccessSource
IOException
public RandomAccessSource createBestSource(FileChannel channel) throws IOException
RandomAccessSource
based on memory mapping a file channel. Unless you are explicitly working with a FileChannel already, it is better to use createBestSource(String)
. If the file is large, it will be opened using a paging strategy.
filename
- the name of the file or resource to create the RandomAccessSource
for
RandomAccessSource
IOException
public RandomAccessSource createRanged(RandomAccessSource source, long[] ranges) throws IOException
IOException
Copyright © 1998–2024. All rights reserved.