|
UC Berkeley Group for User Interface Research Updated November 17, 2000 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.berkeley.guir.lib.collection.DataBuffer
Holds a buffer of bytes that can be resized, compacted, inserted into, removed, sliced, and diced. Useful for networking, file access, and other systems-level operations. As Chris Long astutely pointed out, this is the class to use when interfacing with C.
This software is distributed under the Berkeley Software License.
Revisions: - GUIRLib-v1.0-1.0.0, Jun 29 1999, JH Created class - GUIRLib-v1.2-1.0.0, Jun 22 2000, JH Touched for GUIRLib release - GUIRLib-v1.3-1.0.0, Aug 11 2000, JH Touched for GUIRLib release - GUIRLib-v1.4-1.0.0, Aug 31 2000, JH Touched for GUIRLib release
Constructor Summary | |
DataBuffer()
Create a new, empty DataBuffer. |
|
DataBuffer(byte[] buf)
Create a DataBuffer using the specified buffer. |
|
DataBuffer(byte[] buf,
int len)
Create a DataBuffer using the specified buffer and the specified length. |
|
DataBuffer(int len)
Create a new, empty DataBuffer with the specified buffer size. |
|
DataBuffer(String str)
Create a new DataBuffer containing this String. |
Method Summary | |
void |
append(byte bb)
Append a single byte to this current DataBuffer. |
void |
append(byte[] insertbuf)
Append the specified buffer to the end. |
void |
append(byte[] insertbuf,
int off,
int len)
Append the specified buffer to the end. |
void |
append(DataBuffer buf)
Append a DataBuffer to this current DataBuffer. |
void |
appendToFile(String strFileName)
Append the buffer to the specified file, creating the file if it does not exist. |
byte |
at(int index)
Retrieve the byte at the specified position. |
void |
clear()
Clear out the data in the buffer by setting the length to 0. |
void |
compact()
Compact the data buffer to the current size of the data. |
void |
copyBytes(byte[] buf,
int len)
Copy the bytes in the specified buffer over to this DataBuffer. |
void |
fill()
Fill the entire buffer with byte value 0. |
void |
fill(byte bb)
Fill the entire buffer with the specified byte value. |
byte[] |
getBytes()
Get a reference to the data buffer containing the data. |
int |
getLength()
Get the length of the data. |
int |
index(DataBuffer searchbuf)
Find the index of the specified buffer. |
int |
index(int start,
DataBuffer searchbuf,
int offset,
int len)
Find the index of the specified buffer. |
int |
indexOf(byte[] searchbuf)
Find the index of the specified buffer. |
int |
indexOf(char ch)
Find the index of the first instance of the specified character. |
int |
indexOf(int start,
byte[] searchbuf,
int offset,
int len)
Find the index of the specified buffer. |
int |
indexOf(int start,
char ch)
Find the index of the first instance of the specified character. |
int |
indexOf(int start,
String str)
Find the index of the specified buffer. |
int |
indexOf(int start,
String str,
int offset,
int len)
Find the index of the specified buffer. |
int |
indexOf(String str)
Find the index of the specified buffer. |
void |
insert(int pos,
byte[] insertbuf)
Insert the entire buffer insertbuf at the specified position. |
void |
insert(int pos,
byte[] insertbuf,
int off,
int len)
Insert the specified buffer at the specified position. |
void |
insert(int pos,
DataBuffer buf)
Insert the entire DataBuffer buf at the specified position. |
void |
insert(int pos,
DataBuffer buf,
int off,
int len)
Insert the specified buffer at the specified position. |
void |
insert(int pos,
int len)
Insert len number of spaces (with value 0) at position pos. |
void |
insert(int pos,
String str)
Insert the specified String at the specified position. |
void |
readFromFile(String strFileName)
Restore the buffer with data from the specified file. |
void |
remove(int pos,
int len)
Remove len number of bytes at position pos. |
void |
replace(String[] strFindArray,
String strReplace)
Find any String in strFindArray and replace it with strReplace. |
void |
replace(String strFind,
String strReplace)
Find all instances of a String, and replace these instances with another String. |
void |
resize(int size)
Resize the data buffer size. |
void |
setBytes(byte[] buf,
int len)
Set the bytes contained in this DataBuffer. |
void |
setLength(int len)
Set the length of the data. |
String |
toString()
Convert the data to a String printable format. |
void |
writeToFile(String strFileName)
Save the buffer as a file, overwriting the file if necessary. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public DataBuffer()
public DataBuffer(int len)
len
- is the length of the DataBuffer to create.public DataBuffer(byte[] buf)
buf
- is the array to use in this DataBuffer.public DataBuffer(byte[] buf, int len)
buf
- is the array to use in this DataBuffer.len
- is the length of the bytes to use from the buffer.
Ensure that len is less than or equal to buf.length.public DataBuffer(String str)
str
- is the String to copy into the DataBuffer.Method Detail |
public void writeToFile(String strFileName) throws IOException
strFileName
- is the name of the file to save the buffer to.IOException
- on an I/O error, most likely a file write error.public void appendToFile(String strFileName) throws IOException
strFileName
- is the name of the file to append to.IOException
- on an I/O error, most likely a file write error.public void readFromFile(String strFileName) throws IOException, FileNotFoundException
strFileName
- is the file to read from.IOException
- on an I/O error, most likely either file does not
exist or there is a file read error.public byte[] getBytes()
public int getLength()
public int indexOf(String str)
str
- is the String to search for.public int indexOf(int start, String str)
str
- is the String to search for.start
- is the start position in this databuffer to search from.public int indexOf(int start, String str, int offset, int len)
start
- is the start position in this databuffer to search from.str
- is the String to search for.offset
- is where in searchbuf to start searching from.len
- is the number of bytes to search through in searchbuf.public int index(DataBuffer searchbuf)
searchbuf
- is the bytes to search for.public int index(int start, DataBuffer searchbuf, int offset, int len)
start
- is the start position in this databuffer to search from.searchbuf
- is the bytes to search for.offset
- is where in searchbuf to start searching from.len
- is the number of bytes to search through in searchbuf.public int indexOf(byte[] searchbuf)
searchbuf
- is the bytes to search for.public int indexOf(int start, byte[] searchbuf, int offset, int len)
start
- is the start position in this databuffer to search from.searchbuf
- is the bytes to search for.offset
- is where in searchbuf to start searching from.len
- is the number of bytes to search through in searchbuf.public int indexOf(int start, char ch)
start
- is the start position in this databuffer to search from.ch
- is the char to search for.public int indexOf(char ch)
ch
- is the char to search for.public final byte at(int index)
index
- is the location to retrieve.public void replace(String[] strFindArray, String strReplace)
public void replace(String strFind, String strReplace)
strFind
- is the String to find.strReplace
- is the String to replace strFind with.public void clear()
public void fill()
public void fill(byte bb)
bb
- is the byte to put in the buffer.public void resize(int size)
size
- is the new size to change the buffer to. If it is smaller
than the current length of the data, then it will default to the
current length of the data.public void compact()
public void append(byte[] insertbuf)
insertbuf
- is the buffer to insert.public void append(byte[] insertbuf, int off, int len)
insertbuf
- is the buffer to insert.off
- is the offset in insertbuf to copy from.len
- is the amount to insert from insertbuf.public void append(DataBuffer buf)
buf
- is the DataBuffer to append.public void append(byte bb)
bb
- is the byte to append.public void insert(int pos, int len)
pos
- is the position to insert spaces at.len
- is the number of spaces to insert.public void insert(int pos, byte[] insertbuf, int off, int len)
pos
- is the position to start inserting at.insertbuf
- is the buffer to insert.off
- is the offset in insertbuf to copy from.len
- is the amount to insert from insertbuf.public void insert(int pos, String str)
pos
- is the position to start inserting at.str
- is the String to insert.public void insert(int pos, byte[] insertbuf)
pos
- is the position to start inserting at.insertbuf
- is the buffer to insert.public void insert(int pos, DataBuffer buf)
pos
- is the position to start inserting at.insertbuf
- is the buffer to insert.public void insert(int pos, DataBuffer buf, int off, int len)
pos
- is the position to start inserting at.buf
- is the DataBuffer to insert.off
- is the offset in insertbuf to copy from.len
- is the amount to insert from insertbuf.public void remove(int pos, int len)
pos
- is the position to start removing from (starting with 0,
inclusive).len
- is the length of data to remove.public void setBytes(byte[] buf, int len)
buf
- is the data buffer.len
- is the length of the data. Must be a nonnegative value.public void copyBytes(byte[] buf, int len)
buf
- is the data buffer.len
- is the length of the data. Must be a nonnegative value.public void setLength(int len)
len
- is the length of the data. Must be a nonnegative value.public String toString()
toString
in class Object
|
Copyright Information | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |