Package com.itextpdf.text.io
Class RandomAccessSourceFactory
- java.lang.Object
-
- com.itextpdf.text.io.RandomAccessSourceFactory
-
public final class RandomAccessSourceFactory extends java.lang.Object
Factory to createRandomAccessSource
objects based on various types of sources- Since:
- 5.3.5
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
exclusivelyLockFile
Whether the underlying file should have a RW lock on it or just an R lockprivate boolean
forceRead
whether the full content of the source should be read into memory at constructionprivate boolean
usePlainRandomAccess
WhetherRandomAccessFile
should be used instead of aFileChannel
, where applicable
-
Constructor Summary
Constructors Constructor Description RandomAccessSourceFactory()
Creates a factory that will give preference to accessing the underling data source using memory mapped files
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RandomAccessSource
createBestSource(java.io.RandomAccessFile raf)
Creates aRandomAccessSource
based on a RandomAccessFile.RandomAccessSource
createBestSource(java.lang.String filename)
Creates aRandomAccessSource
based on a filename string.RandomAccessSource
createBestSource(java.nio.channels.FileChannel channel)
Creates aRandomAccessSource
based on memory mapping a file channel.private RandomAccessSource
createByReadingToMemory(java.io.InputStream is)
Creates a newRandomAccessSource
by reading the specified file/resource into memoryprivate RandomAccessSource
createByReadingToMemory(java.lang.String filename)
Creates a newRandomAccessSource
by reading the specified file/resource into memoryRandomAccessSource
createRanged(RandomAccessSource source, long[] ranges)
RandomAccessSource
createSource(byte[] data)
Creates aRandomAccessSource
based on a byte arrayRandomAccessSource
createSource(java.io.InputStream is)
Creates aRandomAccessSource
based on anInputStream
.RandomAccessSource
createSource(java.io.RandomAccessFile raf)
RandomAccessSource
createSource(java.net.URL url)
Creates aRandomAccessSource
based on a URL.RandomAccessSourceFactory
setExclusivelyLockFile(boolean exclusivelyLockFile)
RandomAccessSourceFactory
setForceRead(boolean forceRead)
Determines whether the full content of the source will be read into memoryRandomAccessSourceFactory
setUsePlainRandomAccess(boolean usePlainRandomAccess)
Determines whetherRandomAccessFile
should be used as the primary data access mechanism
-
-
-
Field Detail
-
forceRead
private boolean forceRead
whether the full content of the source should be read into memory at construction
-
usePlainRandomAccess
private boolean usePlainRandomAccess
WhetherRandomAccessFile
should be used instead of aFileChannel
, where applicable
-
exclusivelyLockFile
private boolean exclusivelyLockFile
Whether the underlying file should have a RW lock on it or just an R lock
-
-
Method Detail
-
setForceRead
public RandomAccessSourceFactory setForceRead(boolean forceRead)
Determines whether the full content of the source will be read into memory- Parameters:
forceRead
- true if the full content will be read, false otherwise- Returns:
- this object (this allows chaining of method calls)
-
setUsePlainRandomAccess
public RandomAccessSourceFactory setUsePlainRandomAccess(boolean usePlainRandomAccess)
Determines whetherRandomAccessFile
should be used as the primary data access mechanism- Parameters:
usePlainRandomAccess
- whetherRandomAccessFile
should be used as the primary data access mechanism- Returns:
- this object (this allows chaining of method calls)
-
setExclusivelyLockFile
public RandomAccessSourceFactory setExclusivelyLockFile(boolean exclusivelyLockFile)
-
createSource
public RandomAccessSource createSource(byte[] data)
Creates aRandomAccessSource
based on a byte array- Parameters:
data
- the byte array- Returns:
- the newly created
RandomAccessSource
-
createSource
public RandomAccessSource createSource(java.io.RandomAccessFile raf) throws java.io.IOException
- Throws:
java.io.IOException
-
createSource
public RandomAccessSource createSource(java.net.URL url) throws java.io.IOException
Creates aRandomAccessSource
based on a URL. The data available at the URL is read into memory and used as the source for theRandomAccessSource
- Parameters:
url
- the url to read from- Returns:
- the newly created
RandomAccessSource
- Throws:
java.io.IOException
-
createSource
public RandomAccessSource createSource(java.io.InputStream is) throws java.io.IOException
Creates aRandomAccessSource
based on anInputStream
. The full content of the InputStream is read into memory and used as the source for theRandomAccessSource
- Parameters:
is
- the stream to read from- Returns:
- the newly created
RandomAccessSource
- Throws:
java.io.IOException
-
createBestSource
public RandomAccessSource createBestSource(java.lang.String filename) throws java.io.IOException
Creates aRandomAccessSource
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 usingRandomAccessFile
access (if usePlainRandomAccess is true) This call will automatically failover to usingRandomAccessFile
if the memory map operation fails- Parameters:
filename
- the name of the file or resource to create theRandomAccessSource
for- Returns:
- the newly created
RandomAccessSource
- Throws:
java.io.IOException
-
createBestSource
public RandomAccessSource createBestSource(java.io.RandomAccessFile raf) throws java.io.IOException
Creates aRandomAccessSource
based on a RandomAccessFile. The source will be opened using memory mapped file channel (if usePlainRandomAccess is false), or opened usingRandomAccessFile
access (if usePlainRandomAccess is true) This call will automatically failover to usingRandomAccessFile
if the memory map operation fails If the source couldn't be opened, the RandomAccessFile will be closed- Parameters:
raf
- the RandomAccessFile to create aRandomAccessSource
for- Returns:
- the newly created
RandomAccessSource
- Throws:
java.io.IOException
-
createBestSource
public RandomAccessSource createBestSource(java.nio.channels.FileChannel channel) throws java.io.IOException
Creates aRandomAccessSource
based on memory mapping a file channel. Unless you are explicitly working with a FileChannel already, it is better to usecreateBestSource(String)
. If the file is large, it will be opened using a paging strategy.- Parameters:
filename
- the name of the file or resource to create theRandomAccessSource
for- Returns:
- the newly created
RandomAccessSource
- Throws:
java.io.IOException
-
createRanged
public RandomAccessSource createRanged(RandomAccessSource source, long[] ranges) throws java.io.IOException
- Throws:
java.io.IOException
-
createByReadingToMemory
private RandomAccessSource createByReadingToMemory(java.lang.String filename) throws java.io.IOException
Creates a newRandomAccessSource
by reading the specified file/resource into memory- Parameters:
filename
- the name of the resource to read- Returns:
- the newly created
RandomAccessSource
- Throws:
java.io.IOException
- if reading the underling file or stream fails
-
createByReadingToMemory
private RandomAccessSource createByReadingToMemory(java.io.InputStream is) throws java.io.IOException
Creates a newRandomAccessSource
by reading the specified file/resource into memory- Parameters:
is
- the name of the resource to read- Returns:
- the newly created
RandomAccessSource
- Throws:
java.io.IOException
- if reading the underling file or stream fails
-
-