JPProxy update

This commit is contained in:
Jindra Petk
2011-07-16 12:40:49 +02:00
parent 991b08d8bc
commit 49a8fd03bf
24 changed files with 2419 additions and 1577 deletions

View File

@@ -6,28 +6,25 @@ import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
import java.security.KeyStore;
import java.security.KeyStoreException;
/**
* Create a TCP connection from a Socket or hostname/port
* with buffered IO.
*
* @author Mark Boyns
* @see java.net.Socket
*/
class Connection {
class Connection
{
Socket socket = null;
InputStream in = null;
OutputStream out = null;
/**
* Create a Connection from a Socket.
*
* @param socket a socket
*/
Connection(Socket socket) throws IOException {
this.socket = socket;
in = socket.getInputStream();
out = socket.getOutputStream();
Connection(Socket socket) throws IOException
{
this.socket = socket;
in = socket.getInputStream();
out = socket.getOutputStream();
}
/**
@@ -36,67 +33,82 @@ class Connection {
* @param host remote hostname
* @param port remote port
*/
Connection(String host, int port) throws IOException {
this(new Socket(host, port));
Connection(String host, int port) throws IOException
{
this(new Socket(InetAddress.getByName(host), port));
}
Connection() {
Connection()
{
}
/**
* Return the input stream.
*/
InputStream getInputStream() {
return in;
InputStream getInputStream()
{
return in;
}
/**
* Return the output stream.
*/
OutputStream getOutputStream() {
return out;
OutputStream getOutputStream()
{
return out;
}
void setInputStream(InputStream in) {
this.in = in;
void setInputStream(InputStream in)
{
this.in = in;
}
void setOutputStream(OutputStream out) {
this.out = out;
void setOutputStream(OutputStream out)
{
this.out = out;
}
/**
* Close the connection.
*/
void close() {
if (socket != null) {
try {
socket.close();
}
catch (IOException e) {
System.out.println("Connection: " + e);
}
}
void close()
{
if (socket != null)
{
try
{
socket.close();
}
catch (IOException e)
{
System.out.println("Connection: " + e);
}
}
}
public Socket getSocket() {
return socket;
public Socket getSocket()
{
return socket;
}
public InetAddress getInetAddress() {
return socket.getInetAddress();
public InetAddress getInetAddress()
{
return socket.getInetAddress();
}
public int getPort()
{
return socket.getPort();
}
public int getPort() {
return socket.getPort();
}
public String toString() {
return getInetAddress().getHostAddress() + ":" + getPort();
public String toString()
{
return getInetAddress().getHostAddress() + ":" + getPort();
}
public void setTimeout(int timeout)
throws SocketException {
socket.setSoTimeout(timeout);
throws SocketException
{
socket.setSoTimeout(timeout);
}
}
}