Package totalcross.io
Class RandomAccessStream
- java.lang.Object
-
- totalcross.io.Stream
-
- totalcross.io.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 Summary
Fields Modifier and Type Field Description protected intposThe index of the next position to read or write in the streamstatic intSEEK_CURCurrent position of the file pointerstatic intSEEK_ENDEnd of filestatic intSEEK_SETBeginning of file-
Fields inherited from class totalcross.io.Stream
skipBuffer
-
-
Constructor Summary
Constructors Constructor Description RandomAccessStream()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidclose()Closes this I/O connection, releasing any associated resources.intgetPos()Returns the current offset in this stream.abstract voidsetPos(int pos)Sets the file pointer for read and write operations to the given position.abstract voidsetPos(int offset, int origin)Sets the file pointer for read and write operations to a new position defined by adding offset to a reference position specified by origin.-
Methods inherited from class totalcross.io.Stream
asInputStream, asOutputStream, asStream, asStream, readBytes, skipBytes, wrapInputStream, wrapInputStreamToStream, write, writeBytes, writeBytes, writeBytes, writeBytes
-
-
-
-
Field Detail
-
pos
protected int pos
The index of the next position to read or write in the stream
-
SEEK_SET
public static final int SEEK_SET
Beginning of file- See Also:
- Constant Field Values
-
SEEK_CUR
public static final int SEEK_CUR
Current position of the file pointer- See Also:
- Constant Field Values
-
SEEK_END
public static final int SEEK_END
End of file- See Also:
- Constant Field Values
-
-
Method Detail
-
getPos
public int getPos() throws IOExceptionReturns 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 IOExceptionSets 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 IOExceptionSets 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 IOExceptionCloses this I/O connection, releasing any associated resources. Once closed a connection is no longer valid.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
IOException- If an I/O error occurs.
-
-