Terrier IR Platform
2.2.1

uk.ac.gla.terrier.compression
Class MemoryOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by uk.ac.gla.terrier.compression.MemoryOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class MemoryOutputStream
extends java.io.OutputStream

This class extends an ordinary OutputStream to handle transparently writes in memory. This means that this class doesn't flush to disk anything, that should be done separately (@see MSBOStream). It allocates a byte[] array of original size, that can grow and be reallocated dynamically if it is needed. The class used for handling the reallocations is @see ArrayUtils.

Author:
Roi Blanco

Field Summary
static int DEFAULT_BUFFER_SIZE
          The default size of the internal buffer in bytes
 
Constructor Summary
MemoryOutputStream()
          Default constructor.
MemoryOutputStream(int bufferSize)
          Creates a new instance of this class setting the buffer size.
MemoryOutputStream(int bufferSize, int enlargeSize)
          Creates a new instance of this class setting the buffer size and the growing ratio
 
Method Summary
 void close()
          Empty method
 void flush()
          Empty method
 byte[] getBuffer()
           
 int getPos()
           
 java.lang.String toString()
          Writes the sequence of bytes in the byte[] into String format
 void write(byte[] b, int offset, int length)
          Writes a sequence of bytes to the buffer.
 void write(int b)
          Writes a byte into the buffer.
 void writeByte(byte b)
          Writes a byte into the buffer.
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
The default size of the internal buffer in bytes

See Also:
Constant Field Values
Constructor Detail

MemoryOutputStream

public MemoryOutputStream()
Default constructor. Instanciates a buffer of DEFAULT_BUFFER_SIZE size


MemoryOutputStream

public MemoryOutputStream(int bufferSize)
Creates a new instance of this class setting the buffer size.

Parameters:
bufferSize - size of the buffer (in bytes)

MemoryOutputStream

public MemoryOutputStream(int bufferSize,
                          int enlargeSize)
Creates a new instance of this class setting the buffer size and the growing ratio

Parameters:
bufferSize - size of the buffer (in bytes)
enlargeSize - size the buffer is going to grow if needed (argument to ByteArrays)
Method Detail

getPos

public int getPos()
Returns:
the position in the buffer

write

public void write(int b)
           throws java.io.IOException
Writes a byte into the buffer.

Specified by:
write in class java.io.OutputStream
Parameters:
b - int containing the byte to write.
Throws:
java.io.IOException - if an I/O error occurs.

writeByte

public void writeByte(byte b)
               throws java.io.IOException
Writes a byte into the buffer.

Parameters:
b - byte to write.
Throws:
java.io.IOException - if an I/O error occurs.

write

public void write(byte[] b,
                  int offset,
                  int length)
           throws java.io.IOException
Writes a sequence of bytes to the buffer.

Overrides:
write in class java.io.OutputStream
Parameters:
b - byte[] array containing the bytes to write
offset - int offset where the data to write begins
length - int number of elements to write
Throws:
java.io.IOException - if an I/O error occurs

getBuffer

public byte[] getBuffer()
Returns:
the underlying byte[] buffer

flush

public void flush()
           throws java.io.IOException
Empty method

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Empty method

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException

toString

public java.lang.String toString()
Writes the sequence of bytes in the byte[] into String format

Overrides:
toString in class java.lang.Object

Terrier IR Platform
2.2.1

Terrier Information Retrieval Platform 2.2.1. Copyright 2004-2008 University of Glasgow