Package totalcross.io
Class ResizeRecord
- java.lang.Object
-
- totalcross.io.Stream
-
- totalcross.io.ResizeRecord
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class ResizeRecord extends Stream
This class is used to handle record sizes of a PDBFile. It is used in most cases with a DataStream. For example:PDBFile pdb = new PDBFile("Name.Crtr.Type",PDBFile.CREATE); ResizeRecord rs = new ResizeRecord(pdb,512); DataStream ds = new DataStream(rs); rs.startRecord(); ds.writeStringArray(aStringArray); rs.endRecord();PS: if you dont call startRecord, writeBytes will simply call PDBFile.writeBytes and will not resize the record!- Since:
- SuperWaba 5.8
-
-
Field Summary
-
Fields inherited from class totalcross.io.Stream
skipBuffer
-
-
Constructor Summary
Constructors Constructor Description ResizeRecord(PDBFile cat, int initialSize)Constructs the resize stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()closes the PDBFilevoidendRecord()Must be called after the record is finished so it can be properly resized.protected voidfinalize()StreamgetStream()Returns the stream attached to this stream (which is always a PDBFile).intreadBytes(byte[] buf, int start, int count)Reads bytes from the stream.booleanrestartRecord(int pos)Restart writing to the given record pos, overwritting the current record.voidstartRecord()Appends a new record to the PDBFile.voidstartRecord(int pos)Inserts the record at the specified index in the PDBFile.intwriteBytes(byte[] buf, int start, int count)Writes bytes to the stream.-
Methods inherited from class totalcross.io.Stream
asInputStream, asOutputStream, asStream, asStream, skipBytes, wrapInputStream, wrapInputStreamToStream, write, writeBytes, writeBytes, writeBytes
-
-
-
-
Constructor Detail
-
ResizeRecord
public ResizeRecord(PDBFile cat, int initialSize)
Constructs the resize stream.- Parameters:
cat- The PDBFile associatedinitialSize- The initial size of the record. CANNOT BE 0!
-
-
Method Detail
-
startRecord
public void startRecord(int pos) throws IOExceptionInserts the record at the specified index in the PDBFile.- Parameters:
pos- The position where to insert the record. If greater or equal to the record count, the record is appended.- Throws:
IOException- Since:
- SuperWaba 1.21. *
- See Also:
startRecord(),restartRecord(int),endRecord()
-
startRecord
public void startRecord() throws IOExceptionAppends a new record to the PDBFile.- Throws:
IOException- See Also:
restartRecord(int),startRecord(int),endRecord()
-
restartRecord
public boolean restartRecord(int pos) throws IOExceptionRestart writing to the given record pos, overwritting the current record.- Parameters:
pos- The position to overwrite. If pos is lower than 0 or greater than the number of records of the PDBFile, the record is appended.- Throws:
IOException- See Also:
startRecord(),startRecord(int),endRecord()
-
endRecord
public void endRecord() throws IOExceptionMust be called after the record is finished so it can be properly resized.- Throws:
IOException- See Also:
startRecord(),restartRecord(int),startRecord(int)
-
readBytes
public int readBytes(byte[] buf, int start, int count) throws IOExceptionDescription copied from class:StreamReads bytes from the stream. Returns the number of bytes actually read or -1 if the end of the stream was reached. (if applicable to the stream)- Specified by:
readBytesin classStream- Parameters:
buf- the byte array to read data intostart- the start position in the arraycount- the number of bytes to read- Throws:
IOException
-
writeBytes
public int writeBytes(byte[] buf, int start, int count) throws IOExceptionDescription copied from class:StreamWrites bytes to the stream. Returns the number of bytes actually written or throws anIOExceptionif an error prevented the write operation from occurring.- Specified by:
writeBytesin classStream- Parameters:
buf- the byte array to write data fromstart- the start position in the byte arraycount- the number of bytes to write- Returns:
- the number of bytes actually written
- Throws:
IOException
-
close
public void close() throws IOExceptioncloses the PDBFile- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
IOException
-
getStream
public Stream getStream()
Returns the stream attached to this stream (which is always a PDBFile).
-
finalize
protected void finalize()
- Overrides:
finalizein classjava.lang.Object
-
-