public final class RandomAccessSourceFactory extends Object
IRandomAccessSource
objects based on various types of sourcesConstructor and Description |
---|
RandomAccessSourceFactory()
Creates a factory that will give preference to accessing the underling data source using memory mapped files
|
Modifier and Type | Method and Description |
---|---|
IRandomAccessSource |
createBestSource(FileChannel channel)
Creates a
IRandomAccessSource based on memory mapping a file channel. |
IRandomAccessSource |
createBestSource(String filename)
Creates a
IRandomAccessSource based on a filename string. |
IRandomAccessSource |
createRanged(IRandomAccessSource source,
long[] ranges) |
IRandomAccessSource |
createSource(byte[] data)
Creates a
IRandomAccessSource based on a byte array |
IRandomAccessSource |
createSource(InputStream inputStream)
Creates a
IRandomAccessSource based on an InputStream . |
IRandomAccessSource |
createSource(RandomAccessFile raf) |
IRandomAccessSource |
createSource(URL url)
Creates a
IRandomAccessSource based on a URL. |
IRandomAccessSource |
extractOrCreateSource(InputStream inputStream)
Creates or extracts a
IRandomAccessSource based on an InputStream . |
RandomAccessSourceFactory |
setExclusivelyLockFile(boolean exclusivelyLockFile) |
RandomAccessSourceFactory |
setForceRead(boolean forceRead)
Determines whether the full content of the source will be read into memory
|
static void |
setForceReadDefaultValue(boolean forceRead)
Determines the default value for the forceRead flag
|
RandomAccessSourceFactory |
setUsePlainRandomAccess(boolean usePlainRandomAccess)
Determines whether
RandomAccessFile should be used as the primary data access mechanism |
public RandomAccessSourceFactory()
public static void setForceReadDefaultValue(boolean forceRead)
forceRead
- true if by default the full content will be read, false otherwisepublic RandomAccessSourceFactory setForceRead(boolean forceRead)
forceRead
- true if the full content will be read, false otherwisepublic RandomAccessSourceFactory setUsePlainRandomAccess(boolean usePlainRandomAccess)
RandomAccessFile
should be used as the primary data access mechanismusePlainRandomAccess
- whether RandomAccessFile
should be used as the primary data access mechanismpublic RandomAccessSourceFactory setExclusivelyLockFile(boolean exclusivelyLockFile)
public IRandomAccessSource createSource(byte[] data)
IRandomAccessSource
based on a byte arraydata
- the byte arrayIRandomAccessSource
public IRandomAccessSource createSource(RandomAccessFile raf) throws IOException
IOException
public IRandomAccessSource createSource(URL url) throws IOException
IRandomAccessSource
based on a URL. The data available at the URL is read into memory and used
as the source for the IRandomAccessSource
url
- the url to read fromIRandomAccessSource
IOException
- in case of any I/O error.public IRandomAccessSource extractOrCreateSource(InputStream inputStream) throws IOException
IRandomAccessSource
based on an InputStream
.
If the InputStream is an instance of RASInputStream
then extracts the source from it.
Otherwise The full content of the InputStream is read into memory and used
as the source for the IRandomAccessSource
inputStream
- the stream to read fromIRandomAccessSource
IOException
- in case of any I/O error.public IRandomAccessSource createSource(InputStream inputStream) throws IOException
IRandomAccessSource
based on an InputStream
.
The full content of the InputStream is read into memory and used
as the source for the IRandomAccessSource
inputStream
- the stream to read fromIRandomAccessSource
IOException
- in case of any I/O error.public IRandomAccessSource createBestSource(String filename) throws IOException
IRandomAccessSource
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 fail over to using RandomAccessFile
if the memory map operation failsfilename
- the name of the file or resource to create the IRandomAccessSource
forIRandomAccessSource
IOException
- in case of any I/O errorpublic IRandomAccessSource createBestSource(FileChannel channel) throws IOException
IRandomAccessSource
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.channel
- the name of the file or resource to create the IRandomAccessSource
forIRandomAccessSource
IOException
- in case of any I/O errorpublic IRandomAccessSource createRanged(IRandomAccessSource source, long[] ranges) throws IOException
IOException
Copyright © 1998–2023 Apryse Group NV. All rights reserved.