Class RandomAccessSourceFactory
java.lang.Object
com.itextpdf.text.io.RandomAccessSourceFactory
Factory to create
RandomAccessSource objects based on various types of sources- Since:
- 5.3.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanWhether the underlying file should have a RW lock on it or just an R lockprivate booleanwhether the full content of the source should be read into memory at constructionprivate booleanWhetherRandomAccessFileshould be used instead of aFileChannel, where applicable -
Constructor Summary
ConstructorsConstructorDescriptionCreates a factory that will give preference to accessing the underling data source using memory mapped files -
Method Summary
Modifier and TypeMethodDescriptionCreates aRandomAccessSourcebased on a RandomAccessFile.createBestSource(String filename) Creates aRandomAccessSourcebased on a filename string.createBestSource(FileChannel channel) Creates aRandomAccessSourcebased on memory mapping a file channel.private RandomAccessSourceCreates a newRandomAccessSourceby reading the specified file/resource into memoryprivate RandomAccessSourcecreateByReadingToMemory(String filename) Creates a newRandomAccessSourceby reading the specified file/resource into memorycreateRanged(RandomAccessSource source, long[] ranges) createSource(byte[] data) Creates aRandomAccessSourcebased on a byte arrayCreates aRandomAccessSourcebased on anInputStream.createSource(URL url) Creates aRandomAccessSourcebased on a URL.setExclusivelyLockFile(boolean exclusivelyLockFile) setForceRead(boolean forceRead) Determines whether the full content of the source will be read into memorysetUsePlainRandomAccess(boolean usePlainRandomAccess) Determines whetherRandomAccessFileshould be used as the primary data access mechanism
-
Field Details
-
forceRead
private boolean forceReadwhether the full content of the source should be read into memory at construction -
usePlainRandomAccess
private boolean usePlainRandomAccessWhetherRandomAccessFileshould be used instead of aFileChannel, where applicable -
exclusivelyLockFile
private boolean exclusivelyLockFileWhether the underlying file should have a RW lock on it or just an R lock
-
-
Constructor Details
-
RandomAccessSourceFactory
public RandomAccessSourceFactory()Creates a factory that will give preference to accessing the underling data source using memory mapped files
-
-
Method Details
-
setForceRead
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
Determines whetherRandomAccessFileshould be used as the primary data access mechanism- Parameters:
usePlainRandomAccess- whetherRandomAccessFileshould be used as the primary data access mechanism- Returns:
- this object (this allows chaining of method calls)
-
setExclusivelyLockFile
-
createSource
Creates aRandomAccessSourcebased on a byte array- Parameters:
data- the byte array- Returns:
- the newly created
RandomAccessSource
-
createSource
- Throws:
IOException
-
createSource
Creates aRandomAccessSourcebased 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:
IOException
-
createSource
Creates aRandomAccessSourcebased 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:
IOException
-
createBestSource
Creates aRandomAccessSourcebased 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 usingRandomAccessFileaccess (if usePlainRandomAccess is true) This call will automatically failover to usingRandomAccessFileif the memory map operation fails- Parameters:
filename- the name of the file or resource to create theRandomAccessSourcefor- Returns:
- the newly created
RandomAccessSource - Throws:
IOException
-
createBestSource
Creates aRandomAccessSourcebased on a RandomAccessFile. The source will be opened using memory mapped file channel (if usePlainRandomAccess is false), or opened usingRandomAccessFileaccess (if usePlainRandomAccess is true) This call will automatically failover to usingRandomAccessFileif the memory map operation fails If the source couldn't be opened, the RandomAccessFile will be closed- Parameters:
raf- the RandomAccessFile to create aRandomAccessSourcefor- Returns:
- the newly created
RandomAccessSource - Throws:
IOException
-
createBestSource
Creates aRandomAccessSourcebased 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 theRandomAccessSourcefor- Returns:
- the newly created
RandomAccessSource - Throws:
IOException
-
createRanged
- Throws:
IOException
-
createByReadingToMemory
Creates a newRandomAccessSourceby reading the specified file/resource into memory- Parameters:
filename- the name of the resource to read- Returns:
- the newly created
RandomAccessSource - Throws:
IOException- if reading the underling file or stream fails
-
createByReadingToMemory
Creates a newRandomAccessSourceby reading the specified file/resource into memory- Parameters:
is- the name of the resource to read- Returns:
- the newly created
RandomAccessSource - Throws:
IOException- if reading the underling file or stream fails
-