java.lang.Objectjavax.baja.nre.util.ByteBuffer
ByteBuffer is a dynamically growable byte array which has implicit support for the DataOuput and DataInput interfaces.
| Field Summary | |
protected boolean |
bigEndian
Flag which determines whether to use big or little endian byte ordering |
protected byte[] |
buffer
Byte array buffer. |
protected int |
length
Actual length of valid data in buffer. |
protected int |
pos
Pos is used to store the next read index |
| Constructor Summary | |
ByteBuffer()
Create a buffer with an inital capacity of 64 bytes. |
|
ByteBuffer(byte[] buf)
Create a ByteBuffer of length buf.length
using the specified byte array for the internal buffer. |
|
ByteBuffer(byte[] buf,
int len)
Create a ByteBuffer of length len using
the specified byte array for the internal buffer. |
|
ByteBuffer(int initialCapacity)
Create a buffer with the specified inital capacity. |
|
| Method Summary | |
int |
available()
Return the number of bytes available based on the current read position and the buffer length. |
void |
dump()
Dump the byte buffer to standard output. |
java.lang.String |
dumpToString()
Dump the byte buffer to a String. |
boolean |
endsWith(byte[] b)
Return true if the current byte buffer ends with the specified byte array. |
boolean |
endsWith(int b)
Return true if the current byte buffer ends with the specified byte. |
byte[] |
getBytes()
Get a direct reference to the internal buffer array. |
java.io.InputStream |
getInputStream()
Get a new InputStream for reading the internal buffer. |
int |
getLength()
Get the length of the buffer. |
java.io.OutputStream |
getOutputStream()
Get a new OutputStream for the writing to the internal buffer. |
int |
getPosition()
Get the current read position index. |
int |
indexOf(byte[] b)
Get first the index of the specified byte array pattern or return -1 if the pattern is not found. |
int |
indexOf(byte[] b,
int fromIndex)
Get first the index of the specified byte array pattern or return -1 if the pattern is not found. |
int |
indexOf(int b)
Get first the index of the specified byte or return -1 if the byte is not found. |
int |
indexOf(int b,
int fromIndex)
Get first the index of the specified byte or return -1 if the byte is not found. |
boolean |
isBigEndian()
Get the big endian flag for byte ordering. |
int |
lastIndexOf(byte[] b)
Get last the index of the specified byte array pattern or return -1 if the pattern is not found. |
int |
lastIndexOf(byte[] b,
int fromIndex)
Get last the index of the specified byte array pattern or return -1 if the pattern is not found. |
int |
lastIndexOf(int b)
Get last the index of the specified byte or return -1 if the byte is not found. |
int |
lastIndexOf(int b,
int fromIndex)
Get last the index of the specified byte or return -1 if the byte is not found. |
int |
peek()
Peek at the next byte to read without actually changing the read position. |
int |
read()
Read the next byte from the internal buffer. |
int |
read(byte[] buf)
Read buf.length bytes from the internal
buffer into the specified byte array. |
int |
read(byte[] buf,
int offset,
int len)
Read len bytes from the internal buffer
into the specified byte array at offset. |
boolean |
readBoolean()
Read a boolean from the internal buffer. |
byte |
readByte()
Read a 8-bit signed byte value value from the internal buffer. |
char |
readChar()
Read a unicode char from the internal buffer. |
double |
readDouble()
Read a 64-bit double value from the internal buffer. |
float |
readFloat()
Read a 32-bit float value from the internal buffer. |
int |
readFrom(java.io.InputStream in,
int len)
Read the specified number of bytes from the input stream into the internal buffer. |
void |
readFully(byte[] buf)
Read buf.length bytes from the internal
buffer into the specified byte array. |
void |
readFully(byte[] buf,
int offset,
int len)
Read len bytes from the internal buffer
into the specified byte array at offset. |
void |
readFullyFrom(java.io.InputStream in,
int len)
Read the specified number of bytes from the input stream into the internal buffer. |
int |
readInt()
Read a 32-bit integer value from the internal buffer. |
java.lang.String |
readLine()
Always throw an UnsupportedOperationException. |
long |
readLong()
Read a 64-bit long value from the internal buffer. |
short |
readShort()
Read a 16-bit signed byte value from the internal buffer. |
void |
readToEnd(java.io.InputStream in)
Read from the specified InputStream into the internal buffer. |
int |
readUnsignedByte()
Read a 8-bit unsigned byte value from the internal buffer. |
int |
readUnsignedShort()
Read a 16-bit unsigned byte value from the internal buffer. |
java.lang.String |
readUTF()
Read a UTF encoded string from the internal buffer. |
void |
reset()
Set the length and pos back to 0. |
void |
seek(int pos)
Move the current read position index. |
void |
setBigEndian(boolean bigEndian)
Set the big endian flag for byte ordering. |
void |
setBuffer(byte[] newBuf)
|
void |
setLength(int newLen)
|
int |
skipBytes(int n)
Skip n bytes in the internal buffer. |
boolean |
startsWith(byte[] b)
Return true if the current byte buffer starts with the specified byte array. |
boolean |
startsWith(int b)
Return true if the current byte buffer starts with the specified byte. |
byte[] |
toByteArray()
Get a copy of the byte array sized to actual length. |
static int |
utfEncodedSize(char c)
Utility which returns the number of bytes required to encode the given character as part of a string with the modified UTF-8 format used by DataOutput.writeUTF(). |
static int |
utfEncodedSize(java.lang.String string)
Utility which returns the number of bytes required to encode the given string with the modified UTF-8 format used by DataOutput.writeUTF(). |
void |
write(byte[] buf)
Write the specified buffer to the internal buffer. |
void |
write(byte[] buf,
int offset,
int len)
Writes len bytes from the specified byte array
starting at offset to the internal buffer. |
void |
write(int b)
Write the specified byte to the internal buffer. |
void |
writeBoolean(boolean v)
Write a boolean value to the internal buffer. |
void |
writeByte(int v)
Write a 8 bit value to the internal buffer. |
void |
writeBytes(java.lang.String s)
Write the specified String's bytes to the internal buffer. |
void |
writeChar(int v)
Write a unicode char to the internal buffer. |
void |
writeChars(java.lang.String s)
Write the specified String's characters to the internal buffer. |
void |
writeDouble(double v)
Write a 64 bit double to the internal buffer. |
void |
writeFloat(float v)
Write a 32 bit float to the internal buffer. |
void |
writeInt(int v)
Write a 32 bit value to the internal buffer. |
void |
writeLong(long v)
Write a 64 bit value to the internal buffer. |
void |
writeShort(int v)
Write a 16 bit value to the internal buffer. |
void |
writeTo(java.io.DataOutput out)
Write the entire internal buffer to the specified output. |
void |
writeTo(java.io.DataOutput out,
int offset,
int len)
Write len bytes of the internal buffer
starting at offset to the specified output. |
void |
writeTo(java.io.OutputStream out)
Write the internal buffer in its entirity to the specified output stream. |
void |
writeTo(java.io.OutputStream out,
int offset,
int len)
Write len bytes of the internal buffer
starting at offset to the specified output
stream. |
void |
writeUTF(java.lang.String s)
Write the specified String's to the internal buffer using modified UTF-8 format. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected int length
protected byte[] buffer
protected int pos
protected boolean bigEndian
| Constructor Detail |
public ByteBuffer(byte[] buf,
int len)
len using
the specified byte array for the internal buffer.
public ByteBuffer(byte[] buf)
buf.length
using the specified byte array for the internal buffer.
public ByteBuffer(int initialCapacity)
public ByteBuffer()
| Method Detail |
public int getLength()
public void reset()
public void seek(int pos)
public int getPosition()
public byte[] getBytes()
public byte[] toByteArray()
public boolean isBigEndian()
public void setBigEndian(boolean bigEndian)
public java.io.InputStream getInputStream()
public java.io.OutputStream getOutputStream()
public int readFrom(java.io.InputStream in,
int len)
throws java.io.IOException
java.io.IOException
public void readFullyFrom(java.io.InputStream in,
int len)
throws java.io.IOException
java.io.EOFException - if the end of the stream
is reached before len bytes
are read.
java.io.IOException
public void readToEnd(java.io.InputStream in)
throws java.io.IOException
java.io.IOException
public void writeTo(java.io.OutputStream out)
throws java.io.IOException
java.io.IOException
public void writeTo(java.io.OutputStream out,
int offset,
int len)
throws java.io.IOException
len bytes of the internal buffer
starting at offset to the specified output
stream.
java.io.IOException
public void writeTo(java.io.DataOutput out)
throws java.io.IOException
java.io.IOException
public void writeTo(java.io.DataOutput out,
int offset,
int len)
throws java.io.IOException
len bytes of the internal buffer
starting at offset to the specified output.
java.io.IOExceptionpublic void write(int b)
write in interface java.io.DataOutputpublic void write(byte[] buf)
write in interface java.io.DataOutput
public void write(byte[] buf,
int offset,
int len)
len bytes from the specified byte array
starting at offset to the internal buffer.
write in interface java.io.DataOutputpublic void writeBoolean(boolean v)
writeBoolean in interface java.io.DataOutputpublic void writeByte(int v)
writeByte in interface java.io.DataOutputpublic void writeShort(int v)
writeShort in interface java.io.DataOutputpublic void writeChar(int v)
writeChar in interface java.io.DataOutputpublic void writeInt(int v)
writeInt in interface java.io.DataOutputpublic void writeLong(long v)
writeLong in interface java.io.DataOutputpublic void writeFloat(float v)
writeFloat in interface java.io.DataOutputpublic void writeDouble(double v)
writeDouble in interface java.io.DataOutputpublic void writeBytes(java.lang.String s)
writeBytes in interface java.io.DataOutputpublic void writeChars(java.lang.String s)
writeChars in interface java.io.DataOutput
public void writeUTF(java.lang.String s)
throws java.io.UTFDataFormatException
writeUTF in interface java.io.DataOutputjava.io.UTFDataFormatExceptionpublic static int utfEncodedSize(java.lang.String string)
public static int utfEncodedSize(char c)
public int available()
public int peek()
throws java.io.IOException
java.io.IOException
public int read()
throws java.io.IOException
java.io.EOFException - if there are no more
bytes available in the buffer.
java.io.IOException
public int read(byte[] buf)
throws java.io.IOException
buf.length bytes from the internal
buffer into the specified byte array.
java.io.IOException
public int read(byte[] buf,
int offset,
int len)
throws java.io.IOException
len bytes from the internal buffer
into the specified byte array at offset.
java.io.IOException
public void readFully(byte[] buf)
throws java.io.IOException
buf.length bytes from the internal
buffer into the specified byte array.
readFully in interface java.io.DataInputjava.io.IOException
public void readFully(byte[] buf,
int offset,
int len)
throws java.io.IOException
len bytes from the internal buffer
into the specified byte array at offset.
readFully in interface java.io.DataInputjava.io.IOException
public int skipBytes(int n)
throws java.io.IOException
n bytes in the internal buffer.
skipBytes in interface java.io.DataInputjava.io.IOException
public boolean readBoolean()
throws java.io.IOException
readBoolean in interface java.io.DataInputjava.io.IOException
public byte readByte()
throws java.io.IOException
readByte in interface java.io.DataInputjava.io.IOException
public int readUnsignedByte()
throws java.io.IOException
readUnsignedByte in interface java.io.DataInputjava.io.IOException
public short readShort()
throws java.io.IOException
readShort in interface java.io.DataInputjava.io.IOException
public int readUnsignedShort()
throws java.io.IOException
readUnsignedShort in interface java.io.DataInputjava.io.IOException
public char readChar()
throws java.io.IOException
readChar in interface java.io.DataInputjava.io.IOException
public int readInt()
throws java.io.IOException
readInt in interface java.io.DataInputjava.io.IOException
public long readLong()
throws java.io.IOException
readLong in interface java.io.DataInputjava.io.IOException
public float readFloat()
throws java.io.IOException
readFloat in interface java.io.DataInputjava.io.IOException
public double readDouble()
throws java.io.IOException
readDouble in interface java.io.DataInputjava.io.IOException
public java.lang.String readLine()
throws java.io.IOException
readLine in interface java.io.DataInputjava.io.IOException
public java.lang.String readUTF()
throws java.io.IOException
readUTF in interface java.io.DataInputjava.io.IOExceptionpublic boolean startsWith(int b)
public boolean startsWith(byte[] b)
public boolean endsWith(int b)
public boolean endsWith(byte[] b)
public int indexOf(int b)
public int indexOf(int b,
int fromIndex)
b - byte to search for.fromIndex - the index to start the search from.
There is no restriction on the value of fromIndex. If
it is greater than the length of this string, it has the
same effect as if it were equal to the length. If it is
negative, it has the same effect as if it 0.public int indexOf(byte[] b)
public int indexOf(byte[] b,
int fromIndex)
b - byte array containing pattern to search for.fromIndex - the index to start the search from.
There is no restriction on the value of fromIndex. If
it is greater than the length of this string, it has the
same effect as if it were equal to the length. If it is
negative, it has the same effect as if it were 0.public int lastIndexOf(int b)
public int lastIndexOf(int b,
int fromIndex)
b - byte array containing pattern to search for.fromIndex - the index to start the search from.
There is no restriction on the value of fromIndex. If
it is greater than the length of this string, it has the
same effect as if it were equal to the length. If it is
negative, it has the same effect as if it were -1: -1 is
returned.public int lastIndexOf(byte[] b)
public int lastIndexOf(byte[] b,
int fromIndex)
b - byte array containing pattern to search for.fromIndex - the index to start the search from.
There is no restriction on the value of fromIndex. If
it is greater than the length of this string, it has the
same effect as if it were equal to the length. If it is
negative, it has the same effect as if it were -1: -1 is
returned.public void setLength(int newLen)
public void setBuffer(byte[] newBuf)
public void dump()
public java.lang.String dumpToString()
Copyright © 2000-2016 Tridium Inc. All rights reserved.