org.apache.pdfbox.io
Class RandomAccessFile

java.lang.Object
  extended by org.apache.pdfbox.io.RandomAccessFile
All Implemented Interfaces:
RandomAccess, RandomAccessRead, SequentialRead

public class RandomAccessFile
extends Object
implements RandomAccess

An interface to allow temp PDF data to be stored in a scratch file on the disk to reduce memory consumption.

Version:
$Revision: 1.2 $
Author:
Ben Litchfield

Constructor Summary
RandomAccessFile(File file, String mode)
          Constructor.
 
Method Summary
 void close()
          Release resources that are being held.
 long length()
          The total number of bytes that are available.
 int read()
          Read a single byte of data.
 int read(byte[] b, int offset, int length)
          Read a buffer of data.
 void seek(long position)
          Seek to a position in the data.
 void write(byte[] b, int offset, int length)
          Write a buffer of data to the stream.
 void write(int b)
          Write a byte to the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomAccessFile

public RandomAccessFile(File file,
                        String mode)
                 throws FileNotFoundException
Constructor.

Parameters:
file - The file to write the data to.
mode - The writing mode.
Throws:
FileNotFoundException - If the file cannot be created.
Method Detail

close

public void close()
           throws IOException
Release resources that are being held.

Specified by:
close in interface SequentialRead
Throws:
IOException - If there is an error closing this resource.

seek

public void seek(long position)
          throws IOException
Seek to a position in the data.

Specified by:
seek in interface RandomAccessRead
Parameters:
position - The position to seek to.
Throws:
IOException - If there is an error while seeking.

read

public int read()
         throws IOException
Read a single byte of data.

Specified by:
read in interface SequentialRead
Returns:
The byte of data that is being read.
Throws:
IOException - If there is an error while reading the data.

read

public int read(byte[] b,
                int offset,
                int length)
         throws IOException
Read a buffer of data.

Specified by:
read in interface SequentialRead
Parameters:
b - The buffer to write the data to.
offset - Offset into the buffer to start writing.
length - The amount of data to attempt to read.
Returns:
The number of bytes that were actually read.
Throws:
IOException - If there was an error while reading the data.

length

public long length()
            throws IOException
The total number of bytes that are available.

Specified by:
length in interface RandomAccessRead
Returns:
The number of bytes available.
Throws:
IOException - If there is an IO error while determining the length of the data stream.

write

public void write(byte[] b,
                  int offset,
                  int length)
           throws IOException
Write a buffer of data to the stream.

Specified by:
write in interface RandomAccess
Parameters:
b - The buffer to get the data from.
offset - An offset into the buffer to get the data from.
length - The length of data to write.
Throws:
IOException - If there is an error while writing the data.

write

public void write(int b)
           throws IOException
Write a byte to the stream.

Specified by:
write in interface RandomAccess
Parameters:
b - The byte to write.
Throws:
IOException - If there is an IO error while writing.


Copyright © 2002-2012 The Apache Software Foundation. All Rights Reserved.