FileDocCategorySizeDatePackage
Out.javaAPI DocphoneME MR2 API (J2ME)4573Wed May 02 18:00:00 BST 2007com.sun.midp.ssl

Out

public class Out extends OutputStream
This class is a subclass of OutputStream and is used for writing data to an SSL connection.

see
com.sun.midp.ssl.SSLStreamConnection
see
com.sun.midp.ssl.In

Fields Summary
private static final int
MAX_RECORD_SIZE
The maximum SSL record size to write, currently 2048. RFC 2246 specifies it can be up to 2^14 + 2048, however breaking up streams into smaller chunks make more sense, lower memory usage for small devices and interspacing encryption and network writes may work better on congested wireless networks.
private boolean
isClosed
Indicates the output stream is closed.
private Record
rec
Underlying SSL record layer to which bytes are written.
private SSLStreamConnection
ssc
Handle to current SSL stream connection.
private byte[]
buf
A reusable buffer for the write method.
Constructors Summary
Out(Record r, SSLStreamConnection c)
Creates a new Out object.

param
r SSL record layer object to which bytes are written
param
c SSLStreamConnection object this Out object is a part of


                                       
        
        rec = r;
        ssc = c;
    
Methods Summary
public synchronized voidclose()
Close the stream connection.

exception
IOException is thrown, if an I/O error occurs while shutting down the connection

        if (isClosed) {
            return;
        }

        isClosed = true;
        if (ssc != null) {
            ssc.outputStreamState = SSLStreamConnection.CLOSED;
            rec.closeOutputStream();
            ssc.cleanupIfNeeded();
        }
    
public voidwrite(int b)
Writes the specified byte to this output stream.

param
b byte to be written
exception
IOException if I/O error occurs

        buf[0] = (byte) b;
        write(buf, 0, 1);
    
public voidwrite(byte[] b)
Writes all the bytes in the specified byte array to this output stream. This is equivalent to write(b, 0, b.length).

param
b byte array containing data to be written
exception
IOException if I/O error occurs

        write(b, 0, b.length);
    
public voidwrite(byte[] b, int off, int len)
Writes len bytes starting at offset off from byte array b to this output stream.

param
b byte array containing data to be written
param
off starting offset of data to be written
param
len number of bytes to be written
exception
IOException if I/O error occurs

        if (isClosed) {
            throw new InterruptedIOException("Stream closed");
        }

        synchronized(rec) {
            int bytesToWrite = MAX_RECORD_SIZE;
            while (len > 0) {
                if (len < bytesToWrite) {
                    bytesToWrite = len;
                }

                rec.wrRec(Record.APP, b, off, bytesToWrite);
                len -= bytesToWrite;
                off += bytesToWrite;
            }
        }