waba.io
Class ResizeStream

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

public class ResizeStream
extends Stream

this class is used to create an resizable record. you can use it with DataStream. example:

Catalog cat = new Catalog(type+"."+creator+"."+type,Catalog.READ_WRITE);
ResizeStream rs = new ResizeStream(cat,512);
DataStream ds = new DataStream(rs);
rs.startRecord();
ds.writeStringArray(aStringArray);
rs.endRecord();
ds.close();

ps: if you dont call startRecord, writeBytes will simply call catalog.writeBytes and will not resize the record.


Constructor Summary
ResizeStream(Catalog cat, int initialSize)
          constructs the resize stream.
 
Method Summary
 boolean close()
          closes the catalog
 void endRecord()
          must be called after the record is finished so it can be resized
 boolean isOpen()
          Returns true if this Stream is open and false otherwise
 int readBytes(byte[] buf, int start, int count)
          simply read the bytes from the associated catalog
 boolean restartRecord(int pos)
          Restart writing to the given record pos.
 boolean startRecord()
          add a new record to the catalog.
 boolean startRecord(int pos)
          inserts the record at the specified index in the catalog.
 int writeBytes(byte[] buf, int start, int count)
          writes to the buffer, growing the record if necessary.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, toString, wait, wait
 

Constructor Detail

ResizeStream

public ResizeStream(Catalog cat,
                    int initialSize)
constructs the resize stream.
Parameters:
cat - the catalog associated
initialSize - the initial size of the record. CANNOT BE 0!
Method Detail

startRecord

public boolean startRecord(int pos)
inserts the record at the specified index in the catalog.
Returns:
true if operation was successful, false otherwise.
Since:
SuperWaba 1.21.

startRecord

public boolean startRecord()
add a new record to the catalog.
Returns:
true if operation was successful, false otherwise.

restartRecord

public boolean restartRecord(int pos)
Restart writing to the given record pos. If pos is < 0 or greater than the number of records of the Catalog, the record is appended.

endRecord

public void endRecord()
must be called after the record is finished so it can be resized

readBytes

public int readBytes(byte[] buf,
                     int start,
                     int count)
simply read the bytes from the associated catalog
Overrides:
readBytes in class Stream
Tags copied from class: Stream
Parameters:
buf - the byte array to read data into
start - the start position in the array
count - the number of bytes to read

writeBytes

public int writeBytes(byte[] buf,
                      int start,
                      int count)
writes to the buffer, growing the record if necessary.
Overrides:
writeBytes in class Stream
Tags copied from class: Stream
Parameters:
buf - the byte array to write data from
start - the start position in the byte array
count - the number of bytes to write

close

public boolean close()
closes the catalog
Overrides:
close in class Stream

isOpen

public boolean isOpen()
Description copied from class: Stream
Returns true if this Stream is open and false otherwise
Overrides:
isOpen in class Stream