Package org.simpleframework.transport
Class TransportWriter
- java.lang.Object
-
- org.simpleframework.transport.TransportWriter
-
- All Implemented Interfaces:
ByteWriter
public class TransportWriter extends java.lang.Object implements ByteWriter
TheTransportWriterobject is used to write bytes to and underlying transport. This is essentially an adapter between anOutputStreamand the underlying transport. Each byte array segment written to the underlying transport is wrapped in a bytes buffer so that it can be sent by the transport layer.- See Also:
Transport
-
-
Constructor Summary
Constructors Constructor Description TransportWriter(Transport transport)Constructor for theTransportWriterobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()This is used to close the writer and the underlying transport.voidflush()This method is used to flush the contents of the buffer to the client.voidwrite(byte[] array)This method is used to deliver the provided array of bytes to the underlying transport.voidwrite(byte[] array, int off, int len)This method is used to deliver the provided array of bytes to the underlying transport.voidwrite(java.nio.ByteBuffer buffer)This method is used to deliver the provided buffer of bytes to the underlying transport.voidwrite(java.nio.ByteBuffer buffer, int off, int len)This method is used to deliver the provided buffer of bytes to the underlying transport.
-
-
-
Field Detail
-
closed
private final java.util.concurrent.atomic.AtomicBoolean closed
This is used to determine if the transport has been closed.
-
transport
private final Transport transport
This is the underlying transport to write the bytes to.
-
-
Constructor Detail
-
TransportWriter
public TransportWriter(Transport transport)
Constructor for theTransportWriterobject. This is used to create an adapter for the transport such that a byte array can be used to write bytes to the array.- Parameters:
transport- the underlying transport to write bytes to
-
-
Method Detail
-
write
public void write(byte[] array) throws java.io.IOExceptionThis method is used to deliver the provided array of bytes to the underlying transport. Depending on the connection type the array may be encoded for SSL transport or write directly. Any implementation may choose to buffer the bytes for performance.- Specified by:
writein interfaceByteWriter- Parameters:
array- this is the array of bytes to write to the client- Throws:
java.io.IOException
-
write
public void write(byte[] array, int off, int len) throws java.io.IOExceptionThis method is used to deliver the provided array of bytes to the underlying transport. Depending on the connection type the array may be encoded for SSL transport or write directly. Any implementation may choose to buffer the bytes for performance.- Specified by:
writein interfaceByteWriter- Parameters:
array- this is the array of bytes to write to the clientoff- this is the offset within the array to write fromlen- this is the number of bytes that are to be sent- Throws:
java.io.IOException
-
write
public void write(java.nio.ByteBuffer buffer) throws java.io.IOExceptionThis method is used to deliver the provided buffer of bytes to the underlying transport. Depending on the connection type the array may be encoded for SSL transport or write directly. Any implementation may choose to buffer the bytes for performance.- Specified by:
writein interfaceByteWriter- Parameters:
buffer- this is the buffer of bytes to write to the client- Throws:
java.io.IOException
-
write
public void write(java.nio.ByteBuffer buffer, int off, int len) throws java.io.IOExceptionThis method is used to deliver the provided buffer of bytes to the underlying transport. Depending on the connection type the array may be encoded for SSL transport or write directly. Any implementation may choose to buffer the bytes for performance.- Specified by:
writein interfaceByteWriter- Parameters:
buffer- this is the buffer of bytes to write to the clientoff- this is the offset within the buffer to write fromlen- this is the number of bytes that are to be sent- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOExceptionThis method is used to flush the contents of the buffer to the client. This method will block until such time as all of the data has been sent to the client. If at any point there is an error writing the content an exception is thrown.- Specified by:
flushin interfaceByteWriter- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionThis is used to close the writer and the underlying transport. If a close is performed on the writer then no more bytes can be read from or written to the transport and the client will received a connection close on their side.- Specified by:
closein interfaceByteWriter- Throws:
java.io.IOException
-
-