public class MemoryOutputStream extends OutputStream
Modifier and Type | Field and Description |
---|---|
protected int |
avail
Number of free bytes before having to enlarge
|
protected byte[] |
buffer
The internal buffer.
|
static int |
DEFAULT_BUFFER_SIZE
The default size of the internal buffer in bytes
|
protected int |
enlargeQ
Enlarge size of the array
|
protected int |
pos
The current position in the buffer.
|
Constructor and Description |
---|
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
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Empty method
|
void |
flush()
Empty method
|
byte[] |
getBuffer() |
int |
getPos() |
int |
getSize()
Get size
|
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.
|
write
public static final int DEFAULT_BUFFER_SIZE
protected byte[] buffer
protected int pos
protected int avail
protected final int enlargeQ
public MemoryOutputStream()
public MemoryOutputStream(int bufferSize)
bufferSize
- size of the buffer (in bytes)public MemoryOutputStream(int bufferSize, int enlargeSize)
bufferSize
- size of the buffer (in bytes)enlargeSize
- size the buffer is going to grow if needed (argument to ByteArrays)public int getPos()
public void write(int b) throws IOException
write
in class OutputStream
b
- int containing the byte to write.IOException
- if an I/O error occurs.public void writeByte(byte b) throws IOException
b
- byte to write.IOException
- if an I/O error occurs.public void write(byte[] b, int offset, int length) throws IOException
write
in class OutputStream
b
- byte[] array containing the bytes to writeoffset
- int offset where the data to write beginslength
- int number of elements to writeIOException
- if an I/O error occurspublic int getSize()
public byte[] getBuffer()
public void flush() throws IOException
flush
in interface Flushable
flush
in class OutputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
Terrier Information Retrieval Platform4.1. Copyright © 2004-2015, University of Glasgow