Methods Summary |
---|
private static java.lang.Class | SocketTimeoutExceptionClass()
try {
return Class.forName("java.net.SocketTimeoutException");
} catch (ClassNotFoundException e) {
return null;
}
|
public void | closeSocketAndStreams()
if(usingSecureSocket) {
if (null != sslOutputStream) {
OutputStream temp = sslOutputStream;
sslOutputStream = null;
try {
temp.close();
} catch (Exception ex) {
// ignored
}
}
if (null != sslInputStream) {
InputStream temp = sslInputStream;
sslInputStream = null;
try {
temp.close();
} catch (Exception ex) {
// ignored
}
}
if (null != sslSocket) {
Socket temp = sslSocket;
sslSocket = null;
try {
temp.close();
} catch (Exception ex) {
// ignored
}
}
}
if (null != outputStream) {
OutputStream temp = outputStream;
outputStream = null;
try {
temp.close();
} catch (Exception ex) {
// ignored
}
}
if (null != inputStream) {
InputStream temp = inputStream;
inputStream = null;
try {
temp.close();
} catch (Exception ex) {
// ignored
}
}
if (null != socket) {
Socket temp = socket;
socket = null;
try {
temp.close();
} catch (Exception ex) {
// ignored
}
}
|
public HttpConfiguration | getHttpConfiguration()
return config;
|
public java.io.InputStream | getInputStream()
if(usingSecureSocket) {
if (sslInputStream == null) {
sslInputStream = sslSocket.getInputStream();
}
return sslInputStream;
} else if(inputStream == null) {
inputStream = socket.getInputStream();
}
return inputStream;
|
public java.io.OutputStream | getOutputStream()
if(usingSecureSocket) {
if (sslOutputStream == null) {
sslOutputStream = sslSocket.getOutputStream();
}
return sslOutputStream;
} else if(outputStream == null) {
outputStream = socket.getOutputStream();
}
return outputStream;
|
public javax.net.ssl.SSLSocket | getSecureSocket(javax.net.ssl.SSLSocketFactory sslSocketFactory, javax.net.ssl.HostnameVerifier hostnameVerifier)
if(!usingSecureSocket) {
String hostName = config.getHostName();
int port = config.getHostPort();
// create the wrapper over connected socket
sslSocket = (SSLSocket) sslSocketFactory.createSocket(socket,
hostName, port, true);
sslSocket.setUseClientMode(true);
sslSocket.startHandshake();
if (!hostnameVerifier.verify(hostName, sslSocket.getSession())) {
throw new IOException(Messages.getString("luni.02", hostName)); //$NON-NLS-1$
}
usingSecureSocket = true;
}
return sslSocket;
|
java.net.Socket | getSocket()
return socket;
|
protected boolean | isEligibleForRecycling()Returns whether this connection is eligible to be recycled. This
is like {@link #isStale} except that it doesn't try to actually
perform any I/O.
return ! (socket.isClosed() || socket.isInputShutdown()
|| socket.isOutputShutdown());
|
public static boolean | isSocketTimeoutException(java.io.InterruptedIOException e)
/*
* This method has been copied from the Apache Jakarta Commons HttpClient project
* http://svn.apache.org/repos/asf/jakarta/commons/proper/httpclient/trunk/HttpClient/src/java/org/apache/commons/httpclient/HttpConnection.java r480424
*/
if (SOCKET_TIMEOUT_CLASS != null) {
return SOCKET_TIMEOUT_CLASS.isInstance(e);
} else {
return true;
}
|
protected boolean | isStale()
boolean isStale = true;
// BEGIN android-note
// The following line was expanded to check for input/output shutdown.
// END android-note
if (! (socket.isClosed() || socket.isInputShutdown()
|| socket.isOutputShutdown())) {
// the socket is open, but could still have been closed from the other end
isStale = false;
try {
if (inputStream.available() <= 0) {
int soTimeout = socket.getSoTimeout();
try {
socket.setSoTimeout(1);
inputStream.mark(1);
int byteRead = inputStream.read();
if (byteRead == -1) {
// again - if the socket is reporting all data read,
// probably stale
isStale = true;
} else {
inputStream.reset();
}
} finally {
socket.setSoTimeout(soTimeout);
}
}
} catch (InterruptedIOException e) {
if (!isSocketTimeoutException(e)) {
throw e;
}
// aha - the connection is NOT stale - continue on!
} catch (IOException e) {
// oops - the connection is stale, the read or soTimeout failed.
isStale = true;
}
}
return isStale;
|
public void | setSoTimeout(int readTimeout)
socket.setSoTimeout(readTimeout);
|