java.lang.Object
org.glassfish.grizzly.streams.AbstractStreamWriter
- All Implemented Interfaces:
Closeable,AutoCloseable,Stream,StreamWriter
- Direct Known Subclasses:
DefaultStreamWriter,TransformerStreamWriter
Write the primitive Java type to the current ByteBuffer. If it doesn't fit, call the BufferHandler, and write to the
result, which becomes the new current ByteBuffer. Arrays will be written across multiple ByteBuffers if necessary,
but all primitives will be written to a single ByteBuffer.
- Author:
- Ken Cavanaugh
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanprotected static final Loggerprotected final Outputprotected static final Integerprotected static final GrizzlyFuture<Integer> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractStreamWriter(Connection connection, Output streamOutput) Create a new ByteBufferWriter. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()close(CompletionHandler<Integer> completionHandler) Close theStreamWriterand make sure all data was flushed.<E> GrizzlyFuture<Stream>encode(Transformer<E, Buffer> encoder, E object) <E> GrizzlyFuture<Stream>encode(Transformer<E, Buffer> encoder, E object, CompletionHandler<Stream> completionHandler) flush()Cause the overflow handler to be called even if buffer is not full.flush(CompletionHandler<Integer> completionHandler) Cause the overflow handler to be called even if buffer is not full.Get theConnectionthis StreamWriter belongs to.longgetTimeout(TimeUnit timeunit) Get the timeout for StreamWriter I/O operations.booleanisClosed()Returns true, if StreamReader has been closed, or false otherwise.voidsetTimeout(long timeout, TimeUnit timeunit) Set the timeout for StreamWriter I/O operations.voidwriteBoolean(boolean data) Write the boolean value to the StreamWriter.voidwriteBooleanArray(boolean[] data) Write the array of boolean values to the StreamWriter.voidWrite theBufferto the StreamWriter.voidwriteByte(byte data) Write the byte value to the StreamWriter.voidwriteByteArray(byte[] data) Write the array of byte values to the StreamWriter.voidwriteByteArray(byte[] data, int offset, int length) Write the part of array of byte values to the StreamWriter, using specific offset and length values.voidwriteChar(char data) Write the char value to the StreamWriter.voidwriteCharArray(char[] data) Write the array of char values to the StreamWriter.voidwriteDouble(double data) Write the double value to the StreamWriter.voidwriteDoubleArray(double[] data) Write the array of double values to the StreamWriter.voidwriteFloat(float data) Write the float value to the StreamWriter.voidwriteFloatArray(float[] data) Write the array of float values to the StreamWriter.voidwriteInt(int data) Write the int value to the StreamWriter.voidwriteIntArray(int[] data) Write the array of int values to the StreamWriter.voidwriteLong(long data) Write the long value to the StreamWriter.voidwriteLongArray(long[] data) Write the array of long values to the StreamWriter.voidwriteShort(short data) Write the short value to the StreamWriter.voidwriteShortArray(short[] data) Write the array of short values to the StreamWriter.
-
Field Details
-
logger
-
ZERO
-
ZERO_READY_FUTURE
-
isOutputBuffered
protected final boolean isOutputBuffered -
output
-
-
Constructor Details
-
AbstractStreamWriter
Create a new ByteBufferWriter. An instance maintains a current buffer for use in writing. Whenever the current buffer is insufficient to hold the required data, the BufferHandler is called, and the result of the handler is the new current buffer. The handler is responsible for the disposition of the contents of the old buffer.
-
-
Method Details
-
flush
Cause the overflow handler to be called even if buffer is not full.- Specified by:
flushin interfaceStreamWriter- Throws:
IOException
-
flush
public GrizzlyFuture<Integer> flush(CompletionHandler<Integer> completionHandler) throws IOException Cause the overflow handler to be called even if buffer is not full.- Specified by:
flushin interfaceStreamWriter- Throws:
IOException
-
isClosed
public boolean isClosed()Returns true, if StreamReader has been closed, or false otherwise.- Specified by:
isClosedin interfaceStreamWriter- Returns:
- true, if StreamReader has been closed, or false otherwise.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
close
public GrizzlyFuture<Integer> close(CompletionHandler<Integer> completionHandler) throws IOException Close theStreamWriterand make sure all data was flushed.- Specified by:
closein interfaceStreamWriter- Throws:
IOException
-
writeBuffer
Write theBufferto the StreamWriter.- Specified by:
writeBufferin interfaceStreamWriter- Parameters:
b-Buffer.- Throws:
IOException
-
writeBoolean
Write the boolean value to the StreamWriter.- Specified by:
writeBooleanin interfaceStreamWriter- Parameters:
data- boolean value.- Throws:
IOException
-
writeByte
Write the byte value to the StreamWriter.- Specified by:
writeBytein interfaceStreamWriter- Parameters:
data- byte value.- Throws:
IOException
-
writeChar
Write the char value to the StreamWriter.- Specified by:
writeCharin interfaceStreamWriter- Parameters:
data- char value.- Throws:
IOException
-
writeShort
Write the short value to the StreamWriter.- Specified by:
writeShortin interfaceStreamWriter- Parameters:
data- short value.- Throws:
IOException
-
writeInt
Description copied from interface:StreamWriterWrite the int value to the StreamWriter.- Specified by:
writeIntin interfaceStreamWriter- Parameters:
data- int value.- Throws:
IOException
-
writeLong
Write the long value to the StreamWriter.- Specified by:
writeLongin interfaceStreamWriter- Parameters:
data- long value.- Throws:
IOException
-
writeFloat
Write the float value to the StreamWriter.- Specified by:
writeFloatin interfaceStreamWriter- Parameters:
data- float value.- Throws:
IOException
-
writeDouble
Write the double value to the StreamWriter.- Specified by:
writeDoublein interfaceStreamWriter- Parameters:
data- double value.- Throws:
IOException
-
writeBooleanArray
Write the array of boolean values to the StreamWriter.- Specified by:
writeBooleanArrayin interfaceStreamWriter- Parameters:
data- array of boolean values.- Throws:
IOException
-
writeByteArray
Write the array of byte values to the StreamWriter.- Specified by:
writeByteArrayin interfaceStreamWriter- Parameters:
data- array of byte values.- Throws:
IOException
-
writeByteArray
Write the part of array of byte values to the StreamWriter, using specific offset and length values.- Specified by:
writeByteArrayin interfaceStreamWriter- Parameters:
data- array of byte values.offset- array offset to start from.length- number of bytes to write.- Throws:
IOException
-
writeCharArray
Write the array of char values to the StreamWriter.- Specified by:
writeCharArrayin interfaceStreamWriter- Parameters:
data- array of char values.- Throws:
IOException
-
writeShortArray
Write the array of short values to the StreamWriter.- Specified by:
writeShortArrayin interfaceStreamWriter- Parameters:
data- array of short values.- Throws:
IOException
-
writeIntArray
Write the array of int values to the StreamWriter.- Specified by:
writeIntArrayin interfaceStreamWriter- Parameters:
data- array of int values.- Throws:
IOException
-
writeLongArray
Write the array of long values to the StreamWriter.- Specified by:
writeLongArrayin interfaceStreamWriter- Parameters:
data- array of long values.- Throws:
IOException
-
writeFloatArray
Write the array of float values to the StreamWriter.- Specified by:
writeFloatArrayin interfaceStreamWriter- Parameters:
data- array of float values.- Throws:
IOException
-
writeDoubleArray
Write the array of double values to the StreamWriter.- Specified by:
writeDoubleArrayin interfaceStreamWriter- Parameters:
data- array of double values.- Throws:
IOException
-
encode
- Specified by:
encodein interfaceStreamWriter- Throws:
IOException
-
encode
public <E> GrizzlyFuture<Stream> encode(Transformer<E, Buffer> encoder, E object, CompletionHandler<Stream> completionHandler) throws IOException- Specified by:
encodein interfaceStreamWriter- Throws:
IOException
-
getConnection
Get theConnectionthis StreamWriter belongs to.- Specified by:
getConnectionin interfaceStream- Specified by:
getConnectionin interfaceStreamWriter- Returns:
- the
Connectionthis StreamWriter belongs to.
-
getTimeout
Get the timeout for StreamWriter I/O operations.- Specified by:
getTimeoutin interfaceStreamWriter- Parameters:
timeunit- timeout unitTimeUnit.- Returns:
- the timeout for StreamWriter I/O operations.
-
setTimeout
Set the timeout for StreamWriter I/O operations.- Specified by:
setTimeoutin interfaceStreamWriter- Parameters:
timeout- the timeout for StreamWriter I/O operations.timeunit- timeout unitTimeUnit.
-