|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
totalcross.lang.Objecttotalcross.io.Stream
totalcross.io.BufferedStream
public class BufferedStream
BufferedStream offers a faster way to read and write data from streams in a buffered manner. This is especially useful when reading or writing large amounts of data. It works like the CompressedByteArrayStream, however it does not compresses the data like that one. Here's a sample code:
public void writeLargeFile(totalcross.lang.String path, byte[] largeData) throws IOException
{
File f = new File(path, File.CREATE_EMPTY);
BufferedStream bs = new BufferedStream(f, BufferedStream.WRITE, 4096);
bs.writeBytes(largeData, 0, largeData.length);
bs.close(); // important!
f.close();
}
| Field Summary | |
|---|---|
static int |
READ
Used for opening this buffered stream for reading. |
static int |
WRITE
Used for opening this buffered stream for writing. |
| Fields inherited from class totalcross.io.Stream |
|---|
skipBuffer |
| Constructor Summary | |
|---|---|
BufferedStream(Stream stream,
int mode)
Creates a new buffered stream given the underlying stream and the mode to use. |
|
BufferedStream(Stream stream,
int mode,
int bufferSize)
Creates a new buffered stream given the underlying stream, the mode to use and the buffer size. |
|
| Method Summary | |
|---|---|
void |
close()
This method closes this stream, flushing any pending WRITE data. |
int |
readBytes(byte[] buf,
int start,
int count)
Reads bytes from the stream. |
int |
writeBytes(byte[] buf,
int start,
int count)
Writes bytes to the stream. |
| Methods inherited from class totalcross.io.Stream |
|---|
skipBytes, writeBytes, writeBytes |
| Methods inherited from class totalcross.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int READ
public static final int WRITE
| Constructor Detail |
|---|
public BufferedStream(Stream stream,
int mode)
throws IllegalArgumentIOException
stream - The underlying stream.mode - The mode to use - READ or WRITE.
IllegalArgumentIOException - if the mode is invalid.
public BufferedStream(Stream stream,
int mode,
int bufferSize)
throws IllegalArgumentIOException
stream - The underlying stream.mode - The mode to use - READ or WRITE.bufferSize - The buffer size.
IllegalArgumentIOException - if the mode is invalid or the bufferSize is not
a positive number.| Method Detail |
|---|
public final int readBytes(byte[] buf,
int start,
int count)
throws IllegalArgumentIOException,
IOException
Stream
readBytes in class Streambuf - the byte array to read data intostart - the start position in the arraycount - the number of bytes to read
IOException
IllegalArgumentIOException
public final int writeBytes(byte[] buf,
int start,
int count)
throws IllegalArgumentIOException,
IOException
Stream
writeBytes in class Streambuf - the byte array to write data fromstart - the start position in the byte arraycount - the number of bytes to write
IOException
IllegalArgumentIOException
public final void close()
throws IOException
IOException - If an I/O error occurs.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||