public class

Protocol

extends Object
java.lang.Object
   ↳ com.google.code.com.sun.mail.iap.Protocol
Known Direct Subclasses

Class Overview

General protocol handling code for IMAP-like protocols.

The Protocol object is multithread safe.

Summary

Fields
private static final byte[] CRLF
private boolean connected
protected boolean debug
private final Vector handlers
protected String host
private ResponseInputStream input
private String localHostName
protected PrintStream out
private DataOutputStream output
protected String prefix
protected Properties props
protected boolean quote
private Socket socket
private int tagCounter
private long timestamp
private TraceInputStream traceInput
private TraceOutputStream traceOutput
Public Constructors
Protocol(String host, int port, boolean debug, PrintStream out, Properties props, String prefix, boolean isSSL)
Constructor.
Protocol(InputStream in, OutputStream out, boolean debug)
Constructor for debugging.
Public Methods
void addResponseHandler(ResponseHandler h)
Adds a response handler.
synchronized Response[] command(String command, Argument args)
Send a command to the server.
long getTimestamp()
Returns the timestamp.
void handleResult(Response response)
Convenience routine to handle OK, NO, BAD and BYE responses.
void notifyResponseHandlers(Response[] responses)
Notify response handlers
Response readResponse()
void removeResponseHandler(ResponseHandler h)
Removed the specified response handler.
void simpleCommand(String cmd, Argument args)
Convenience routine to handle simple IAP commands that do not have responses specific to that command.
synchronized void startTLS(String cmd)
Start TLS on the current connection.
String writeCommand(String command, Argument args)
Protected Methods
synchronized void disconnect()
Disconnect.
void finalize()
Finalizer.
ResponseInputStream getInputStream()
Return the Protocol's InputStream.
synchronized String getLocalHost()
Get the name of the local host.
OutputStream getOutputStream()
Return the Protocol's OutputStream
ByteArray getResponseBuffer()
Return a buffer to be used to read a response.
void processGreeting(Response r)
synchronized boolean supportsNonSyncLiterals()
Returns whether this Protocol supports non-synchronizing literals Default is false.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

private static final byte[] CRLF

private boolean connected

protected boolean debug

private final Vector handlers

protected String host

private ResponseInputStream input

private String localHostName

protected PrintStream out

private DataOutputStream output

protected String prefix

protected Properties props

protected boolean quote

private Socket socket

private int tagCounter

private long timestamp

private TraceInputStream traceInput

private TraceOutputStream traceOutput

Public Constructors

public Protocol (String host, int port, boolean debug, PrintStream out, Properties props, String prefix, boolean isSSL)

Constructor.

Opens a connection to the given host at given port.

Parameters
host Host to connect to
port Portnumber to connect to
debug Debug mode
out Debug output stream
props Properties object used by this protocol
prefix Prefix to prepend to property keys
isSSL
Throws
IOException
ProtocolException

public Protocol (InputStream in, OutputStream out, boolean debug)

Constructor for debugging.

Parameters
in
out
debug
Throws
IOException

Public Methods

public void addResponseHandler (ResponseHandler h)

Adds a response handler.

Parameters
h

public synchronized Response[] command (String command, Argument args)

Send a command to the server. Collect all responses until either the corresponding command completion response or a BYE response (indicating server failure). Return all the collected responses.

Parameters
command The command
args The arguments
Returns
  • array of Response objects returned by the server

public long getTimestamp ()

Returns the timestamp.

public void handleResult (Response response)

Convenience routine to handle OK, NO, BAD and BYE responses.

Parameters
response

public void notifyResponseHandlers (Response[] responses)

Notify response handlers

Parameters
responses

public Response readResponse ()

Throws
IOException
ProtocolException

public void removeResponseHandler (ResponseHandler h)

Removed the specified response handler.

Parameters
h

public void simpleCommand (String cmd, Argument args)

Convenience routine to handle simple IAP commands that do not have responses specific to that command.

Parameters
cmd
args

public synchronized void startTLS (String cmd)

Start TLS on the current connection. cmd is the command to issue to start TLS negotiation. If the command succeeds, we begin TLS negotiation.

Parameters
cmd
Throws
IOException
ProtocolException

public String writeCommand (String command, Argument args)

Parameters
command
args
Throws
IOException
ProtocolException

Protected Methods

protected synchronized void disconnect ()

Disconnect.

protected void finalize ()

Finalizer.

Throws
Throwable

protected ResponseInputStream getInputStream ()

Return the Protocol's InputStream.

protected synchronized String getLocalHost ()

Get the name of the local host. The property .localhost overrides .localaddress, which overrides what InetAddress would tell us.

protected OutputStream getOutputStream ()

Return the Protocol's OutputStream

protected ByteArray getResponseBuffer ()

Return a buffer to be used to read a response. The default implementation returns null, which causes a new buffer to be allocated for every response.

protected void processGreeting (Response r)

Parameters
r

protected synchronized boolean supportsNonSyncLiterals ()

Returns whether this Protocol supports non-synchronizing literals Default is false. Subclasses should override this if required