Package totalcross.io

Class 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
    • Constructor Detail

      • ResizeRecord

        public ResizeRecord​(PDBFile cat,
                            int initialSize)
        Constructs the resize stream.
        Parameters:
        cat - The PDBFile associated
        initialSize - The initial size of the record. CANNOT BE 0!
    • Method Detail

      • startRecord

        public void startRecord​(int pos)
                         throws IOException
        Inserts 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()
      • restartRecord

        public boolean restartRecord​(int pos)
                              throws IOException
        Restart 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()
      • readBytes

        public int readBytes​(byte[] buf,
                             int start,
                             int count)
                      throws IOException
        Description copied from class: Stream
        Reads 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:
        readBytes in 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
        Throws:
        IOException
      • writeBytes

        public int writeBytes​(byte[] buf,
                              int start,
                              int count)
                       throws IOException
        Description copied from class: Stream
        Writes bytes to the stream. Returns the number of bytes actually written or throws an IOException if an error prevented the write operation from occurring.
        Specified by:
        writeBytes in 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
        Returns:
        the number of bytes actually written
        Throws:
        IOException
      • close

        public void close()
                   throws IOException
        closes the PDBFile
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.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:
        finalize in class java.lang.Object