com.itextpdf.text.pdf
Class RandomAccessFileOrArray

java.lang.Object
  extended by com.itextpdf.text.pdf.RandomAccessFileOrArray
All Implemented Interfaces:
DataInput

public class RandomAccessFileOrArray
extends Object
implements DataInput

Intended to be layered on top of a low level RandomAccessSource object. Provides functionality useful during parsing:

Author:
Paulo Soares, Kevin Day

Constructor Summary
RandomAccessFileOrArray(byte[] arrayIn)
          Deprecated. use RandomAccessSourceFactory.createSource(byte[]) and RandomAccessFileOrArray(RandomAccessSource) instead
RandomAccessFileOrArray(InputStream is)
          Deprecated. use RandomAccessSourceFactory.createSource(InputStream) and RandomAccessFileOrArray(RandomAccessSource) instead
RandomAccessFileOrArray(RandomAccessFileOrArray source)
          Deprecated. use createView() instead
RandomAccessFileOrArray(RandomAccessSource byteSource)
          Creates a RandomAccessFileOrArray that wraps the specified byte source.
RandomAccessFileOrArray(String filename)
          Deprecated. use RandomAccessFileOrArray(RandomAccessSource) instead
RandomAccessFileOrArray(String filename, boolean forceRead, boolean plainRandomAccess)
          Deprecated. use RandomAccessSourceFactory.createBestSource(String) and RandomAccessFileOrArray(RandomAccessSource) instead
RandomAccessFileOrArray(URL url)
          Deprecated. use RandomAccessSourceFactory.createSource(URL) and RandomAccessFileOrArray(RandomAccessSource) instead
 
Method Summary
 void close()
           
 RandomAccessSource createSourceView()
           
 RandomAccessFileOrArray createView()
          Creates an independent view of this object (with it's own file pointer and pushback queue).
protected  RandomAccessSource getByteSource()
          Deprecated. 
 long getFilePointer()
           
 long length()
           
 void pushBack(byte b)
          Pushes a byte back.
 int read()
          Reads a single byte
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 boolean readBoolean()
           
 byte readByte()
           
 char readChar()
           
 char readCharLE()
          Reads a Unicode character from this stream in little-endian order.
 double readDouble()
           
 double readDoubleLE()
           
 float readFloat()
           
 float readFloatLE()
           
 void readFully(byte[] b)
           
 void readFully(byte[] b, int off, int len)
           
 int readInt()
           
 int readIntLE()
          Reads a signed 32-bit integer from this stream in little-endian order.
 String readLine()
           
 long readLong()
           
 long readLongLE()
           
 short readShort()
           
 short readShortLE()
          Reads a signed 16-bit number from this stream in little-endian order.
 String readString(int length, String encoding)
          Reads a String from the font file as bytes using the given encoding.
 int readUnsignedByte()
           
 long readUnsignedInt()
          Reads an unsigned 32-bit integer from this stream.
 long readUnsignedIntLE()
           
 int readUnsignedShort()
           
 int readUnsignedShortLE()
          Reads an unsigned 16-bit number from this stream in little-endian order.
 String readUTF()
           
 void reOpen()
          Deprecated. 
 void seek(long pos)
           
 long skip(long n)
           
 int skipBytes(int n)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomAccessFileOrArray

@Deprecated
public RandomAccessFileOrArray(String filename)
                        throws IOException
Deprecated. use RandomAccessFileOrArray(RandomAccessSource) instead

Parameters:
filename -
Throws:
IOException

RandomAccessFileOrArray

@Deprecated
public RandomAccessFileOrArray(RandomAccessFileOrArray source)
Deprecated. use createView() instead

Creates an independent view of the specified source. Closing the new object will not close the source. Closing the source will have adverse effect on the behavior of the new view.

Parameters:
source - the source for the new independent view

RandomAccessFileOrArray

public RandomAccessFileOrArray(RandomAccessSource byteSource)
Creates a RandomAccessFileOrArray that wraps the specified byte source. The byte source will be closed when this RandomAccessFileOrArray is closed.

Parameters:
byteSource - the byte source to wrap

RandomAccessFileOrArray

@Deprecated
public RandomAccessFileOrArray(String filename,
                                          boolean forceRead,
                                          boolean plainRandomAccess)
                        throws IOException
Deprecated. use RandomAccessSourceFactory.createBestSource(String) and RandomAccessFileOrArray(RandomAccessSource) instead

Constructs a new RandomAccessFileOrArrayObject

Parameters:
filename - the file to open (can be a file system file or one of the following url strings: file://, http://, https://, jar:, wsjar:, vfszip:
forceRead - if true, the entire file will be read into memory
plainRandomAccess - if true, a regular RandomAccessFile is used to access the file contents. If false, a memory mapped file will be used, unless the file cannot be mapped into memory, in which case regular RandomAccessFile will be used
Throws:
IOException - if there is a failure opening or reading the file

RandomAccessFileOrArray

@Deprecated
public RandomAccessFileOrArray(URL url)
                        throws IOException
Deprecated. use RandomAccessSourceFactory.createSource(URL) and RandomAccessFileOrArray(RandomAccessSource) instead

Parameters:
url -
Throws:
IOException

RandomAccessFileOrArray

@Deprecated
public RandomAccessFileOrArray(InputStream is)
                        throws IOException
Deprecated. use RandomAccessSourceFactory.createSource(InputStream) and RandomAccessFileOrArray(RandomAccessSource) instead

Parameters:
is -
Throws:
IOException

RandomAccessFileOrArray

@Deprecated
public RandomAccessFileOrArray(byte[] arrayIn)
Deprecated. use RandomAccessSourceFactory.createSource(byte[]) and RandomAccessFileOrArray(RandomAccessSource) instead

Parameters:
arrayIn - byte[]
Throws:
IOException
Method Detail

createView

public RandomAccessFileOrArray createView()
Creates an independent view of this object (with it's own file pointer and pushback queue). Closing the new object will not close this object. Closing this object will have adverse effect on the view.

Returns:
the new view

createSourceView

public RandomAccessSource createSourceView()

getByteSource

@Deprecated
protected RandomAccessSource getByteSource()
Deprecated. 


pushBack

public void pushBack(byte b)
Pushes a byte back. The next get() will return this byte instead of the value from the underlying data source

Parameters:
b - the byte to push

read

public int read()
         throws IOException
Reads a single byte

Returns:
the byte, or -1 if EOF is reached
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Throws:
IOException

read

public int read(byte[] b)
         throws IOException
Throws:
IOException

readFully

public void readFully(byte[] b)
               throws IOException
Specified by:
readFully in interface DataInput
Throws:
IOException

readFully

public void readFully(byte[] b,
                      int off,
                      int len)
               throws IOException
Specified by:
readFully in interface DataInput
Throws:
IOException

skip

public long skip(long n)
          throws IOException
Throws:
IOException

skipBytes

public int skipBytes(int n)
              throws IOException
Specified by:
skipBytes in interface DataInput
Throws:
IOException

reOpen

@Deprecated
public void reOpen()
            throws IOException
Deprecated. 

Throws:
IOException

close

public void close()
           throws IOException
Throws:
IOException

length

public long length()
            throws IOException
Throws:
IOException

seek

public void seek(long pos)
          throws IOException
Throws:
IOException

getFilePointer

public long getFilePointer()
                    throws IOException
Throws:
IOException

readBoolean

public boolean readBoolean()
                    throws IOException
Specified by:
readBoolean in interface DataInput
Throws:
IOException

readByte

public byte readByte()
              throws IOException
Specified by:
readByte in interface DataInput
Throws:
IOException

readUnsignedByte

public int readUnsignedByte()
                     throws IOException
Specified by:
readUnsignedByte in interface DataInput
Throws:
IOException

readShort

public short readShort()
                throws IOException
Specified by:
readShort in interface DataInput
Throws:
IOException

readShortLE

public final short readShortLE()
                        throws IOException
Reads a signed 16-bit number from this stream in little-endian order. The method reads two bytes from this stream, starting at the current stream pointer. If the two bytes read, in order, are b1 and b2, where each of the two values is between 0 and 255, inclusive, then the result is equal to:
     (short)((b2 << 8) | b1)
 

This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.

Returns:
the next two bytes of this stream, interpreted as a signed 16-bit number.
Throws:
EOFException - if this stream reaches the end before reading two bytes.
IOException - if an I/O error occurs.

readUnsignedShort

public int readUnsignedShort()
                      throws IOException
Specified by:
readUnsignedShort in interface DataInput
Throws:
IOException

readUnsignedShortLE

public final int readUnsignedShortLE()
                              throws IOException
Reads an unsigned 16-bit number from this stream in little-endian order. This method reads two bytes from the stream, starting at the current stream pointer. If the bytes read, in order, are b1 and b2, where 0 <= b1, b2 <= 255, then the result is equal to:
     (b2 << 8) | b1
 

This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.

Returns:
the next two bytes of this stream, interpreted as an unsigned 16-bit integer.
Throws:
EOFException - if this stream reaches the end before reading two bytes.
IOException - if an I/O error occurs.

readChar

public char readChar()
              throws IOException
Specified by:
readChar in interface DataInput
Throws:
IOException

readCharLE

public final char readCharLE()
                      throws IOException
Reads a Unicode character from this stream in little-endian order. This method reads two bytes from the stream, starting at the current stream pointer. If the bytes read, in order, are b1 and b2, where 0 <= b1, b2 <= 255, then the result is equal to:
     (char)((b2 << 8) | b1)
 

This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.

Returns:
the next two bytes of this stream as a Unicode character.
Throws:
EOFException - if this stream reaches the end before reading two bytes.
IOException - if an I/O error occurs.

readInt

public int readInt()
            throws IOException
Specified by:
readInt in interface DataInput
Throws:
IOException

readIntLE

public final int readIntLE()
                    throws IOException
Reads a signed 32-bit integer from this stream in little-endian order. This method reads 4 bytes from the stream, starting at the current stream pointer. If the bytes read, in order, are b1, b2, b3, and b4, where 0 <= b1, b2, b3, b4 <= 255, then the result is equal to:
     (b4 << 24) | (b3 << 16) + (b2 << 8) + b1
 

This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.

Returns:
the next four bytes of this stream, interpreted as an int.
Throws:
EOFException - if this stream reaches the end before reading four bytes.
IOException - if an I/O error occurs.

readUnsignedInt

public final long readUnsignedInt()
                           throws IOException
Reads an unsigned 32-bit integer from this stream. This method reads 4 bytes from the stream, starting at the current stream pointer. If the bytes read, in order, are b1, b2, b3, and b4, where 0 <= b1, b2, b3, b4 <= 255, then the result is equal to:
     (b1 << 24) | (b2 << 16) + (b3 << 8) + b4
 

This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.

Returns:
the next four bytes of this stream, interpreted as a long.
Throws:
EOFException - if this stream reaches the end before reading four bytes.
IOException - if an I/O error occurs.

readUnsignedIntLE

public final long readUnsignedIntLE()
                             throws IOException
Throws:
IOException

readLong

public long readLong()
              throws IOException
Specified by:
readLong in interface DataInput
Throws:
IOException

readLongLE

public final long readLongLE()
                      throws IOException
Throws:
IOException

readFloat

public float readFloat()
                throws IOException
Specified by:
readFloat in interface DataInput
Throws:
IOException

readFloatLE

public final float readFloatLE()
                        throws IOException
Throws:
IOException

readDouble

public double readDouble()
                  throws IOException
Specified by:
readDouble in interface DataInput
Throws:
IOException

readDoubleLE

public final double readDoubleLE()
                          throws IOException
Throws:
IOException

readLine

public String readLine()
                throws IOException
Specified by:
readLine in interface DataInput
Throws:
IOException

readUTF

public String readUTF()
               throws IOException
Specified by:
readUTF in interface DataInput
Throws:
IOException

readString

public String readString(int length,
                         String encoding)
                  throws IOException
Reads a String from the font file as bytes using the given encoding.

Parameters:
length - the length of bytes to read
encoding - the given encoding
Returns:
the String read
Throws:
IOException - the font file could not be read


Copyright © 2013. All Rights Reserved.