Package totalcross.io
Class Stream
- java.lang.Object
-
- totalcross.io.Stream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
BufferedStream,CompressedByteArrayStream,CompressedStream,CRC32Stream,DataStream,HttpStream,Launcher.IS2S,PDBFile,PDBStream,PortConnector,RandomAccessStream,ResizeRecord,SerialPortClient,Socket
public abstract class Stream extends java.lang.ObjectStream is the base class for all stream-based I/O classes.
-
-
Field Summary
Fields Modifier and Type Field Description protected static byte[]skipBuffer
-
Constructor Summary
Constructors Constructor Description Stream()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.io.InputStreamasInputStream()java.io.OutputStreamasOutputStream()static StreamasStream(java.io.InputStream inputStream)static StreamasStream(java.io.OutputStream outputStream)abstract voidclose()Closes this I/O connection, releasing any associated resources.abstract intreadBytes(byte[] buf, int start, int count)Reads bytes from the stream.intskipBytes(int n)Skips over and discards n bytes of data from this stream.java.io.InputStreamwrapInputStream()Deprecated.useasInputStream()insteadstatic StreamwrapInputStreamToStream(java.io.InputStream inputStream)Deprecated.useasStream(InputStream)insteadintwrite(int b)Writes a single byte to the stream.intwriteBytes(byte[] buf)Writes bytes to the stream.abstract intwriteBytes(byte[] buf, int start, int count)Writes bytes to the stream.intwriteBytes(java.lang.String string)Writes the string to the stream as a byte array.intwriteBytes(java.lang.StringBuffer sb)Writes the given StringBuffer as a byte array, retrieved using Convert.getBytes.
The String is written as-is, nothing is placed before or after it.
-
-
-
Method Detail
-
readBytes
public abstract int readBytes(byte[] buf, int start, int count) throws IOExceptionReads 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)- 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 abstract int writeBytes(byte[] buf, int start, int count) throws IOExceptionWrites bytes to the stream. Returns the number of bytes actually written or throws anIOExceptionif an error prevented the write operation from occurring.- 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
-
writeBytes
public int writeBytes(byte[] buf) throws IOExceptionWrites bytes to the stream. Returns the number of bytes actually written or throws anIOExceptionif an error prevented the write operation from occurring.- Parameters:
buf- the byte array to write data from- Returns:
- the number of bytes actually written
- Throws:
IOException
-
writeBytes
public int writeBytes(java.lang.String string) throws IOExceptionWrites the string to the stream as a byte array. Returns the number of bytes actually written or throws anIOExceptionif an error prevented the write operation from occurring.
The String is written as-is, nothing is placed before or after it.- Parameters:
string- the string whose bytes will be written- Returns:
- the number of bytes actually written
- Throws:
IOException
-
writeBytes
public final int writeBytes(java.lang.StringBuffer sb) throws IOExceptionWrites the given StringBuffer as a byte array, retrieved using Convert.getBytes.
The String is written as-is, nothing is placed before or after it.- Parameters:
sb- the StringBuffer to get the bytes from- Returns:
- the number of bytes actually written
- Throws:
IOException- Since:
- TotalCross 1.23
-
write
public int write(int b) throws IOExceptionWrites a single byte to the stream.- Parameters:
b- the byte to write (only least significant byte is written)- Returns:
- the number of bytes actually written
- Throws:
IOException- Since:
- TotalCross 4.1.1
-
skipBytes
public int skipBytes(int n) throws IOExceptionSkips over and discards n bytes of data from this stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. The actual number of bytes skipped is returned. If n is negative, no bytes are skipped, but this may vary among some implementations of skipBytes in classes that inherit them (like File and PDBFile).
The skip method of this class uses a static byte array, repeatedly reading into it until n bytes have been read or the end of the stream has been reached. Subclasses are encouraged to provide a more efficient implementation of this method. For instance, the implementation may depend on the ability to seek.- Parameters:
n- the number of bytes to be skipped.- Returns:
- the actual number of bytes skipped.
- Throws:
IOException- if the stream does not support skip, or if some other I/O error occurs.
-
wrapInputStream
@Deprecated public java.io.InputStream wrapInputStream()
Deprecated.useasInputStream()instead
-
asInputStream
public java.io.InputStream asInputStream()
-
asOutputStream
public java.io.OutputStream asOutputStream()
-
wrapInputStreamToStream
@Deprecated public static Stream wrapInputStreamToStream(java.io.InputStream inputStream)
Deprecated.useasStream(InputStream)instead
-
asStream
public static Stream asStream(java.io.InputStream inputStream)
-
asStream
public static Stream asStream(java.io.OutputStream outputStream)
-
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.
-
-