Secure iNet Factory

com.jscape.util
Class ByteBuffer

java.lang.Object
  extended by com.jscape.util.ByteBuffer

public class ByteBuffer
extends java.lang.Object

Class for managing an array of bytes.


Constructor Summary
ByteBuffer()
          Creates a new instance of ByteBuffer
ByteBuffer(byte[] buffer)
          Creates a new instance of ByteBuffer
ByteBuffer(int size)
          Creates a new ByteBuffer object.
 
Method Summary
 void append(byte b)
          Appends data to this ByteBuffer
 void append(byte[] buf)
          Appends data to this ByteBuffer
 void append(byte[] buf, int offset, int len)
          Appends data to this ByteBuffer
 void append(ByteBuffer buf)
          Appends data to this ByteBuffer
 void append(char c)
          Appends a character to this ByteBuffer.
 void append(char[] data)
          Appends data to this ByteBuffer
 void append(java.lang.String data, java.lang.String encoding)
          Appends data to this ByteBuffer
 boolean contains(byte[] data)
          Checks if data is contained in this buffer.
 boolean contains(byte[] data, boolean matchAll)
          Checks if data is contained in this buffer.
 boolean endsWith(java.lang.String str, java.lang.String encoding)
          Checks if buffer ends with specified String
 boolean equals(java.lang.Object obj)
          Checks for equality of this ByteBuffer.
 boolean equals(java.lang.String str, java.lang.String encoding)
          Checks if buffer equals specified String
 ByteBuffer getBuffer(int start)
          Gets a portion of this ByteBuffer data.
 ByteBuffer getBuffer(int start, int end)
          Gets a portion of this ByteBuffer data.
 int indexOf(byte data)
          Locates the index of the specified data.
 int indexOf(byte[] data)
          Locates the index of the specified data.
 int indexOf(byte[] data, int begin)
          Locates the index of the specified data.
 int indexOf(byte data, int begin)
          Locates the index of the specified data.
 int indexOf(java.lang.String str, java.lang.String encoding)
          Locates the index of the specified data.
 int indexOf(java.lang.String str, java.lang.String encoding, int begin)
          Locates the index of the specified data.
 int length()
          Gets the length of this ByteBuffer in bytes.
 boolean startsWith(java.lang.String str, java.lang.String encoding)
          Checks if buffer starts with specified String
 byte[] toByteArray()
          Gets buffer as a byte array.
 java.lang.String toString()
          Gets buffer as a String using system default character encoding.
 java.lang.String toString(java.lang.String encoding)
          Gets buffer as a String using provided character encoding.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ByteBuffer

public ByteBuffer()
Creates a new instance of ByteBuffer


ByteBuffer

public ByteBuffer(int size)
Creates a new ByteBuffer object.

Parameters:
size - int initial size of buffer

ByteBuffer

public ByteBuffer(byte[] buffer)
Creates a new instance of ByteBuffer

Parameters:
buffer - the data to initialize this ByteBuffer with
Method Detail

append

public void append(ByteBuffer buf)
Appends data to this ByteBuffer

Parameters:
buf - the ByteBuffer to appending from

append

public void append(byte[] buf,
                   int offset,
                   int len)
Appends data to this ByteBuffer

Parameters:
buf - a byte array
offset - the beginning index of array
len - the total number of bytes to appending, starting from offset

append

public void append(byte[] buf)
Appends data to this ByteBuffer

Parameters:
buf - a byte[]

append

public void append(byte b)
Appends data to this ByteBuffer

Parameters:
b - a single byte

append

public void append(java.lang.String data,
                   java.lang.String encoding)
            throws java.io.UnsupportedEncodingException
Appends data to this ByteBuffer

Parameters:
data - the data to appending
encoding - the character encoding to use
Throws:
java.io.UnsupportedEncodingException - if invalid encoding specified

append

public void append(char[] data)
Appends data to this ByteBuffer

Parameters:
data - the data to appending

append

public void append(char c)
Appends a character to this ByteBuffer.

Parameters:
c - the character to appending

toByteArray

public byte[] toByteArray()
Gets buffer as a byte array.

Returns:
a byte[]

toString

public java.lang.String toString()
Gets buffer as a String using system default character encoding.

Overrides:
toString in class java.lang.Object
Returns:
the buffer contents as a String

toString

public java.lang.String toString(java.lang.String encoding)
                          throws java.io.UnsupportedEncodingException
Gets buffer as a String using provided character encoding.

Parameters:
encoding - the character encoding to use
Returns:
the buffer encoded using specified encoding
Throws:
java.io.UnsupportedEncodingException - if encoding is not valid

length

public int length()
Gets the length of this ByteBuffer in bytes.

Returns:
length in bytes

getBuffer

public ByteBuffer getBuffer(int start,
                            int end)
Gets a portion of this ByteBuffer data.

Parameters:
start - the beginning index
end - the end index
Returns:
the buffer portion

getBuffer

public ByteBuffer getBuffer(int start)
Gets a portion of this ByteBuffer data.

Parameters:
start - the beginning index
Returns:
the buffer portion

indexOf

public int indexOf(byte data,
                   int begin)
Locates the index of the specified data.

Parameters:
data - the byte to search for
begin - the beginning index to start searching from
Returns:
the index of specified data or -1 if not found

indexOf

public int indexOf(byte data)
Locates the index of the specified data.

Parameters:
data - the byte[] to search for
Returns:
the index of specified data or -1 if not found

indexOf

public int indexOf(byte[] data,
                   int begin)
Locates the index of the specified data.

Parameters:
data - the byte[] to search for
begin - the beginning index to start searching from
Returns:
the index of specified data or -1 if not found

indexOf

public int indexOf(byte[] data)
Locates the index of the specified data.

Parameters:
data - the byte[] to search for
Returns:
the index of specified data or -1 if not found

indexOf

public int indexOf(java.lang.String str,
                   java.lang.String encoding,
                   int begin)
            throws java.io.UnsupportedEncodingException
Locates the index of the specified data.

Parameters:
str - the String to search for
encoding - the character encoding to use when performing search
begin - begin the beginning index
Returns:
the index of specified data or -1 if not found
Throws:
java.io.UnsupportedEncodingException - if encoding is invalid

contains

public boolean contains(byte[] data,
                        boolean matchAll)
Checks if data is contained in this buffer.

Parameters:
data - the data to check for
matchAll - if true then all data must be found in sequence, if false then only one byte of data must be found.

contains

public boolean contains(byte[] data)
Checks if data is contained in this buffer.

Parameters:
data - the data to check for

indexOf

public int indexOf(java.lang.String str,
                   java.lang.String encoding)
            throws java.io.UnsupportedEncodingException
Locates the index of the specified data.

Parameters:
str - the String to search for
encoding - the character encoding to use when performing search
Returns:
the index of the data found or -1 if not found
Throws:
java.io.UnsupportedEncodingException - if encoding is invalid

startsWith

public boolean startsWith(java.lang.String str,
                          java.lang.String encoding)
                   throws java.io.UnsupportedEncodingException
Checks if buffer starts with specified String

Parameters:
str - the String to check for
encoding - the character encoding to use
Returns:
true if buffer starts with specified String, false otherwise
Throws:
java.io.UnsupportedEncodingException - if encoding is invalid

endsWith

public boolean endsWith(java.lang.String str,
                        java.lang.String encoding)
                 throws java.io.UnsupportedEncodingException
Checks if buffer ends with specified String

Parameters:
str - the String to check for
encoding - the character encoding to use
Returns:
true if data ends with specified String, false otherwise
Throws:
java.io.UnsupportedEncodingException - if encoding is invalid

equals

public boolean equals(java.lang.String str,
                      java.lang.String encoding)
               throws java.io.UnsupportedEncodingException
Checks if buffer equals specified String

Parameters:
str - the String to check for
encoding - the character encoding to use
Returns:
true if data equals specified String, false otherwise
Throws:
java.io.UnsupportedEncodingException - if encoding is invalid

equals

public boolean equals(java.lang.Object obj)
Checks for equality of this ByteBuffer.

Overrides:
equals in class java.lang.Object
Parameters:
obj - a ByteBuffer
Returns:
true if equal, false otherwise

Secure iNet Factory

Copyright © JSCAPE LLC. 1999-2011. All Rights Reserved