PDF Clown
0.0.8

it.stefanochizzolini.clown.bytes
Class Buffer

java.lang.Object
  extended by it.stefanochizzolini.clown.bytes.Buffer
All Implemented Interfaces:
IBuffer, IInputStream, IOutputStream, IStream, Closeable

public final class Buffer
extends Object
implements IBuffer

Byte buffer.

Version:
0.0.8
Author:
Stefano Chizzolini (http://www.stefanochizzolini.it)

Constructor Summary
Buffer()
           
Buffer(BufferedReader dataStream)
           
Buffer(byte[] data)
           
Buffer(byte[] data, ByteOrder byteOrder)
           
Buffer(InputStream dataStream)
           
Buffer(int capacity)
           
 
Method Summary
 void append(byte data)
          Appends a byte to the buffer.
 void append(byte[] data)
          Appends a byte array to the buffer.
 void append(byte[] data, int offset, int length)
          Appends a byte range to the buffer.
 void append(IInputStream data)
          Appends an IInputStream to the buffer.
 void append(String data)
          Appends a string to the buffer.
 Buffer clone()
          Gets a clone of the buffer.
 void close()
           
 void decode(Filter filter)
          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)
          Applies the specified filter to encode the buffer.
protected  boolean ensureCapacity(int additionalLength)
          Check whether the buffer capacity has sufficient room for adding data.
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.
 void read(byte[] data)
          Reads a sequence of bytes from the stream and advances the position within the stream.
 void read(byte[] data, int offset, int length)
          Reads a sequence of bytes from the stream and advances the position within the stream.
 byte readByte()
          Reads a byte from the stream and advances the position within the stream.
 int readInt()
          Reads an integer from the stream and advances the position within the stream.
 String readLine()
          Reads the next line of text.
 short readShort()
          Reads a short integer from the stream and advances the position within the stream.
 String readString(int length)
          Reads a string from the stream and advances the position within the stream.
 int readUnsignedByte()
          Reads an unsigned byte integer from the stream and advances the position within the stream.
 int readUnsignedShort()
          Reads an unsigned short integer from the stream and advances the position within the stream.
 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 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 it.stefanochizzolini.clown.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

append

public void 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.

append

public void 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.

append

public void 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.

append

public void 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.

append

public void 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.

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)
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.

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)
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.
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.

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.

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

getLength

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

Specified by:
getLength in interface IStream

getPosition

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

Specified by:
getPosition in interface IInputStream

read

public void read(byte[] data)
Description copied from interface: IInputStream
Reads a sequence of bytes from the stream and advances the position within the stream.

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 from the stream and advances the position within the stream.

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 copy.

readByte

public byte readByte()
              throws EOFException
Description copied from interface: IInputStream
Reads a byte from the stream and advances the position within the stream.

Specified by:
readByte in interface IInputStream
Returns:
Byte from the stream.
Throws:
EOFException

readInt

public int readInt()
            throws EOFException
Description copied from interface: IInputStream
Reads an integer from the stream and advances the position within the stream.

Specified by:
readInt in interface IInputStream
Returns:
Integer from the stream.
Throws:
EOFException

readLine

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

Specified by:
readLine in interface IInputStream
Returns:
String from the stream.
Throws:
EOFException

readShort

public short readShort()
                throws EOFException
Description copied from interface: IInputStream
Reads a short integer from the stream and advances the position within the stream.

Specified by:
readShort in interface IInputStream
Returns:
Short integer from the stream.
Throws:
EOFException

readString

public String readString(int length)
Description copied from interface: IInputStream
Reads a string from the stream and advances the position within the stream.

Specified by:
readString in interface IInputStream
Parameters:
length - Number of bytes to read.
Returns:
String from the stream.

readUnsignedByte

public int readUnsignedByte()
                     throws EOFException
Description copied from interface: IInputStream
Reads an unsigned byte integer from the stream and advances the position within the stream.

Specified by:
readUnsignedByte in interface IInputStream
Returns:
Unsigned byte integer from the stream.
Throws:
EOFException

readUnsignedShort

public int readUnsignedShort()
                      throws EOFException
Description copied from interface: IInputStream
Reads an unsigned short integer from the stream and advances the position within the stream.

Specified by:
readUnsignedShort in interface IInputStream
Returns:
Unsigned short integer from the stream.
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: IInputStream
Gets the buffer data copied to a newly-allocated byte array.

Specified by:
toByteArray in interface IInputStream

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.

ensureCapacity

protected boolean ensureCapacity(int additionalLength)
Check whether the buffer capacity has sufficient room for adding data.


finalize

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

PDF Clown
0.0.8

Project home page

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