Package org.glassfish.grizzly.utils
Class BufferOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.glassfish.grizzly.utils.BufferOutputStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
public class BufferOutputStream extends OutputStream
OutputStreamimplementation 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)-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
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 IOException- Specified by:
writein classOutputStream- Throws:
IOException
-
write
public void write(byte[] b) throws IOException- Overrides:
writein classOutputStream- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException- Overrides:
writein classOutputStream- Throws:
IOException
-
flush
public void flush() throws IOException- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
reset
public void reset()
-
allocateNewBuffer
protected Buffer allocateNewBuffer(MemoryManager memoryManager, int size)
-
-