Package com.sshtools.j2ssh.io
Class DynamicBuffer
- java.lang.Object
-
- com.sshtools.j2ssh.io.DynamicBuffer
-
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.
*- Version:
- $Revision: 1.20 $
- Author:
- Lee David Painter
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]
buf
The bufferprotected static int
DEFAULT_BUFFER_SIZE
Buffer size when the dynamic buffer is openedprotected java.io.InputStream
in
This buffers InputStreamprotected java.io.OutputStream
out
This buffers OutputStreamprotected int
readpos
The current read positionprotected int
writepos
The current write position
-
Constructor Summary
Constructors Constructor Description DynamicBuffer()
Creates a new DynamicBuffer object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
available()
Return the number of bytes of data available to be read from the buffervoid
close()
Closes the bufferprotected void
flush()
Flush datajava.io.InputStream
getInputStream()
Get the InputStream of this buffer.java.io.OutputStream
getOutputStream()
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 Detail
-
DEFAULT_BUFFER_SIZE
protected static final int DEFAULT_BUFFER_SIZE
Buffer size when the dynamic buffer is opened- See Also:
- Constant Field Values
-
buf
protected byte[] buf
The buffer
-
writepos
protected int writepos
The current write position
-
readpos
protected int readpos
The current read position
-
in
protected java.io.InputStream in
This buffers InputStream
-
out
protected java.io.OutputStream out
This buffers OutputStream
-
-
Method Detail
-
getInputStream
public java.io.InputStream getInputStream()
Get the InputStream of this buffer. Use the stream to read data from this buffer.- Returns:
-
getOutputStream
public java.io.OutputStream 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
protected void write(int b) throws java.io.IOException
Write a byte array to the buffer- Parameters:
b
-- Throws:
java.io.IOException
-
write
protected void write(byte[] data, int offset, int len) throws java.io.IOException
- Parameters:
data
-offset
-len
-- Throws:
java.io.IOException
-
setBlockInterrupt
public void setBlockInterrupt(int interrupt)
-
read
protected int read() throws java.io.IOException
Read a byte from the buffer- Returns:
- Throws:
java.io.IOException
java.io.InterruptedIOException
-
read
protected int read(byte[] data, int offset, int len) throws java.io.IOException
Read a byte array from the buffer- Parameters:
data
-offset
-len
-- Returns:
- Throws:
java.io.IOException
java.io.InterruptedIOException
-
flush
protected void flush() throws java.io.IOException
Flush data- Throws:
java.io.IOException
-
-