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 int
Buffer size when the dynamic buffer is openedprotected InputStream
This buffers InputStreamprotected OutputStream
This buffers OutputStreamprotected int
The current read positionprotected int
The current write position -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected int
Return the number of bytes of data available to be read from the buffervoid
close()
Closes the bufferprotected void
flush()
Flush dataGet the InputStream of this buffer.Get the OutputStream of the buffer.protected int
read()
Read a byte from the bufferprotected int
read
(byte[] data, int offset, int len) Read a byte array from the buffervoid
setBlockInterrupt
(int interrupt) protected void
write
(byte[] data, int offset, int len) protected void
write
(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:
IOException
InterruptedIOException
-
read
Read a byte array from the buffer- Parameters:
data
-offset
-len
-- Returns:
- Throws:
IOException
InterruptedIOException
-
flush
Flush data- Throws:
IOException
-