|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--gnu.iou.bbuf
Byte buffer with `InputStream'
and
`OutputStream'
emulation APIs for convenience in
software using streams or buffers. Unfortunately we're not able to
implement `InputStream'
and
`OutputStream'
interfaces as both are abstract
classes, not interfaces.
Reading and writing can occur in any order. Writing adds data, reading consumes data. Any constructor can be used with any usage.
The `reset()'
method positions the read pointer to
the beginning of the internal buffer, unless the
`mark(int)'
method has been used.
The `flush()'
method positions the write pointer
to the beginning of the buffer. After writing has occurred,
reading will not proceed beyond the written buffer, unless we're
still reading the input (constructor) buffer.
The `close()'
method does both. And resets read-
marking as well.
This class is not synchronized, as most applications of most classes have only one thread accessing an object and are penalized in runtime performance by utilities that are multithread- safe (synchronized).
Multithreaded applications of this class must provide their own multi- thread safety (synchronization).
bbo
,
bbi
,
dbo
Constructor Summary | |
bbuf()
Output/ write constructor. |
|
bbuf(byte[] input)
Input/ read constructor. |
|
bbuf(java.io.InputStream in)
Copy input into buffer until EOF |
|
bbuf(int gf)
|
Method Summary | |
void |
append(boolean[] ary)
|
void |
append(double[] ary,
bbuf bb)
|
void |
append(float[] ary,
bbuf bb)
|
void |
append(int[] ary)
|
void |
append(long[] ary)
|
void |
append(java.lang.Object o)
|
void |
append(java.lang.Object[] oary)
|
void |
append(short[] ary)
|
int |
available()
Bytes available for reading. |
int |
buf_gf(int gf)
Get or set internal buffer growth factor. |
java.lang.String |
bufString()
Naively construct a string on a non- null buffer, otherwise return null for an empty buffer. |
static byte[] |
cat(byte[] a,
byte[] b)
|
void |
close()
Reset reading, writing and "read mark" to the start. |
int |
copyOutArray(java.io.OutputStream out)
Unsynchronized raw buffer copy to output stream using a loop for block devices, etc.. |
int |
copyOutLoop(java.io.OutputStream out)
Unsynchronized raw buffer copy to output stream using a loop for TCP based destinations. |
static void |
debugPrint(byte[] buf,
int ofs,
int len,
java.io.PrintStream out)
|
void |
destroy()
Discard the internal buffer. |
byte[] |
dump()
Return a copy of the internal buffer, verbatim. |
void |
flush()
Reset reading, writing and "read mark" to the head of the current buffer. |
static byte[] |
growbuf(byte[] src,
int to_idx)
Array stretch function. |
int |
length()
Same as `available()'. |
void |
mark()
Sets "reset" (writing) mark to current position. |
void |
mark(int readlimit)
Sets "reset" (writing) mark to the current position, ignoring "readlimit" because this is a buffer -- we don't need a buffer size. |
byte[] |
markedBits()
Return bytes written since last "mark". |
boolean |
markSupported()
|
int |
nwrite(byte ch,
int many)
Repeat the byte into the buffer. |
void |
print(java.lang.String s)
Encode string in UTF-8 and append to buffer. |
void |
println()
Write CRLF newline to buffer. |
void |
println(java.lang.Object obj)
Encode to string (UTF-8) with CRLF newline. |
void |
println(java.lang.Object[] objs)
Add CRLF after each. |
void |
println(java.lang.String s)
Encode string with CRLF newline in UTF-8 and append to buffer. |
int |
read()
|
int |
read(byte[] b)
|
int |
read(byte[] b,
int off,
int len)
Copy into buffer as many as buffer- length bytes, or available bytes. |
short |
read2()
Read two bytes into a short. |
int |
read4()
Read four bytes into an int using network byte order (big endian). |
long |
read8()
Read eight bytes into a long using network byte order (big endian). |
void |
reset()
Reset writing back to first byte of the current buffer, or to the last marked position. |
long |
skip(long n)
Skip bytes, or available bytes. |
byte[] |
toByteArray()
Copy readable (available) bytes from buffer. |
static byte[] |
toByteArray(java.lang.Object obj)
|
static byte[] |
toByteArray(java.lang.Object[] oary)
|
static bbuf |
toByteArray(java.lang.Object[] objs,
bbuf bbu)
|
static bbuf |
toByteArray(java.lang.Object obj,
bbuf bbu)
|
java.lang.String |
toString()
Pass the available bits through UTF-8 |
int |
write(byte[] b)
|
int |
write(byte[] b,
int off,
int len)
|
void |
write(int b)
|
void |
write2(short b)
Write 16 bits in big endian network byte order. |
void |
write4(int b)
Write 32 bits in big endian network byte order. |
void |
write8(long b)
Write 64 bits in big endian network byte order. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public bbuf(byte[] input)
input
- Read- available data (not an empty buffer!)public bbuf(java.io.InputStream in) throws java.io.IOException
public bbuf()
public bbuf(int gf)
gf
- Internal buffer growth factor, set initial buffer
size to gf.Method Detail |
public final int buf_gf(int gf)
gf
- If greater than zero, set, otherwise just return
current value.public int read()
public int read(byte[] b)
public int read(byte[] b, int off, int len)
b
- Non null buffer to copy into.off
- Valid offset in buffer `b' to copy to.len
- Valid number of bytes to copy into `b', usually
`b.length'.public short read2() throws java.io.IOException
java.io.IOException
- If two bytes are not available.public int read4() throws java.io.IOException
java.io.IOException
- If four bytes are not available.public long read8() throws java.io.IOException
java.io.IOException
- If eight bytes are not available.public long skip(long n)
n
- Number of bytes to skip.public int available()
public void reset()
public void mark(int readlimit)
The readlimit argument is ignored because this
is a buffer
public boolean markSupported()
public void mark()
public byte[] markedBits()
public void write2(short b)
b
- 16 bitspublic void write4(int b)
b
- 32 bitspublic void write8(long b)
b
- 64 bitspublic void write(int b)
b
- Eight bit byte valuepublic int write(byte[] b)
b
- Non null buffer to copy into the internal buffer.public int write(byte[] b, int off, int len)
b
- Non null input buffer to copy into the internal buffer.off
- Offset in input buffer `b' from which to copylen
- Number of bytes to copy from input buffer `b'.public int nwrite(byte ch, int many)
public void print(java.lang.String s)
public void println(java.lang.String s)
public void println()
public void println(java.lang.Object obj)
public void println(java.lang.Object[] objs)
public void append(boolean[] ary)
public void append(short[] ary)
public void append(int[] ary)
public void append(long[] ary)
public void append(float[] ary, bbuf bb)
public void append(double[] ary, bbuf bb)
public void append(java.lang.Object[] oary)
public void append(java.lang.Object o)
public void flush()
public void close()
public final java.lang.String bufString()
`toByteArray()'.
toByteArray()
public final byte[] toByteArray()
public final byte[] dump()
public final void destroy()
public int length()
public int copyOutLoop(java.io.OutputStream out) throws java.io.IOException
Copies from present read point without changing the read or write points.
public int copyOutArray(java.io.OutputStream out) throws java.io.IOException
Copies from present read point without changing the read or write points.
public java.lang.String toString()
toString
in class java.lang.Object
public static final byte[] growbuf(byte[] src, int to_idx)
src
- Array, null or extant.to_idx
- Index that must be accomodated in the extent of
the source array.public static final byte[] toByteArray(java.lang.Object[] oary)
public static final byte[] toByteArray(java.lang.Object obj)
public static final bbuf toByteArray(java.lang.Object obj, bbuf bbu)
public static final bbuf toByteArray(java.lang.Object[] objs, bbuf bbu)
public static final byte[] cat(byte[] a, byte[] b)
public static final void debugPrint(byte[] buf, int ofs, int len, java.io.PrintStream out)
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |