waba.io
Class ByteArrayStream

java.lang.Object
  |
  +--waba.io.Stream
        |
        +--waba.io.ByteArrayStream

public class ByteArrayStream
extends Stream

creates a byte array stream. it can be useful with the method Catalog.inspectRecord, since that method returns a byte array. When writing, the buffer expands itself if needed. This class cannot be used for output AND input, but only for output OR input.


Constructor Summary
ByteArrayStream(byte[] buffer)
          sets the internal buffer to be the specified buffer param.
ByteArrayStream(int size)
          creates a new buffer with the specific size.
 
Method Summary
 int available()
          Returns the number of bytes available from the actual read position
 boolean close()
          does nothing.
 int count()
          returns the current position in the buffer.
 byte[] getBuffer()
          gets the buffer used. the size of the buffer may be different of the array length. get its size in count().
 byte[] getCopy()
          Returns a copy of the data inside this buffer.
 boolean isOpen()
          Returns true if buffer is not null
 void mark()
          Sets the current position as the maximum size of the buffer so that no more than the current written data will be read.
 int readBytes(byte[] buf, int start, int count)
          transfers count bytes from class buffer to buf.
 void reset()
          resets the position to 0 so the buffer can be reused, and sets the mark to the buffer real limits.
 int reuse()
          Reuses the already read part of the buffer.
 void setSize(int newSize, boolean copyOldData)
          Sets the size of the current byte array.
 int skipBytes(int count)
          Skips the number of bytes from the current position.
 int writeBytes(byte[] buf, int start, int count)
          this writes to the byte array, expanding it if necessary. returns the number of bytes written.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteArrayStream

public ByteArrayStream(byte[] buffer)
sets the internal buffer to be the specified buffer param.

ByteArrayStream

public ByteArrayStream(int size)
creates a new buffer with the specific size. CANNOT BE 0!
Method Detail

mark

public void mark()
Sets the current position as the maximum size of the buffer so that no more than the current written data will be read. This already resets the read position to zero.

available

public int available()
Returns the number of bytes available from the actual read position
Since:
SuperWaba 4.02

close

public boolean close()
does nothing.
Overrides:
close in class Stream

getBuffer

public byte[] getBuffer()
gets the buffer used. the size of the buffer may be different of the array length. get its size in count().

count

public int count()
returns the current position in the buffer.

readBytes

public int readBytes(byte[] buf,
                     int start,
                     int count)
transfers count bytes from class buffer to buf.
Overrides:
readBytes in class Stream
Returns:
the number of bytes read.

reset

public void reset()
resets the position to 0 so the buffer can be reused, and sets the mark to the buffer real limits.

skipBytes

public int skipBytes(int count)
Skips the number of bytes from the current position. It may be < than 0.
Returns:
The number of bytes skipped, or -1 if error.
Since:
SuperWaba 4.01

reuse

public int reuse()
Reuses the already read part of the buffer. This method shifts the buffer from the current position to 0, so you can reuse the buffer, avoiding exceed the memory limits.
Returns:
The number of bytes shifted
Since:
SuperWaba 4.01

writeBytes

public int writeBytes(byte[] buf,
                      int start,
                      int count)
this writes to the byte array, expanding it if necessary. returns the number of bytes written.
Overrides:
writeBytes in class Stream
Since:
SuperWaba2_0beta2

isOpen

public boolean isOpen()
Returns true if buffer is not null
Overrides:
isOpen in class Stream

setSize

public void setSize(int newSize,
                    boolean copyOldData)
Sets the size of the current byte array. If the current size is smaller then the given one, a new byte array is created with the given size. If there's already enough room for the given size, nothing is made. Note that this method does not reset the current position. If copyOldData is true, the old data up to pos is copied into the new buffer.
Since:
SuperWaba 5.1

getCopy

public byte[] getCopy()
Returns a copy of the data inside this buffer. The returned buffer will have the exact size of the stored data
Since:
SuperWaba 5.1