Package org.glassfish.grizzly.utils
Class BufferOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.glassfish.grizzly.utils.BufferOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class BufferOutputStream extends java.io.OutputStreamOutputStreamimplementation to write to aBuffer.
-
-
Constructor Summary
Constructors Constructor Description BufferOutputStream(MemoryManager mm)Creates the BufferOutputStream without initial Buffer.BufferOutputStream(MemoryManager mm, Buffer buffer)Creates the BufferOutputStream using passedBufferas initial.BufferOutputStream(MemoryManager mm, Buffer buffer, boolean reallocate)Creates the BufferOutputStream using passedBufferas initial.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected BufferallocateNewBuffer(MemoryManager memoryManager, int size)voidclose()voidflush()BuffergetBuffer()Get the resultBuffer(not flipped).booleanisReallocate()Returns true if "reallocate" strategy is used or false otherwise.voidreset()voidsetInitialOutputBuffer(Buffer initialBuffer)voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)
-
-
-
Constructor Detail
-
BufferOutputStream
public BufferOutputStream(MemoryManager mm)
Creates the BufferOutputStream without initial Buffer. Created BufferOutputStream won't use "reallocate" strategy, which means if internalBufferwindow gets overloaded - it will be appended to theCompositeBufferand new window will be allocated.- Parameters:
mm-MemoryManager
-
BufferOutputStream
public BufferOutputStream(MemoryManager mm, Buffer buffer)
Creates the BufferOutputStream using passedBufferas initial. Created BufferOutputStream won't use "reallocate" strategy, which means if internalBufferwindow gets overloaded - it will be appended to theCompositeBufferand new window will be allocated.- Parameters:
mm-MemoryManagerbuffer- initialBuffer
-
BufferOutputStream
public BufferOutputStream(MemoryManager mm, Buffer buffer, boolean reallocate)
Creates the BufferOutputStream using passedBufferas initial. Created BufferOutputStream can choose whether use or not "reallocate" strategy. Using "reallocate" strategy means following: if internalBufferwindow gets overloaded - it will be reallocated usingMemoryManager.reallocate(org.glassfish.grizzly.Buffer, int), which may lead to extra memory allocation and bytes copying (bigger memory chunk might be allocated to keep original stream data plus extra data been written to stream), the benefit of this is that stream data will be located in the single memory chunk. If we don't use "reallocate" strategy - when internalBuffergets overloaded it will be appended to theCompositeBufferand new windowBufferwill be allocated then.- Parameters:
mm-MemoryManagerbuffer- initialBuffer
-
-
Method Detail
-
setInitialOutputBuffer
public void setInitialOutputBuffer(Buffer initialBuffer)
-
getBuffer
public Buffer getBuffer()
Get the resultBuffer(not flipped).- Returns:
- the result
Buffer(not flipped).
-
isReallocate
public boolean isReallocate()
Returns true if "reallocate" strategy is used or false otherwise. Using "reallocate" strategy means following: if internalBufferwindow gets overloaded - it will be reallocated usingMemoryManager.reallocate(org.glassfish.grizzly.Buffer, int), which may lead to extra memory allocation and bytes copying (bigger memory chunk might be allocated to keep original stream data plus extra data been written to stream), the benefit of this is that stream data will be located in the single memory chunk. If we don't use "reallocate" strategy - when internalBuffergets overloaded it will be appended to theCompositeBufferand new windowBufferwill be allocated then.- Returns:
- true if "reallocate" strategy is used or false otherwise.
-
write
public void write(int b) throws java.io.IOException- Specified by:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
reset
public void reset()
-
allocateNewBuffer
protected Buffer allocateNewBuffer(MemoryManager memoryManager, int size)
-
-