PDF Clown
0.1.2

org.pdfclown.bytes
Class Buffer

java.lang.Object
  extended by org.pdfclown.bytes.Buffer
All Implemented Interfaces:
Closeable, IBuffer, IInputStream, IOutputStream, IStream, IDataWrapper

public final class Buffer
extends Object
implements IBuffer

Byte buffer.

Version:
0.1.2, 01/29/12
Author:
Stefano Chizzolini (http://www.stefanochizzolini.it)

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.pdfclown.bytes.IBuffer
IBuffer.IListener
 
Constructor Summary
Buffer()
           
Buffer(BufferedReader dataStream)
           
Buffer(byte[] data)
           
Buffer(byte[] data, ByteOrder byteOrder)
           
Buffer(InputStream dataStream)
           
Buffer(int capacity)
           
 
Method Summary
 void addListener(IBuffer.IListener listener)
          Adds the specified listener.
 IBuffer append(byte data)
          Appends a byte to the buffer.
 IBuffer append(byte[] data)
          Appends a byte array to the buffer.
 IBuffer append(byte[] data, int offset, int length)
          Appends a byte range to the buffer.
 IBuffer append(IInputStream data)
          Appends an IInputStream to the buffer.
 IBuffer append(String data)
          Appends a string to the buffer.
 Buffer clone()
          Gets a clone of the buffer.
 void close()
           
 void decode(Filter filter, PdfDictionary parameters)
          Applies the specified filter to decode the buffer.
 void delete(int index, int length)
          Deletes a byte chunk from the buffer.
 byte[] encode(Filter filter, PdfDictionary parameters)
          Applies the specified filter to encode the buffer.
protected  void finalize()
           
 int getByte(int index)
          Gets the byte at a specified location.
 byte[] getByteArray(int index, int length)
          Gets the byte range beginning at a specified location.
 ByteOrder getByteOrder()
          Gets the byte order.
 int getCapacity()
          Gets the allocated buffer size.
 long getLength()
          Gets the length of the stream.
 long getPosition()
          Gets the pointer position.
 String getString(int index, int length)
          Gets the string beginning at a specified location.
 void insert(int index, byte[] data)
          Inserts a byte array into the buffer.
 void insert(int index, byte[] data, int offset, int length)
          Inserts a byte range into the buffer.
 void insert(int index, IInputStream data)
          Inserts an IInputStream into the buffer.
 void insert(int index, String data)
          Inserts a string into the buffer.
 boolean isDirty()
          Gets whether this buffer has changed.
 void read(byte[] data)
          Reads a sequence of bytes.
 void read(byte[] data, int offset, int length)
          Reads a sequence of bytes.
 byte readByte()
          Reads a byte.
 int readInt()
          Reads an integer.
 int readInt(int length)
          Reads a variable-length integer.
 String readLine()
          Reads the next line of text.
 short readShort()
          Reads a short integer.
 String readString(int length)
          Reads a string.
 int readUnsignedByte()
          Reads an unsigned byte integer.
 int readUnsignedShort()
          Reads an unsigned short integer.
 boolean removeListener(IBuffer.IListener listener)
          Removes the specified listener.
 void replace(int index, byte[] data)
          Replaces the buffer contents with a byte array.
 void replace(int index, byte[] data, int offset, int length)
          Replaces the buffer contents with a byte range.
 void replace(int index, IInputStream data)
          Replaces the buffer contents with an IInputStream.
 void replace(int index, String data)
          Replaces the buffer contents with a string.
 void seek(long position)
          Sets the pointer absolute position.
 void setByteOrder(ByteOrder value)
          Sets the byte order.
 void setDirty(boolean value)
           
 void setLength(int value)
          Sets the used buffer size.
 void setPosition(long value)
          Sets the pointer position.
 void skip(long offset)
          Sets the pointer relative position.
 byte[] toByteArray()
          Gets the buffer data copied to a newly-allocated byte array.
 void write(byte[] data)
          Writes a byte array into the stream.
 void write(byte[] data, int offset, int length)
          Writes a byte range into the stream.
 void write(IInputStream data)
          Writes an IInputStream into the stream.
 void write(String data)
          Writes a string into the stream.
 void writeTo(IOutputStream stream)
          Writes the buffer data to a stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.pdfclown.bytes.IInputStream
hashCode
 

Constructor Detail

Buffer

public Buffer()

Buffer

public Buffer(int capacity)

Buffer

public Buffer(BufferedReader dataStream)

Buffer

public Buffer(InputStream dataStream)

Buffer

public Buffer(byte[] data)

Buffer

public Buffer(byte[] data,
              ByteOrder byteOrder)
Method Detail

addListener

public void addListener(IBuffer.IListener listener)
Description copied from interface: IBuffer
Adds the specified listener.

Specified by:
addListener in interface IBuffer
Parameters:
listener - Listener to add.

append

public IBuffer append(byte data)
Description copied from interface: IBuffer
Appends a byte to the buffer.

Specified by:
append in interface IBuffer
Parameters:
data - Byte to copy.
Returns:
This buffer.

append

public IBuffer append(byte[] data)
Description copied from interface: IBuffer
Appends a byte array to the buffer.

Specified by:
append in interface IBuffer
Parameters:
data - Byte array to copy.
Returns:
This buffer.

append

public IBuffer append(byte[] data,
                      int offset,
                      int length)
Description copied from interface: IBuffer
Appends a byte range to the buffer.

Specified by:
append in interface IBuffer
Parameters:
data - Byte array from which the byte range has to be copied.
offset - Location in the byte array at which copying begins.
length - Number of bytes to copy.
Returns:
This buffer.

append

public IBuffer append(String data)
Description copied from interface: IBuffer
Appends a string to the buffer.

Specified by:
append in interface IBuffer
Parameters:
data - String to copy.
Returns:
This buffer.

append

public IBuffer append(IInputStream data)
Description copied from interface: IBuffer
Appends an IInputStream to the buffer.

Specified by:
append in interface IBuffer
Parameters:
data - Source data to copy.
Returns:
This buffer.

clone

public Buffer clone()
Description copied from interface: IBuffer
Gets a clone of the buffer.

Specified by:
clone in interface IBuffer
Overrides:
clone in class Object
Returns:
Deep copy of the buffer.

decode

public void decode(Filter filter,
                   PdfDictionary parameters)
Description copied from interface: IBuffer
Applies the specified filter to decode the buffer.

Specified by:
decode in interface IBuffer
Parameters:
filter - Filter to use for decoding the buffer.
parameters - Decoding parameters.

delete

public void delete(int index,
                   int length)
Description copied from interface: IBuffer
Deletes a byte chunk from the buffer.

Specified by:
delete in interface IBuffer
Parameters:
index - Location at which deletion has to begin.
length - Number of bytes to delete.

encode

public byte[] encode(Filter filter,
                     PdfDictionary parameters)
Description copied from interface: IBuffer
Applies the specified filter to encode the buffer.

Specified by:
encode in interface IBuffer
Parameters:
filter - Filter to use for encoding the buffer.
parameters - Encoding parameters.
Returns:
Encoded buffer.

getByte

public int getByte(int index)
Description copied from interface: IBuffer
Gets the byte at a specified location.

Specified by:
getByte in interface IBuffer
Parameters:
index - A location in the buffer.
Returns:
Byte at the specified location.

getByteArray

public byte[] getByteArray(int index,
                           int length)
Description copied from interface: IBuffer
Gets the byte range beginning at a specified location.

Specified by:
getByteArray in interface IBuffer
Parameters:
index - Location at which the byte range has to begin.
length - Number of bytes to copy.
Returns:
Byte range beginning at the specified location.

getString

public String getString(int index,
                        int length)
Description copied from interface: IBuffer
Gets the string beginning at a specified location.

Specified by:
getString in interface IBuffer
Parameters:
index - Location at which the string has to begin.
length - Number of bytes to convert.
Returns:
String beginning at the specified location.

getCapacity

public int getCapacity()
Description copied from interface: IBuffer
Gets the allocated buffer size.

Specified by:
getCapacity in interface IBuffer
Returns:
Allocated buffer size.

insert

public void insert(int index,
                   byte[] data)
Description copied from interface: IBuffer
Inserts a byte array into the buffer.

Specified by:
insert in interface IBuffer
Parameters:
index - Location at which the byte array has to be inserted.
data - Byte array to insert.

insert

public void insert(int index,
                   byte[] data,
                   int offset,
                   int length)
Description copied from interface: IBuffer
Inserts a byte range into the buffer.

Specified by:
insert in interface IBuffer
Parameters:
index - Location at which the byte range has to be inserted.
data - Byte array from which the byte range has to be copied.
offset - Location in the byte array at which copying begins.
length - Number of bytes to copy.

insert

public void insert(int index,
                   String data)
Description copied from interface: IBuffer
Inserts a string into the buffer.

Specified by:
insert in interface IBuffer
Parameters:
index - Location at which the string has to be inserted.
data - String to insert.

insert

public void insert(int index,
                   IInputStream data)
Description copied from interface: IBuffer
Inserts an IInputStream into the buffer.

Specified by:
insert in interface IBuffer
Parameters:
index - Location at which the IInputStream has to be inserted.
data - Source data to copy.

removeListener

public boolean removeListener(IBuffer.IListener listener)
Description copied from interface: IBuffer
Removes the specified listener.

Specified by:
removeListener in interface IBuffer
Parameters:
listener - Listener to remove.
Returns:
Whether the specified listener has been removed.

replace

public void replace(int index,
                    byte[] data)
Description copied from interface: IBuffer
Replaces the buffer contents with a byte array.

Specified by:
replace in interface IBuffer
Parameters:
index - Location at which the byte array has to be copied.
data - Byte array to copy.

replace

public void replace(int index,
                    byte[] data,
                    int offset,
                    int length)
Description copied from interface: IBuffer
Replaces the buffer contents with a byte range.

Specified by:
replace in interface IBuffer
Parameters:
index - Location at which the byte range has to be copied.
data - Byte array from which the byte range has to be copied.
offset - Location in the byte array at which copying begins.
length - Number of bytes to copy.

replace

public void replace(int index,
                    String data)
Description copied from interface: IBuffer
Replaces the buffer contents with a string.

Specified by:
replace in interface IBuffer
Parameters:
index - Location at which the string has to be copied.
data - String to copy.

replace

public void replace(int index,
                    IInputStream data)
Description copied from interface: IBuffer
Replaces the buffer contents with an IInputStream.

Specified by:
replace in interface IBuffer
Parameters:
index - Location at which the IInputStream has to be copied.
data - Source data to copy.

setDirty

public void setDirty(boolean value)
Specified by:
setDirty in interface IBuffer
See Also:
IBuffer.isDirty()

setLength

public void setLength(int value)
Description copied from interface: IBuffer
Sets the used buffer size.

Specified by:
setLength in interface IBuffer
Parameters:
value - New length.

writeTo

public void writeTo(IOutputStream stream)
Description copied from interface: IBuffer
Writes the buffer data to a stream.

Specified by:
writeTo in interface IBuffer
Parameters:
stream - Target stream.

getByteOrder

public ByteOrder getByteOrder()
Description copied from interface: IInputStream
Gets the byte order.

Specified by:
getByteOrder in interface IInputStream

getPosition

public long getPosition()
Description copied from interface: IInputStream
Gets the pointer position.

Specified by:
getPosition in interface IInputStream

isDirty

public boolean isDirty()
Description copied from interface: IBuffer
Gets whether this buffer has changed.

Specified by:
isDirty in interface IBuffer

read

public void read(byte[] data)
Description copied from interface: IInputStream
Reads a sequence of bytes.

This operation causes the stream pointer to advance after the read data.

Specified by:
read in interface IInputStream
Parameters:
data - Target byte array.

read

public void read(byte[] data,
                 int offset,
                 int length)
Description copied from interface: IInputStream
Reads a sequence of bytes.

This operation causes the stream pointer to advance after the read data.

Specified by:
read in interface IInputStream
Parameters:
data - Target byte array.
offset - Location in the byte array at which storing begins.
length - Number of bytes to read.

readByte

public byte readByte()
              throws EOFException
Description copied from interface: IInputStream
Reads a byte.

This operation causes the stream pointer to advance after the read data.

Specified by:
readByte in interface IInputStream
Throws:
EOFException

readInt

public int readInt()
            throws EOFException
Description copied from interface: IInputStream
Reads an integer.

This operation causes the stream pointer to advance after the read data.

Specified by:
readInt in interface IInputStream
Throws:
EOFException

readInt

public int readInt(int length)
            throws EOFException
Description copied from interface: IInputStream
Reads a variable-length integer.

This operation causes the stream pointer to advance after the read data.

Specified by:
readInt in interface IInputStream
Parameters:
length - Number of bytes to read.
Throws:
EOFException

readLine

public String readLine()
                throws EOFException
Description copied from interface: IInputStream
Reads the next line of text.

This operation causes the stream pointer to advance after the read data.

Specified by:
readLine in interface IInputStream
Throws:
EOFException

readShort

public short readShort()
                throws EOFException
Description copied from interface: IInputStream
Reads a short integer.

This operation causes the stream pointer to advance after the read data.

Specified by:
readShort in interface IInputStream
Throws:
EOFException

readString

public String readString(int length)
Description copied from interface: IInputStream
Reads a string.

This operation causes the stream pointer to advance after the read data.

Specified by:
readString in interface IInputStream
Parameters:
length - Number of bytes to read.

readUnsignedByte

public int readUnsignedByte()
                     throws EOFException
Description copied from interface: IInputStream
Reads an unsigned byte integer.

This operation causes the stream pointer to advance after the read data.

Specified by:
readUnsignedByte in interface IInputStream
Throws:
EOFException

readUnsignedShort

public int readUnsignedShort()
                      throws EOFException
Description copied from interface: IInputStream
Reads an unsigned short integer.

This operation causes the stream pointer to advance after the read data.

Specified by:
readUnsignedShort in interface IInputStream
Throws:
EOFException

seek

public void seek(long position)
Description copied from interface: IInputStream
Sets the pointer absolute position.

Specified by:
seek in interface IInputStream

setByteOrder

public void setByteOrder(ByteOrder value)
Description copied from interface: IInputStream
Sets the byte order.

Specified by:
setByteOrder in interface IInputStream

setPosition

public void setPosition(long value)
Description copied from interface: IInputStream
Sets the pointer position.

Specified by:
setPosition in interface IInputStream

skip

public void skip(long offset)
Description copied from interface: IInputStream
Sets the pointer relative position.

Specified by:
skip in interface IInputStream

toByteArray

public byte[] toByteArray()
Description copied from interface: IDataWrapper
Gets the buffer data copied to a newly-allocated byte array.

Specified by:
toByteArray in interface IDataWrapper

getLength

public long getLength()
Description copied from interface: IStream
Gets the length of the stream.

Specified by:
getLength in interface IStream

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException

write

public void write(byte[] data)
Description copied from interface: IOutputStream
Writes a byte array into the stream.

Specified by:
write in interface IOutputStream
Parameters:
data - Byte array to write into the stream.

write

public void write(byte[] data,
                  int offset,
                  int length)
Description copied from interface: IOutputStream
Writes a byte range into the stream.

Specified by:
write in interface IOutputStream
Parameters:
data - Byte array to write into the stream.
offset - Location in the byte array at which writing begins.
length - Number of bytes to write.

write

public void write(String data)
Description copied from interface: IOutputStream
Writes a string into the stream.

Specified by:
write in interface IOutputStream
Parameters:
data - String to write into the stream.

write

public void write(IInputStream data)
Description copied from interface: IOutputStream
Writes an IInputStream into the stream.

Specified by:
write in interface IOutputStream
Parameters:
data - IInputStream to write into the stream.

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

PDF Clown
0.1.2

Project home page

Copyright © 2006-2013 Stefano Chizzolini. Some Rights Reserved.
This documentation is available under the terms of the GNU Free Documentation License.