You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.



All Packages  This Package  Class Hierarchy  Class Search  Index

Class calypso.util.ByteBuf

java.lang.Object
   |
   +----calypso.util.ByteBuf

This class is similar to java/lang/StringBuffer with the following changes:

  • Stores bytes, not chars
  • None of the methods are synchronized
  • There is no sharing of the character array
  • Converting to a String requires a copy of the character data
  • Alloc and Recycle are provided to speed up allocation
  • A bunch of useful operations are provided (comparisons, etc.)


public final class  ByteBuf
     extends java.lang.Object
{
          // Fields 2
     private int count;
     private byte[] value;

          // Constructors 4
     public ByteBuf();
     public ByteBuf(byte[], int, int);
     public ByteBuf(int);
     public ByteBuf(String);

          // Methods 57
     public static synchronized ByteBuf Alloc();
     public static synchronized void EmptyRecycler();
     public static synchronized void Recycle(ByteBuf);
     public ByteBuf append(boolean);
     public ByteBuf append(byte);
     public ByteBuf append(byte[]);
     public ByteBuf append(byte[], int, int);
     public ByteBuf append(ByteBuf);
     public ByteBuf append(double);
     public ByteBuf append(float);
     public ByteBuf append(int);
     public ByteBuf append(Object);
     public ByteBuf append(String);
     public ByteBuf append(long);
     public byte byteAt(int);
     public int capacity();
     static void classFinalize() throws Throwable;
     public void ensureCapacity(int);
     public boolean equals(ByteBuf);
     public boolean equals(Object);
     public boolean equals(String);
     public boolean equalsIgnoreCase(ByteBuf);
     public void fullDump(PrintStream);
     public void fullDump(PrintStream, int, int);
     public void getBytes(int, int, byte[], int);
     public int indexOf(int);
     public int indexOf(int, int);
     public ByteBuf insert(int, boolean);
     public ByteBuf insert(int, byte);
     public ByteBuf insert(int, byte[]);
     public ByteBuf insert(int, double);
     public ByteBuf insert(int, float);
     public ByteBuf insert(int, int);
     public ByteBuf insert(int, Object);
     public ByteBuf insert(int, String);
     public ByteBuf insert(int, long);
     public int length();
     public InputStream makeInputStream();
     public int read(InputStream, int) throws IOException;
     public int read(RandomAccessFile, int) throws IOException;
     public boolean regionMatches(boolean, int, byte[], int, int);
     public boolean regionMatches(boolean, int, ByteBuf, int, int);
     public boolean regionMatches(boolean, int, String, int, int);
     public boolean regionMatches(int, byte[], int, int);
     public boolean regionMatches(int, ByteBuf, int, int);
     public boolean regionMatches(int, String, int, int);
     public void remove(int);
     public void remove(int, int);
     public ByteBuf reverse();
     public void setByteAt(int, byte);
     public void setLength(int);
     public byte[] toBytes();
     public int toInteger() throws NumberFormatException;
     public String toString();
     public ByteBuf trim();
     public void write(OutputStream) throws IOException;
     public void write(RandomAccessFile) throws IOException;
}



Fields


value

   private byte[] value


count

   private int count



Constructors


ByteBuf

   public ByteBuf() 

Constructs an empty String buffer.



ByteBuf

   public ByteBuf(int length) 

Constructs an empty byte buffer with the specified initial length.

Parameter Description
length the initial length



ByteBuf

   public ByteBuf(String str) 

Constructs a byte buffer with the specified initial value.

Parameter Description
str the initial value of the buffer



ByteBuf

   public ByteBuf(byte[] bytes, 
                  int offset, 
                  int length) 



Methods


Alloc

   public static synchronized ByteBuf Alloc() 

Constructs an empty String buffer, reusing one from the recycler.



Recycle

   public static synchronized void Recycle(ByteBuf aBuf) 

Release a ByteBuf to the recycler. It is up to the caller to ensure that buffer is no longer being used otherwise unpredicatable program behavior will result.



EmptyRecycler

   public static synchronized void EmptyRecycler() 

Empty the recycler discarding any cached ByteBuf objects



classFinalize

   static void classFinalize()  throws Throwable


length

   public int length() 

Returns the length (character count) of the buffer.



capacity

   public int capacity() 

Returns the current capacity of the String buffer. The capacity is the amount of storage available for newly inserted characters; beyond which an allocation will occur.



ensureCapacity

   public void ensureCapacity(int minimumCapacity) 

Ensures that the capacity of the buffer is at least equal to the specified minimum.

Parameter Description
minimumCapacity the minimum desired capacity



setLength

   public void setLength(int newLength) 

Sets the length of the String. If the length is reduced, characters are lost. If the length is extended, the values of the new characters are set to 0.

Parameter Description
newLength the new length of the buffer

Throws: StringIndexOutOfBoundsException
If the length is invalid.


byteAt

   public byte byteAt(int index) 

Returns the byte at the specified index. An index ranges from 0..length()-1.

Parameter Description
index the index of the desired character

Throws: StringIndexOutOfBoundsException
If the index is invalid.


getBytes

   public void getBytes(int srcBegin, 
                        int srcEnd, 
                        byte[] dst, 
                        int dstBegin) 

Copies the characters of the specified substring (determined by srcBegin and srcEnd) into the character array, starting at the array's dstBegin location. Both srcBegin and srcEnd must be legal indexes into the buffer.

Parameter Description
srcBegin begin copy at this offset in the String
srcEnd stop copying at this offset in the String
dst the array to copy the data into
dstBegin offset into dst

Throws: StringIndexOutOfBoundsException
If there is an invalid index into the buffer.


setByteAt

   public void setByteAt(int index, 
                         byte b) 

Changes the byte at the specified index to be ch.

Parameter Description
index the index of the character
ch the new character

Throws: StringIndexOutOfBoundsException
If the index is invalid.


append

   public ByteBuf append(Object obj) 

Appends an object to the end of this buffer.

Parameter Description
obj the object to be appended

Returns:
the ByteBuf itself, NOT a new one.


append

   public ByteBuf append(String str) 

Appends a String to the end of this buffer. This just appends one byte per char; it strips off the upper 8 bits. If you want the localized method of converting chars to bytes, use append(String.getBytes()).

Parameter Description
str the String to be appended

Returns:
the ByteBuf itself, NOT a new one.


append

   public ByteBuf append(byte[] str) 

Appends an array of bytes to the end of this buffer.

Parameter Description
str the characters to be appended

Returns:
the ByteBuf itself, NOT a new one.


append

   public ByteBuf append(byte[] str, 
                         int offset, 
                         int len) 

Appends a part of an array of characters to the end of this buffer.

Parameter Description
str the characters to be appended
offset where to start
len the number of characters to add

Returns:
the ByteBuf itself, NOT a new one.


append

   public ByteBuf append(ByteBuf buf) 


append

   public ByteBuf append(boolean b) 

Appends a boolean to the end of this buffer.

Parameter Description
b the boolean to be appended

Returns:
the ByteBuf itself, NOT a new one.


append

   public ByteBuf append(byte b) 

Appends a byte to the end of this buffer.

Parameter Description
ch the character to be appended

Returns:
the ByteBuf itself, NOT a new one.


append

   public ByteBuf append(int i) 

Appends an integer to the end of this buffer.

Parameter Description
i the integer to be appended

Returns:
the ByteBuf itself, NOT a new one.


append

   public ByteBuf append(long l) 

Appends a long to the end of this buffer.

Parameter Description
l the long to be appended

Returns:
the ByteBuf itself, NOT a new one.


append

   public ByteBuf append(float f) 

Appends a float to the end of this buffer.

Parameter Description
f the float to be appended

Returns:
the ByteBuf itself, NOT a new one.


append

   public ByteBuf append(double d) 

Appends a double to the end of this buffer.

Parameter Description
d the double to be appended

Returns:
the ByteBuf itself, NOT a new one.


insert

   public ByteBuf insert(int offset, 
                         Object obj) 

Inserts an object into the String buffer.

Parameter Description
offset the offset at which to insert
obj the object to insert

Returns:
the ByteBuf itself, NOT a new one.
Throws: StringIndexOutOfBoundsException
If the offset is invalid.


insert

   public ByteBuf insert(int offset, 
                         String str) 

Inserts a String into the String buffer.

Parameter Description
offset the offset at which to insert
str the String to insert

Returns:
the ByteBuf itself, NOT a new one.
Throws: StringIndexOutOfBoundsException
If the offset is invalid.


insert

   public ByteBuf insert(int offset, 
                         byte[] str) 

Inserts an array of bytes into the String buffer.

Parameter Description
offset the offset at which to insert
str the characters to insert

Returns:
the ByteBuf itself, NOT a new one.
Throws: StringIndexOutOfBoundsException
If the offset is invalid.


insert

   public ByteBuf insert(int offset, 
                         boolean b) 

Inserts a boolean into the String buffer.

Parameter Description
offset the offset at which to insert
b the boolean to insert

Returns:
the ByteBuf itself, NOT a new one.
Throws: StringIndexOutOfBoundsException
If the offset is invalid.


insert

   public ByteBuf insert(int offset, 
                         byte b) 

Inserts a byte into the String buffer.

Parameter Description
offset the offset at which to insert
ch the character to insert

Returns:
the ByteBuf itself, NOT a new one.
Throws: StringIndexOutOfBoundsException
If the offset invalid.


insert

   public ByteBuf insert(int offset, 
                         int i) 

Inserts an integer into the String buffer.

Parameter Description
offset the offset at which to insert
i the integer to insert

Returns:
the ByteBuf itself, NOT a new one.
Throws: StringIndexOutOfBoundsException
If the offset is invalid.


insert

   public ByteBuf insert(int offset, 
                         long l) 

Inserts a long into the String buffer.

Parameter Description
offset the offset at which to insert
l the long to insert

Returns:
the ByteBuf itself, NOT a new one.
Throws: StringIndexOutOfBoundsException
If the offset is invalid.


insert

   public ByteBuf insert(int offset, 
                         float f) 

Inserts a float into the String buffer.

Parameter Description
offset the offset at which to insert
f the float to insert

Returns:
the ByteBuf itself, NOT a new one.
Throws: StringIndexOutOfBoundsException
If the offset is invalid.


insert

   public ByteBuf insert(int offset, 
                         double d) 

Inserts a double into the String buffer.

Parameter Description
offset the offset at which to insert
d the double to insert

Returns:
the ByteBuf itself, NOT a new one.
Throws: StringIndexOutOfBoundsException
If the offset is invalid.


reverse

   public ByteBuf reverse() 

Reverse the order of the characters in the String buffer.



toString

   public String toString() 

Converts to a String representing the data in the buffer.

Overrides:
toString in class Object


toBytes

   public byte[] toBytes() 


equalsIgnoreCase

   public boolean equalsIgnoreCase(ByteBuf anotherString) 

Compares this ByteBuf to another ByteBuf. Returns true if the other ByteBuf is equal to this ByteBuf; that is, has the same length and the same characters in the same sequence. Upper case characters are folded to lower case before they are compared.

Parameter Description
anotherString the String to compare this String against

Returns:
true if the Strings are equal, ignoring case; false otherwise.


equals

   public boolean equals(Object aObject) 
Overrides:
equals in class Object


equals

   public boolean equals(ByteBuf anotherString) 

Compares this ByteBuf to another ByteBuf. Returns true if the other ByteBuf is equal to this ByteBuf; that is, has the same length and the same characters in the same sequence.

Parameter Description
anotherString the String to compare this String against

Returns:
true if the Strings are equal, ignoring case; false otherwise.


equals

   public boolean equals(String anotherString) 

Compares this ByteBuf to another String. Returns true if the other String is equal to this ByteBuf; that is, has the same length and the same characters in the same sequence. (No localization is done; if the string doesn't contain 8-bit chars, it won't be equal to this ByteBuf.)

Parameter Description
anotherString the String to compare this String against

Returns:
true if the Strings are equal, ignoring case; false otherwise.


regionMatches

   public boolean regionMatches(int toffset, 
                                byte[] other, 
                                int ooffset, 
                                int len) 

Tests if two byte regions are equal.

If toffset or ooffset is negative, or if toffset+length is greater than the length of this ByteBuf, or if ooffset+length is greater than the length of the argument, then this method returns false.

Parameter Description
toffset the starting offset of the subregion in this ByteBuf.
other the other bytes.
ooffset the starting offset of the subregion in the argument.
len the number of bytes to compare.

Returns:
true if the specified subregion of this ByteBuf exactly matches the specified subregion of the argument; false otherwise.


regionMatches

   public boolean regionMatches(boolean ignoreCase, 
                                int toffset, 
                                byte[] other, 
                                int ooffset, 
                                int len) 

Tests if two byte regions are equal.

If toffset or ooffset is negative, or if toffset+length is greater than the length of this ByteBuf, or if ooffset+length is greater than the length of the argument, then this method returns false.

Parameter Description
ignoreCase if true, ignore case when comparing bytes (treating them as characters).
toffset the starting offset of the subregion in this ByteBuf.
other the other bytes.
ooffset the starting offset of the subregion in the argument.
len the number of bytes to compare.

Returns:
true if the specified subregion of this ByteBuf matches the specified subregion of the argument; false otherwise. Whether the matching is exact or case insensitive depends on the ignoreCase argument.


regionMatches

   public boolean regionMatches(int toffset, 
                                ByteBuf other, 
                                int ooffset, 
                                int len) 


regionMatches

   public boolean regionMatches(boolean ignoreCase, 
                                int toffset, 
                                ByteBuf other, 
                                int ooffset, 
                                int len) 


regionMatches

   public boolean regionMatches(int toffset, 
                                String other, 
                                int ooffset, 
                                int len) 

Tests if two byte regions are equal.

If toffset or ooffset is negative, or if toffset+length is greater than the length of this ByteBuf, or if ooffset+length is greater than the length of the argument, then this method returns false.

Parameter Description
toffset the starting offset of the subregion in this ByteBuf.
other the other String.
ooffset the starting offset of the subregion in the argument.
len the number of bytes/characters to compare.

Returns:
true if the specified subregion of this ByteBuf exactly matches the specified subregion of the String argument; false otherwise.


regionMatches

   public boolean regionMatches(boolean ignoreCase, 
                                int toffset, 
                                String other, 
                                int ooffset, 
                                int len) 

Tests if two byte regions are equal.

If toffset or ooffset is negative, or if toffset+length is greater than the length of this ByteBuf, or if ooffset+length is greater than the length of the argument, then this method returns false.

Parameter Description
ignoreCase if true, ignore case when comparing bytes (treating them as characters).
toffset the starting offset of the subregion in this ByteBuf.
other the other String.
ooffset the starting offset of the subregion in the String argument.
len the number of bytes to compare.

Returns:
true if the specified subregion of this ByteBuf matches the specified subregion of the String argument; false otherwise. Whether the matching is exact or case insensitive depends on the ignoreCase argument.


indexOf

   public int indexOf(int ch) 


indexOf

   public int indexOf(int ch, 
                      int fromIndex) 


remove

   public void remove(int fromIndex) 


remove

   public void remove(int fromIndex, 
                      int toIndex) 

Remove characters from the ByteBuf starting at fromIndex and up to but not including toIndex. If toIndex is beyond the length of the ByteBuf then it is automatically clamped to the end of the ByteBuf. If fromIndex is out of range a StringIndexOutOfBoundsException is thrown.



toInteger

   public int toInteger()  throws NumberFormatException


trim

   public ByteBuf trim() 


fullDump

   public void fullDump(PrintStream out) 

Write to the given output stream a detailed description of each byte in this buffer.



fullDump

   public void fullDump(PrintStream out, 
                        int start, 
                        int end) 

Write to the given output stream a detailed description of the given bytes in this buffer.



read

   public int read(InputStream file, 
                   int max_bytes)  throws IOException

Invokes InputStream.read(), appending the bytes to this Bytebuf.

Returns:
the number of bytes read, or -1 if eof.


read

   public int read(RandomAccessFile file, 
                   int max_bytes)  throws IOException

Invokes RandomAccessFile.read(), appending the bytes to this Bytebuf. (A RandomAccessFile is not an InputStream, because Java is a crock.)

Returns:
the number of bytes read, or -1 if eof.


write

   public void write(OutputStream out)  throws IOException

Writes the contents to the given output stream.



write

   public void write(RandomAccessFile out)  throws IOException

Writes the contents to the given RandomAccessFile.



makeInputStream

   public InputStream makeInputStream() 

Creates a new InputStream whose content is this ByteBuf. Note that changing the ByteBuf can affect the stream; the data is not copied.



All Packages  This Package  Class Hierarchy  Class Search  Index
Freshly brewed Java API Documentation automatically generated with polardoc Version 1.0.4