org.glassfish.grizzly.streams
Class AbstractStreamWriter

java.lang.Object
  extended by org.glassfish.grizzly.streams.AbstractStreamWriter
All Implemented Interfaces:
java.io.Closeable, Stream, StreamWriter
Direct Known Subclasses:
DefaultStreamWriter, TransformerStreamWriter

public abstract class AbstractStreamWriter
extends java.lang.Object
implements StreamWriter

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
static class AbstractStreamWriter.DisposeBufferCompletionHandler
           
 
Field Summary
protected  boolean isOutputBuffered
           
protected static java.util.logging.Logger logger
           
protected  Output output
           
protected static java.lang.Integer ZERO
           
protected static GrizzlyFuture<java.lang.Integer> ZERO_READY_FUTURE
           
 
Constructor Summary
protected AbstractStreamWriter(Connection connection, Output streamOutput)
          Create a new ByteBufferWriter.
 
Method Summary
 void close()
          
 GrizzlyFuture<java.lang.Integer> close(CompletionHandler<java.lang.Integer> completionHandler)
          Close the StreamWriter and 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)
          
 GrizzlyFuture<java.lang.Integer> flush()
          Cause the overflow handler to be called even if buffer is not full.
 GrizzlyFuture<java.lang.Integer> flush(CompletionHandler<java.lang.Integer> completionHandler)
          Cause the overflow handler to be called even if buffer is not full.
 Connection getConnection()
          Get the Connection this StreamWriter belongs to.
 long getTimeout(java.util.concurrent.TimeUnit timeunit)
          Get the timeout for StreamWriter I/O operations.
 boolean isClosed()
          Returns true, if StreamReader has been closed, or false otherwise.
 void setTimeout(long timeout, java.util.concurrent.TimeUnit timeunit)
          Set the timeout for StreamWriter I/O operations.
 void writeBoolean(boolean data)
          Write the boolean value to the StreamWriter.
 void writeBooleanArray(boolean[] data)
          Write the array of boolean values to the StreamWriter.
 void writeBuffer(Buffer b)
          Write the Buffer to the StreamWriter.
 void writeByte(byte data)
          Write the byte value to the StreamWriter.
 void writeByteArray(byte[] data)
          Write the array of byte values to the StreamWriter.
 void writeByteArray(byte[] data, int offset, int length)
          Write the part of array of byte values to the StreamWriter, using specific offset and length values.
 void writeChar(char data)
          Write the char value to the StreamWriter.
 void writeCharArray(char[] data)
          Write the array of char values to the StreamWriter.
 void writeDouble(double data)
          Write the double value to the StreamWriter.
 void writeDoubleArray(double[] data)
          Write the array of double values to the StreamWriter.
 void writeFloat(float data)
          Write the float value to the StreamWriter.
 void writeFloatArray(float[] data)
          Write the array of float values to the StreamWriter.
 void writeInt(int data)
          Write the int value to the StreamWriter.
 void writeIntArray(int[] data)
          Write the array of int values to the StreamWriter.
 void writeLong(long data)
          Write the long value to the StreamWriter.
 void writeLongArray(long[] data)
          Write the array of long values to the StreamWriter.
 void writeShort(short data)
          Write the short value to the StreamWriter.
 void writeShortArray(short[] data)
          Write the array of short values to the StreamWriter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final java.util.logging.Logger logger

ZERO

protected static final java.lang.Integer ZERO

ZERO_READY_FUTURE

protected static final GrizzlyFuture<java.lang.Integer> ZERO_READY_FUTURE

isOutputBuffered

protected final boolean isOutputBuffered

output

protected final Output output
Constructor Detail

AbstractStreamWriter

protected AbstractStreamWriter(Connection connection,
                               Output streamOutput)
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 Detail

flush

public GrizzlyFuture<java.lang.Integer> flush()
                                       throws java.io.IOException
Cause the overflow handler to be called even if buffer is not full.

Specified by:
flush in interface StreamWriter
Throws:
java.io.IOException

flush

public GrizzlyFuture<java.lang.Integer> flush(CompletionHandler<java.lang.Integer> completionHandler)
                                       throws java.io.IOException
Cause the overflow handler to be called even if buffer is not full.

Specified by:
flush in interface StreamWriter
Throws:
java.io.IOException

isClosed

public boolean isClosed()
Returns true, if StreamReader has been closed, or false otherwise.

Specified by:
isClosed in interface StreamWriter
Returns:
true, if StreamReader has been closed, or false otherwise.

close

public void close()
           throws java.io.IOException

Specified by:
close in interface java.io.Closeable
Throws:
java.io.IOException

close

public GrizzlyFuture<java.lang.Integer> close(CompletionHandler<java.lang.Integer> completionHandler)
                                       throws java.io.IOException
Close the StreamWriter and make sure all data was flushed.

Specified by:
close in interface StreamWriter
Throws:
java.io.IOException

writeBuffer

public void writeBuffer(Buffer b)
                 throws java.io.IOException
Write the Buffer to the StreamWriter.

Specified by:
writeBuffer in interface StreamWriter
Parameters:
b - Buffer.
Throws:
java.io.IOException

writeBoolean

public void writeBoolean(boolean data)
                  throws java.io.IOException
Write the boolean value to the StreamWriter.

Specified by:
writeBoolean in interface StreamWriter
Parameters:
data - boolean value.
Throws:
java.io.IOException

writeByte

public void writeByte(byte data)
               throws java.io.IOException
Write the byte value to the StreamWriter.

Specified by:
writeByte in interface StreamWriter
Parameters:
data - byte value.
Throws:
java.io.IOException

writeChar

public void writeChar(char data)
               throws java.io.IOException
Write the char value to the StreamWriter.

Specified by:
writeChar in interface StreamWriter
Parameters:
data - char value.
Throws:
java.io.IOException

writeShort

public void writeShort(short data)
                throws java.io.IOException
Write the short value to the StreamWriter.

Specified by:
writeShort in interface StreamWriter
Parameters:
data - short value.
Throws:
java.io.IOException

writeInt

public void writeInt(int data)
              throws java.io.IOException
Description copied from interface: StreamWriter
Write the int value to the StreamWriter.

Specified by:
writeInt in interface StreamWriter
Parameters:
data - int value.
Throws:
java.io.IOException

writeLong

public void writeLong(long data)
               throws java.io.IOException
Write the long value to the StreamWriter.

Specified by:
writeLong in interface StreamWriter
Parameters:
data - long value.
Throws:
java.io.IOException

writeFloat

public void writeFloat(float data)
                throws java.io.IOException
Write the float value to the StreamWriter.

Specified by:
writeFloat in interface StreamWriter
Parameters:
data - float value.
Throws:
java.io.IOException

writeDouble

public void writeDouble(double data)
                 throws java.io.IOException
Write the double value to the StreamWriter.

Specified by:
writeDouble in interface StreamWriter
Parameters:
data - double value.
Throws:
java.io.IOException

writeBooleanArray

public void writeBooleanArray(boolean[] data)
                       throws java.io.IOException
Write the array of boolean values to the StreamWriter.

Specified by:
writeBooleanArray in interface StreamWriter
Parameters:
data - array of boolean values.
Throws:
java.io.IOException

writeByteArray

public void writeByteArray(byte[] data)
                    throws java.io.IOException
Write the array of byte values to the StreamWriter.

Specified by:
writeByteArray in interface StreamWriter
Parameters:
data - array of byte values.
Throws:
java.io.IOException

writeByteArray

public void writeByteArray(byte[] data,
                           int offset,
                           int length)
                    throws java.io.IOException
Write the part of array of byte values to the StreamWriter, using specific offset and length values.

Specified by:
writeByteArray in interface StreamWriter
Parameters:
data - array of byte values.
offset - array offset to start from.
length - number of bytes to write.
Throws:
java.io.IOException

writeCharArray

public void writeCharArray(char[] data)
                    throws java.io.IOException
Write the array of char values to the StreamWriter.

Specified by:
writeCharArray in interface StreamWriter
Parameters:
data - array of char values.
Throws:
java.io.IOException

writeShortArray

public void writeShortArray(short[] data)
                     throws java.io.IOException
Write the array of short values to the StreamWriter.

Specified by:
writeShortArray in interface StreamWriter
Parameters:
data - array of short values.
Throws:
java.io.IOException

writeIntArray

public void writeIntArray(int[] data)
                   throws java.io.IOException
Write the array of int values to the StreamWriter.

Specified by:
writeIntArray in interface StreamWriter
Parameters:
data - array of int values.
Throws:
java.io.IOException

writeLongArray

public void writeLongArray(long[] data)
                    throws java.io.IOException
Write the array of long values to the StreamWriter.

Specified by:
writeLongArray in interface StreamWriter
Parameters:
data - array of long values.
Throws:
java.io.IOException

writeFloatArray

public void writeFloatArray(float[] data)
                     throws java.io.IOException
Write the array of float values to the StreamWriter.

Specified by:
writeFloatArray in interface StreamWriter
Parameters:
data - array of float values.
Throws:
java.io.IOException

writeDoubleArray

public void writeDoubleArray(double[] data)
                      throws java.io.IOException
Write the array of double values to the StreamWriter.

Specified by:
writeDoubleArray in interface StreamWriter
Parameters:
data - array of double values.
Throws:
java.io.IOException

encode

public <E> GrizzlyFuture<Stream> encode(Transformer<E,Buffer> encoder,
                                        E object)
                             throws java.io.IOException

Specified by:
encode in interface StreamWriter
Throws:
java.io.IOException

encode

public <E> GrizzlyFuture<Stream> encode(Transformer<E,Buffer> encoder,
                                        E object,
                                        CompletionHandler<Stream> completionHandler)
                             throws java.io.IOException

Specified by:
encode in interface StreamWriter
Throws:
java.io.IOException

getConnection

public Connection getConnection()
Get the Connection this StreamWriter belongs to.

Specified by:
getConnection in interface Stream
Specified by:
getConnection in interface StreamWriter
Returns:
the Connection this StreamWriter belongs to.

getTimeout

public long getTimeout(java.util.concurrent.TimeUnit timeunit)
Get the timeout for StreamWriter I/O operations.

Specified by:
getTimeout in interface StreamWriter
Parameters:
timeunit - timeout unit TimeUnit.
Returns:
the timeout for StreamWriter I/O operations.

setTimeout

public void setTimeout(long timeout,
                       java.util.concurrent.TimeUnit timeunit)
Set the timeout for StreamWriter I/O operations.

Specified by:
setTimeout in interface StreamWriter
Parameters:
timeout - the timeout for StreamWriter I/O operations.
timeunit - timeout unit TimeUnit.


Copyright © 2012 Oracle Corporation. All Rights Reserved.