nl.justobjects.toolkit.collection
Class ByteBuffer

java.lang.Object
  |
  +--nl.justobjects.toolkit.collection.ByteBuffer

public class ByteBuffer
extends java.lang.Object

Simple implementation of extensible byte array.

Purpose

Implementation

Examples


$Source: /var/cvs/justobjects/toolkit/src/nl/justobjects/toolkit/collection/ByteBuffer.java,v $

Version:
$Id: ByteBuffer.java,v 1.3 2003/01/06 00:23:48 just Exp $
Author:
$Author: just $ - Just van den Broecke - Just Objects ©

Field Summary
protected  byte[] buf
          The buffer where data is stored.
protected  int count
          The number of valid bytes in the buffer.
 
Constructor Summary
ByteBuffer()
          Creates a new byte buffer.
ByteBuffer(int size)
          Creates a new byte buffer, with a buffer capacity of the specified size, in bytes.
 
Method Summary
 void add(byte b)
          Add the specified byte to this byte buffer.
 void add(byte[] b)
          Adds bytes from the specified byte array
 void add(byte[] b, int off, int len)
          Adds len bytes from the specified byte array starting at offset off to this byte buffer.
 void add(char c)
           
 void add(java.lang.String s)
           
 void reset()
          Resets the count field of this byte buffer to zero
 int size()
          Returns the current size of the buffer.
 byte[] toByteArray()
          Creates a newly allocated byte array.
 java.lang.String toString()
          Converts the buffer's contents into a string, translating bytes into characters according to the platform's default character encoding.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

buf

protected byte[] buf
The buffer where data is stored.

count

protected int count
The number of valid bytes in the buffer.
Constructor Detail

ByteBuffer

public ByteBuffer()
Creates a new byte buffer. The buffer capacity is initially 32 bytes, though its size increases if necessary.

ByteBuffer

public ByteBuffer(int size)
Creates a new byte buffer, with a buffer capacity of the specified size, in bytes.
Parameters:
size - the initial size.
Throws:
java.lang.IllegalArgumentException - if size is negative.
Method Detail

add

public void add(byte b)
Add the specified byte to this byte buffer.
Parameters:
b - the byte to be written.

add

public void add(byte[] b)
Adds bytes from the specified byte array
Parameters:
b - the data.

add

public void add(byte[] b,
                int off,
                int len)
Adds len bytes from the specified byte array starting at offset off to this byte buffer.
Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.

add

public void add(char c)

add

public void add(java.lang.String s)

reset

public void reset()
Resets the count field of this byte buffer to zero

toByteArray

public byte[] toByteArray()
Creates a newly allocated byte array. Its size is the current size of this buffer and the valid contents of the buffer have been copied into it.
Returns:
the current contents of this buffer, as a byte array.
See Also:
ByteArrayOutputStream.size()

size

public int size()
Returns the current size of the buffer.
Returns:
the value of the count field, which is the number of valid bytes in this buffer.
See Also:
ByteArrayOutputStream.count

toString

public java.lang.String toString()
Converts the buffer's contents into a string, translating bytes into characters according to the platform's default character encoding.
Overrides:
toString in class java.lang.Object
Returns:
String translated from the buffer's contents.
Since:
JDK1.1


Copyright © 2000-2001 - Just Objects B.V.