public class BufferedStream extends Stream
public void writeLargeFile(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(); }
Modifier and Type | Field and Description |
---|---|
static int |
READ
Used for opening this buffered stream for reading.
|
static int |
WRITE
Used for opening this buffered stream for writing.
|
skipBuffer
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
This method closes this stream, flushing any pending WRITE data.
|
Stream |
getStream()
Returns the Stream attached to this BufferedStream.
|
int |
readBytes(byte[] buf,
int start,
int count)
Reads bytes from the stream.
|
java.lang.String |
readLine()
Reads a line of text from this BufferedStream.
|
void |
setStream(Stream f)
Changes the initial Stream to the attached one.
|
int |
writeBytes(byte[] buf,
int start,
int count)
Writes bytes to the stream.
|
asInputStream, asOutputStream, asStream, asStream, skipBytes, wrapInputStream, wrapInputStreamToStream, write, writeBytes, writeBytes, writeBytes
public static final int READ
public static final int WRITE
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, java.lang.NullPointerException
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.java.lang.NullPointerException
- if stream is null.public final int readBytes(byte[] buf, int start, int count) throws IllegalArgumentIOException, IOException, java.lang.NullPointerException
Stream
readBytes
in class Stream
buf
- the byte array to read data intostart
- the start position in the arraycount
- the number of bytes to readIOException
IllegalArgumentIOException
java.lang.NullPointerException
public final int writeBytes(byte[] buf, int start, int count) throws IllegalArgumentIOException, IOException, java.lang.NullPointerException
Stream
IOException
if an error prevented the write
operation from occurring.writeBytes
in class Stream
buf
- the byte array to write data fromstart
- the start position in the byte arraycount
- the number of bytes to writeIOException
IllegalArgumentIOException
java.lang.NullPointerException
public final void close() throws IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
IOException
- If an I/O error occurs.public void setStream(Stream f) throws IOException, java.lang.NullPointerException
IOException
java.lang.NullPointerException
public Stream getStream()
public java.lang.String readLine() throws IOException
null
if nothing was read.IOException
LineReader