org.simpleframework.transport
Interface Transport

All Superinterfaces:
Socket

public interface Transport
extends Socket

The Transport interface represents a low level means to deliver content to the connected client. Typically this will be a connected, non-blocking, TCP connection. However, for tests and other purposes this may be adapted. The general contract of the transport is that it provides non-blocking reads and blocking writes. Blocking writes are required to ensure that memory does not build up in output buffers during high load periods.

Author:
Niall Gallagher

Method Summary
 void close()
          This is used to close the transport and the underlying socket.
 void flush()
          This method is used to flush the contents of the buffer to the client.
 int read(java.nio.ByteBuffer buffer)
          This is used to perform a non-blocking read on the transport.
 void write(java.nio.ByteBuffer buffer)
          This method is used to deliver the provided buffer of bytes to the underlying transport.
 
Methods inherited from interface org.simpleframework.transport.Socket
getAttributes, getChannel, getEngine
 

Method Detail

read

int read(java.nio.ByteBuffer buffer)
         throws java.io.IOException
This is used to perform a non-blocking read on the transport. If there are no bytes available on the input buffers then this method will return zero and the buffer will remain the same. If there is data and the buffer can be filled then this will return the number of bytes read. Finally if the socket is closed this will return a -1 value.

Parameters:
buffer - this is the buffer to append the bytes to
Returns:
this returns the number of bytes that have been read
Throws:
java.io.IOException

write

void write(java.nio.ByteBuffer buffer)
           throws java.io.IOException
This 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 send directly. Any implementation may choose to buffer the bytes for performance.

Parameters:
buffer - this is the buffer of bytes to send to the client
Throws:
java.io.IOException

flush

void flush()
           throws java.io.IOException
This method is used to flush the contents of the buffer to the client. This method will block not block but will simply flush any data to the underlying transport. Internally the data will be queued for delivery to the connected entity.

Throws:
java.io.IOException

close

void close()
           throws java.io.IOException
This is used to close the transport and the underlying socket. If a close is performed on the transport then no more bytes can be read from or written to the transport and the client will receive a connection close on their side.

Throws:
java.io.IOException