public class DynamicBuffer
extends java.lang.Object
This class provides an alternative method of storing data, used within the API where Piped Streams could have been used. We found that Piped streams would lock if a thread attempted to read to data when the OutputStream attached was not being read; since we have no control over when the user will actually read the data, this behaviour led us to develop this dynamic buffer which will automatically grow if the buffer is full.
*| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
buf
The buffer
|
protected static int |
DEFAULT_BUFFER_SIZE
Buffer size when the dynamic buffer is opened
|
protected java.io.InputStream |
in
This buffers InputStream
|
protected java.io.OutputStream |
out
This buffers OutputStream
|
protected int |
readpos
The current read position
|
protected int |
writepos
The current write position
|
| Constructor and Description |
|---|
DynamicBuffer()
Creates a new DynamicBuffer object.
|
DynamicBuffer(int bufferSize) |
| Modifier and Type | Method and Description |
|---|---|
protected int |
available()
Return the number of bytes of data available to be read from the buffer
|
void |
close() |
void |
close(boolean closedWithError)
Closes the buffer
|
protected void |
flush()
Flush data
|
java.io.InputStream |
getInputStream()
Get the InputStream of this buffer.
|
java.io.OutputStream |
getOutputStream()
Get the OutputStream of the buffer.
|
long |
getTimeout() |
protected int |
read()
Read a byte from the buffer
|
protected int |
read(byte[] data,
int offset,
int len)
Read a byte array from the buffer
|
void |
setBlockInterrupt(int interrupt) |
void |
setTimeout(int timeout) |
protected void |
write(byte[] data,
int offset,
int len) |
protected void |
write(int b)
Write a byte array to the buffer
|
protected static final int DEFAULT_BUFFER_SIZE
protected byte[] buf
protected int writepos
protected int readpos
protected java.io.InputStream in
protected java.io.OutputStream out
public DynamicBuffer()
public DynamicBuffer(int bufferSize)
public java.io.InputStream getInputStream()
public java.io.OutputStream getOutputStream()
public long getTimeout()
public void setTimeout(int timeout)
protected int available()
public void close()
public void close(boolean closedWithError)
protected void write(int b)
throws java.io.IOException
b - java.io.IOExceptionprotected void write(byte[] data,
int offset,
int len)
throws java.io.IOException
data - offset - len - java.io.IOExceptionpublic void setBlockInterrupt(int interrupt)
protected int read()
throws java.io.IOException
java.io.IOExceptionjava.io.InterruptedIOExceptionprotected int read(byte[] data,
int offset,
int len)
throws java.io.IOException
data - offset - len - java.io.IOExceptionjava.io.InterruptedIOExceptionprotected void flush()
throws java.io.IOException
java.io.IOExceptionCopyright © 2022. All rights reserved.