private final Socket s;
public final String vhost;
public Connection(Socket s, String vhost) { super(s); this.vhost = vhost; this.s = s; }
+ protected Connection(InputStream i, OutputStream o) { super(i, o); vhost = null; s = null; }
public Socket getSocket() { return s; }
- public void close() { try{s.close();}catch(Exception e){throw new Stream.StreamException(e);} super.close(); }
+ public void close() { try{if (s!=null) s.close();}catch(Exception e){throw new Stream.StreamException(e);} super.close(); }
public int getLocalPort() { return s.getLocalPort(); }
public InetAddress getLocalAddress() { return ((InetSocketAddress)s.getLocalSocketAddress()).getAddress(); }
public int getRemotePort() { return s.getPort(); }
public static boolean loggingEnabled = "true".equals(System.getProperty("ibex.io.stream.logEnabled", "false"));
- public void transcribe(Stream out) {
+ public void transcribe(Stream out) { transcribe(out, false); }
+ public void transcribe(Stream out, boolean close) {
try {
byte[] buf = new byte[1024];
while(true) {
int numread = in.read(buf, 0, buf.length);
- if (numread==-1) return;
+ if (numread==-1) break;
out.out.write(buf, 0, numread);
}
+ if (close) out.close();
} catch (IOException ioe) { throw new StreamException(ioe); }
}