FileDocCategorySizeDatePackage
SSLEngineAppData.javaAPI DocAndroid 1.5 API3326Wed May 06 22:41:06 BST 2009org.apache.harmony.xnet.provider.jsse

SSLEngineAppData

public class SSLEngineAppData extends Object implements org.apache.harmony.xnet.provider.jsse.Appendable
This class is used to retrieve the application data arrived for the SSLEngine.

Fields Summary
byte[]
buffer
Buffer containing received application data.
Constructors Summary
protected SSLEngineAppData()
Constructor

Methods Summary
public voidappend(byte[] src)
Stores received data. The source data is not cloned, just the array reference is remembered into the buffer field.

        if (buffer != null) {
            throw new AlertException(
                AlertProtocol.INTERNAL_ERROR,
                new SSLException("Attempt to override the data"));
        }
        buffer = src;
    
protected intplaceTo(java.nio.ByteBuffer[] dsts, int offset, int length)
Places the data from the buffer into the array of destination ByteBuffer objects.

        if (buffer == null) {
            return 0;
        }
        int pos = 0;
        int len = buffer.length;
        int rem;
        // write data to the buffers
        for (int i=offset; i<offset+length; i++) {
            rem = dsts[i].remaining();
            // TODO: optimization work - use hasArray, array(), arraycopy
            if (len - pos < rem) {
                // can fully write remaining data into buffer
                dsts[i].put(buffer, pos, len - pos);
                pos = len;
                // data was written, exit
                break;
            } else {
                // write chunk of data
                dsts[i].put(buffer, pos, rem);
                pos += rem;
            }
        }
        if (pos != len) {
            // The data did not feet into the buffers,
            // it should not happen, because the destination buffers
            // had been checked for the space before record unwrapping.
            // But if it so, we should allert about internal error.
            throw new AlertException(
                AlertProtocol.INTERNAL_ERROR,
                new SSLException(
                    "The received application data could not be fully written"
                    + "into the destination buffers"));
        }
        buffer = null;
        return len;