it.unimi.dsi.fastutil.io
Class FastBufferedOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended byit.unimi.dsi.fastutil.io.FastBufferedOutputStream

public class FastBufferedOutputStream
extends OutputStream

Lightweight, unsynchronised, aligned output stream buffering class.

This class provides buffering for output streams, but it does so with purposes and an internal logic that are radically different from the ones adopted in BufferedOutputStream.

All methods are unsychronised. Moreover, it is guaranteed that all writes performed by this class will be multiples of the given buffer size. If, for instance, you use the default buffer size, writes will be performed on the underlying input stream in multiples of 16384 bytes. This is very important on operating systems that optimise disk reads on disk block boundaries. If you flush() the stream, the buffer will be emptied, but it will realign again as soon as possible.

Since:
4.4

Field Summary
static int DEFAULT_BUFFER_SIZE
          The default size of the internal buffer in bytes (8Ki).
 
Constructor Summary
FastBufferedOutputStream(OutputStream os)
          Creates a new fast buffered ouptut stream by wrapping a given output stream with a buffer of DEFAULT_BUFFER_SIZE bytes.
FastBufferedOutputStream(OutputStream os, int bufSize)
          Creates a new fast buffered output stream by wrapping a given output stream with a given buffer size.
 
Method Summary
 void close()
           
 void flush()
           
 void write(byte[] b, int offset, int length)
           
 void write(int b)
           
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
The default size of the internal buffer in bytes (8Ki).

See Also:
Constant Field Values
Constructor Detail

FastBufferedOutputStream

public FastBufferedOutputStream(OutputStream os,
                                int bufSize)
Creates a new fast buffered output stream by wrapping a given output stream with a given buffer size.

Parameters:
os - an output stream to wrap.
bufSize - the size in bytes of the internal buffer.

FastBufferedOutputStream

public FastBufferedOutputStream(OutputStream os)
Creates a new fast buffered ouptut stream by wrapping a given output stream with a buffer of DEFAULT_BUFFER_SIZE bytes.

Parameters:
os - an output stream to wrap.
Method Detail

write

public void write(int b)
           throws IOException
Throws:
IOException

write

public void write(byte[] b,
                  int offset,
                  int length)
           throws IOException
Throws:
IOException

flush

public void flush()
           throws IOException
Throws:
IOException

close

public void close()
           throws IOException
Throws:
IOException