java.lang.Object
java.io.OutputStream
org.glassfish.grizzly.utils.BufferOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
OutputStream implementation to write to a Buffer.-
Constructor Summary
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionprotected BufferallocateNewBuffer(MemoryManager memoryManager, int size) voidclose()voidflush()Get the resultBuffer(not flipped).booleanReturns 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 Details
-
BufferOutputStream
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
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
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 Details
-
setInitialOutputBuffer
-
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
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
reset
public void reset() -
allocateNewBuffer
-