Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.mule.transport.tcp.protocols
Class AbstractByteProtocol

    java.lang.Object
      org.mule.transport.tcp.protocols.AbstractByteProtocol

All Implemented Interfaces:
  TcpProtocol

Direct Known Subclasses:
  DirectProtocol, XmlMessageProtocol

    public abstract class AbstractByteProtocol

extends Object
implements TcpProtocol

This Abstract class has been introduced so as to have the byte protocols (i.e. the protocols that had only a single write method taking just an array of bytes as a parameter) to inherit from since they will all behave the same, i.e. if the object is serializable, serialize it into an array of bytes and send it.

Note that the raw write method has changed name from `write` to `writeByteArray`. This is to remove ambiguity from the code. In almost all cases it is possible to call `write(java.io.OutputStream, Object)` which will, via `write(java.io.OutputStream, Object)`, dispatch to `writeByteArray(java.io.OutputStream, byte[])`.

.

Field Summary
`static int` | `EOF`
`static boolean` | `NO_STREAM`
`static boolean` | `STREAM_OK`

Constructor Summary
`AbstractByteProtocol(boolean streamOk)`

Method Summary
`protected int` | `copy(InputStream source, byte[] buffer, OutputStream dest)` Make a single transfer from source to dest via a byte array buffer
`protected int` | `copy(InputStream source, byte[] buffer, OutputStream dest, int size)` Make a single transfer from source to dest via a byte array buffer
`ResponseOutputStream` | `createResponse(Socket socket)` This lets protocols encode a response stream.
`boolean` | `isRethrowExceptionOnRead()`
`protected byte[]` | `nullEmptyArray(byte[] data)`
`protected int` | `safeRead(InputStream is, byte[] buffer)` Manage non-blocking reads and handle errors
`protected int` | `safeRead(InputStream is, byte[] buffer, int size)` Manage non-blocking reads and handle errors
`void` | `setRethrowExceptionOnRead(boolean rethrowExceptionOnRead)`
`void` | `write(OutputStream os, Object data)` Write the specified message to the output stream.
`protected void` | `writeByteArray(OutputStream os, byte[] data)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface org.mule.transport.tcp.TcpProtocol
`read`

Field Detail

### EOF

    public static final int EOF

See Also:
  Constant Field Values

### STREAM_OK

    public static final boolean STREAM_OK

See Also:
  Constant Field Values

### NO_STREAM

    public static final boolean NO_STREAM

See Also:
  Constant Field Values

Constructor Detail

### AbstractByteProtocol

    public AbstractByteProtocol(boolean streamOk)

Method Detail

### write

    public void write(OutputStream os,
                      Object data)
               throws IOException

  Description copied from interface: `TcpProtocol`
  Write the specified message to the output stream.

  Specified by:
    `write` in interface `TcpProtocol`
  Parameters:
    `os` - the output stream to write to
    `data` - the data to write
  Throws:
    `IOException` - if an exception occurs

### writeByteArray

    protected void writeByteArray(OutputStream os,
                                  byte[] data)
                           throws IOException

  Throws:
    `IOException`

### safeRead

    protected int safeRead(InputStream is,
                           byte[] buffer)
                    throws IOException

  Manage non-blocking reads and handle errors

  Parameters:
    `is` - The input stream to read from
    `buffer` - The buffer to read into
  Returns:
    The amount of data read (always non-zero, -1 on EOF or socket exception)
  Throws:
    `IOException` - other than socket exceptions

### safeRead

    protected int safeRead(InputStream is,
                           byte[] buffer,
                           int size)
                    throws IOException

  Manage non-blocking reads and handle errors

  Parameters:
    `is` - The input stream to read from
    `buffer` - The buffer to read into
    `size` - The amount of data (upper bound) to read
  Returns:
    The amount of data read (always non-zero, -1 on EOF or socket exception)
  Throws:
    `IOException` - other than socket exceptions

### copy

    protected int copy(InputStream source,
                       byte[] buffer,
                       OutputStream dest)
                throws IOException

  Make a single transfer from source to dest via a byte array buffer

  Parameters:
    `source` - Source of data
    `buffer` - Buffer array for transfer
    `dest` - Destination of data
  Returns:
    Amount of data transferred, or -1 on eof or socket error
  Throws:
    `IOException` - On non-socket error

### copy

    protected int copy(InputStream source,
                       byte[] buffer,
                       OutputStream dest,
                       int size)
                throws IOException

  Make a single transfer from source to dest via a byte array buffer

  Parameters:
    `source` - Source of data
    `buffer` - Buffer array for transfer
    `dest` - Destination of data
    `size` - The amount of data (upper bound) to read
  Returns:
    Amount of data transferred, or -1 on eof or socket error
  Throws:
    `IOException` - On non-socket error

### nullEmptyArray

    protected byte[] nullEmptyArray(byte[] data)

### createResponse

    public ResponseOutputStream createResponse(Socket socket)
                                        throws IOException

  Description copied from interface: `TcpProtocol`
  This lets protocols encode a response stream. If the protocol does not support a response stream (ie does not support streaming) then the stream should thrown an exception when used.

  Specified by:
    `createResponse` in interface `TcpProtocol`
  Parameters:
    `socket` - The destination to write to
  Returns:
    A stream whose output will be encoded
  Throws:
    `IOException`

### isRethrowExceptionOnRead

    public boolean isRethrowExceptionOnRead()

### setRethrowExceptionOnRead

    public void setRethrowExceptionOnRead(boolean rethrowExceptionOnRead)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2010 MuleSoft, Inc.. All Rights Reserved.