org.blinkenbyte.io
Class ReadWriteByteArray

java.lang.Object
  extended by org.blinkenbyte.io.ReadWriteByteArray
All Implemented Interfaces:
java.io.Closeable, ReadWriteDevice

public class ReadWriteByteArray
extends java.lang.Object
implements ReadWriteDevice

This class implements a ReadWriteDevice using a ByteArrayBuffer as a backing store.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.blinkenbyte.io.ReadWriteDevice
ReadWriteDevice.RWDInputStream, ReadWriteDevice.RWDOutputStream
 
Field Summary
protected  ByteArrayBuffer bab
           
protected  ByteArrayBuffer.ByteArrayBufferInputStream babInp
           
protected  boolean isClosed
           
 
Constructor Summary
ReadWriteByteArray()
           
ReadWriteByteArray(int initialSize)
          Constructs a new ReadWriteByteArray with an initial size of initialSize bytes.
 
Method Summary
 int available()
          Returns the number of bytes between the current pointer and end-of-stream.
 void clear()
           
 void close()
          Closes the device.
 void flush()
          Flushes the device.
 java.io.InputStream getInputStream()
          Return an InputStream for reading from this device.
 java.io.OutputStream getOutputStream()
          Return an OututStream for writing to this device.
 long getPointer()
          Returns the current pointer for this device.
 long length()
          Returns the total length in bytes of this device.
 void mark(long markLimit)
          Sets the mark with the specified limit.
 boolean markSupported()
          Returns whether mark is supported.
 int read()
          Reads and returns a single byte.
 int read(byte[] b)
          Reads up to b.length bytes from the device into array b.
 int read(byte[] b, int offset, int len)
          Reads up to len bytes from the device into array b at b[offset].
 void reset()
          Resets the pointer to the mark position.
 void seek(long newPointer)
          Seeks the pointer to the specified offset.
 void setLength(int newLength)
           
 long skip(long amtToSkip)
          Advances the pointer by the specified number of bytes
protected  void throwIfClosed()
           
 void write(byte[] b)
          Writes b.length bytes from array b to the device.
 void write(byte[] b, int offset, int len)
          Writes len bytes from array b starting at b[offset] to the device.
 void write(int b)
          Writes a single byte to the device.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bab

protected ByteArrayBuffer bab

babInp

protected ByteArrayBuffer.ByteArrayBufferInputStream babInp

isClosed

protected boolean isClosed
Constructor Detail

ReadWriteByteArray

public ReadWriteByteArray()

ReadWriteByteArray

public ReadWriteByteArray(int initialSize)
Constructs a new ReadWriteByteArray with an initial size of initialSize bytes.

Method Detail

close

public void close()
           throws java.io.IOException
Description copied from interface: ReadWriteDevice
Closes the device.

Specified by:
close in interface java.io.Closeable
Specified by:
close in interface ReadWriteDevice
Throws:
java.io.IOException

throwIfClosed

protected void throwIfClosed()
                      throws java.io.IOException
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Description copied from interface: ReadWriteDevice
Flushes the device.

Specified by:
flush in interface ReadWriteDevice
Throws:
java.io.IOException

available

public int available()
              throws java.io.IOException
Description copied from interface: ReadWriteDevice
Returns the number of bytes between the current pointer and end-of-stream.

Specified by:
available in interface ReadWriteDevice
Throws:
java.io.IOException

length

public long length()
            throws java.io.IOException
Description copied from interface: ReadWriteDevice
Returns the total length in bytes of this device.

Specified by:
length in interface ReadWriteDevice
Throws:
java.io.IOException

setLength

public void setLength(int newLength)
               throws java.io.IOException
Throws:
java.io.IOException

getPointer

public long getPointer()
                throws java.io.IOException
Description copied from interface: ReadWriteDevice
Returns the current pointer for this device.

Specified by:
getPointer in interface ReadWriteDevice
Throws:
java.io.IOException

seek

public void seek(long newPointer)
          throws java.io.IOException
Description copied from interface: ReadWriteDevice
Seeks the pointer to the specified offset.

Specified by:
seek in interface ReadWriteDevice
Throws:
java.io.IOException

skip

public long skip(long amtToSkip)
          throws java.io.IOException
Description copied from interface: ReadWriteDevice
Advances the pointer by the specified number of bytes

Specified by:
skip in interface ReadWriteDevice
Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
Description copied from interface: ReadWriteDevice
Reads and returns a single byte. Returns -1 if end-of-stream.

Specified by:
read in interface ReadWriteDevice
Throws:
java.io.IOException

read

public int read(byte[] b)
         throws java.io.IOException
Description copied from interface: ReadWriteDevice
Reads up to b.length bytes from the device into array b. Returns the number of bytes read, -1 if currently at end-of-stream.

Specified by:
read in interface ReadWriteDevice
Throws:
java.io.IOException

read

public int read(byte[] b,
                int offset,
                int len)
         throws java.io.IOException
Description copied from interface: ReadWriteDevice
Reads up to len bytes from the device into array b at b[offset]. Returns the number of bytes read, -1 if currently at end-of-stream.

Specified by:
read in interface ReadWriteDevice
Throws:
java.io.IOException

write

public void write(int b)
           throws java.io.IOException
Description copied from interface: ReadWriteDevice
Writes a single byte to the device.

Specified by:
write in interface ReadWriteDevice
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Description copied from interface: ReadWriteDevice
Writes b.length bytes from array b to the device.

Specified by:
write in interface ReadWriteDevice
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int offset,
                  int len)
           throws java.io.IOException
Description copied from interface: ReadWriteDevice
Writes len bytes from array b starting at b[offset] to the device.

Specified by:
write in interface ReadWriteDevice
Throws:
java.io.IOException

mark

public void mark(long markLimit)
          throws java.io.IOException
Description copied from interface: ReadWriteDevice
Sets the mark with the specified limit.

Specified by:
mark in interface ReadWriteDevice
Throws:
java.io.IOException

markSupported

public boolean markSupported()
Description copied from interface: ReadWriteDevice
Returns whether mark is supported.

Specified by:
markSupported in interface ReadWriteDevice

reset

public void reset()
           throws java.io.IOException
Description copied from interface: ReadWriteDevice
Resets the pointer to the mark position.

Specified by:
reset in interface ReadWriteDevice
Throws:
java.io.IOException

clear

public void clear()

getInputStream

public java.io.InputStream getInputStream()
Description copied from interface: ReadWriteDevice
Return an InputStream for reading from this device.

Specified by:
getInputStream in interface ReadWriteDevice

getOutputStream

public java.io.OutputStream getOutputStream()
Description copied from interface: ReadWriteDevice
Return an OututStream for writing to this device.

Specified by:
getOutputStream in interface ReadWriteDevice