Package totalcross.io

Class RandomAccessStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    ByteArrayStream, File

    public abstract class RandomAccessStream
    extends Stream
    Represents a stream that behaves like a large array of bytes and may be randomly accessed.
    Since:
    TotalCross 1.01
    • Field Detail

      • pos

        protected int pos
        The index of the next position to read or write in the stream
      • SEEK_CUR

        public static final int SEEK_CUR
        Current position of the file pointer
        See Also:
        Constant Field Values
    • Constructor Detail

      • RandomAccessStream

        public RandomAccessStream()
    • Method Detail

      • getPos

        public int getPos()
                   throws IOException
        Returns the current offset in this stream.
        Returns:
        the offset from the beginning of the stream, in bytes, at which the next read or write occurs.
        Throws:
        IOException - if an I/O error has occurred.
        Since:
        TotalCross 1.2
      • setPos

        public abstract void setPos​(int offset,
                                    int origin)
                             throws IOException
        Sets the file pointer for read and write operations to a new position defined by adding offset to a reference position specified by origin.
        Parameters:
        offset - number of bytes to offset from origin.
        origin - position from where offset is added. It is specified by one of the SEEK_* constants.
        Throws:
        java.lang.IllegalArgumentException - if origin is not one of the values specified by the SEEK_* constants.
        IOException - if the new position is negative or if an I/O error occurs.
        Since:
        TotalCross 1.2
      • setPos

        public abstract void setPos​(int pos)
                             throws IOException
        Sets the file pointer for read and write operations to the given position. The position passed is an absolute position, in bytes, from the beginning of the stream.
        Parameters:
        pos - the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.
        Throws:
        IOException - if pos is negative or if an I/O error occurs.
      • close

        public abstract void close()
                            throws IOException
        Closes this I/O connection, releasing any associated resources. Once closed a connection is no longer valid.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        IOException - If an I/O error occurs.