Package com.sshtools.j2ssh.io
Class DynamicBuffer
java.lang.Object
com.sshtools.j2ssh.io.DynamicBuffer
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.
*- Version:
- $Revision: 1.20 $
- Author:
- Lee David Painter
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]The bufferprotected static final intBuffer size when the dynamic buffer is openedprotected InputStreamThis buffers InputStreamprotected OutputStreamThis buffers OutputStreamprotected intThe current read positionprotected intThe current write position -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intReturn the number of bytes of data available to be read from the buffervoidclose()Closes the bufferprotected voidflush()Flush dataGet the InputStream of this buffer.Get the OutputStream of the buffer.protected intread()Read a byte from the bufferprotected intread(byte[] data, int offset, int len) Read a byte array from the buffervoidsetBlockInterrupt(int interrupt) protected voidwrite(byte[] data, int offset, int len) protected voidwrite(int b) Write a byte array to the buffer
-
Field Details
-
DEFAULT_BUFFER_SIZE
protected static final int DEFAULT_BUFFER_SIZEBuffer size when the dynamic buffer is opened- See Also:
-
buf
protected byte[] bufThe buffer -
writepos
protected int writeposThe current write position -
readpos
protected int readposThe current read position -
in
This buffers InputStream -
out
This buffers OutputStream
-
-
Constructor Details
-
DynamicBuffer
public DynamicBuffer()Creates a new DynamicBuffer object.
-
-
Method Details
-
getInputStream
Get the InputStream of this buffer. Use the stream to read data from this buffer.- Returns:
-
getOutputStream
Get the OutputStream of the buffer. Use this stream to write data to the buffer.- Returns:
-
available
protected int available()Return the number of bytes of data available to be read from the buffer- Returns:
-
close
public void close()Closes the buffer -
write
Write a byte array to the buffer- Parameters:
b-- Throws:
IOException
-
write
- Parameters:
data-offset-len-- Throws:
IOException
-
setBlockInterrupt
public void setBlockInterrupt(int interrupt) -
read
Read a byte from the buffer- Returns:
- Throws:
IOExceptionInterruptedIOException
-
read
Read a byte array from the buffer- Parameters:
data-offset-len-- Returns:
- Throws:
IOExceptionInterruptedIOException
-
flush
Flush data- Throws:
IOException
-