com.itextpdf.text.io
Class RandomAccessSourceFactory

java.lang.Object
  extended by com.itextpdf.text.io.RandomAccessSourceFactory

public final class RandomAccessSourceFactory
extends Object

Factory to create RandomAccessSource objects based on various types of sources

Since:
5.3.5

Constructor Summary
RandomAccessSourceFactory()
          Creates a factory that will give preference to accessing the underling data source using memory mapped files
 
Method Summary
 RandomAccessSource createBestSource(FileChannel channel)
          Creates a RandomAccessSource based on memory mapping a file channel.
 RandomAccessSource createBestSource(String filename)
          Creates a RandomAccessSource based on a filename string.
 RandomAccessSource createRanged(RandomAccessSource source, long[] ranges)
           
 RandomAccessSource createSource(byte[] data)
          Creates a RandomAccessSource based on a byte array
 RandomAccessSource createSource(InputStream is)
          Creates a RandomAccessSource based on an InputStream.
 RandomAccessSource createSource(RandomAccessFile raf)
           
 RandomAccessSource createSource(URL url)
          Creates a RandomAccessSource based on a URL.
 RandomAccessSourceFactory setExclusivelyLockFile(boolean exclusivelyLockFile)
           
 RandomAccessSourceFactory setForceRead(boolean forceRead)
          Determines whether the full content of the source will be read into memory
 RandomAccessSourceFactory setUsePlainRandomAccess(boolean usePlainRandomAccess)
          Determines whether RandomAccessFile should be used as the primary data access mechanism
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomAccessSourceFactory

public RandomAccessSourceFactory()
Creates a factory that will give preference to accessing the underling data source using memory mapped files

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 whether RandomAccessFile should be used as the primary data access mechanism

Parameters:
usePlainRandomAccess - whether RandomAccessFile 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 a RandomAccessSource based on a byte array

Parameters:
data - the byte array
Returns:
the newly created RandomAccessSource

createSource

public RandomAccessSource createSource(RandomAccessFile raf)
                                throws IOException
Throws:
IOException

createSource

public RandomAccessSource createSource(URL url)
                                throws IOException
Creates a RandomAccessSource based on a URL. The data available at the URL is read into memory and used as the source for the RandomAccessSource

Parameters:
url - the url to read from
Returns:
the newly created RandomAccessSource
Throws:
IOException

createSource

public RandomAccessSource createSource(InputStream is)
                                throws IOException
Creates a RandomAccessSource based on an InputStream. The full content of the InputStream is read into memory and used as the source for the RandomAccessSource

Parameters:
is - the stream to read from
Returns:
the newly created RandomAccessSource
Throws:
IOException

createBestSource

public RandomAccessSource createBestSource(String filename)
                                    throws IOException
Creates a 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

Parameters:
filename - the name of the file or resource to create the RandomAccessSource for
Returns:
the newly created RandomAccessSource
Throws:
IOException

createBestSource

public RandomAccessSource createBestSource(FileChannel channel)
                                    throws IOException
Creates a 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.

Parameters:
filename - the name of the file or resource to create the RandomAccessSource for
Returns:
the newly created RandomAccessSource
Throws:
IOException

createRanged

public RandomAccessSource createRanged(RandomAccessSource source,
                                       long[] ranges)
                                throws IOException
Throws:
IOException


Copyright © 2013. All Rights Reserved.