From: adam Date: Sun, 9 Jul 2006 06:33:28 +0000 (+0000) Subject: hacks to support resin-based connections X-Git-Url: http://git.megacz.com/?p=org.ibex.io.git;a=commitdiff_plain;h=3b2ea827949a6b21b360f43dc829e34650d9c203 hacks to support resin-based connections darcs-hash:20060709063328-5007d-767f8ff642288bdd0c2789316e31ac8ad1cbe1ad.gz --- diff --git a/src/org/ibex/io/Connection.java b/src/org/ibex/io/Connection.java index 5c8d148..5c8c0fd 100644 --- a/src/org/ibex/io/Connection.java +++ b/src/org/ibex/io/Connection.java @@ -13,8 +13,9 @@ public class Connection extends Stream { 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(); } diff --git a/src/org/ibex/io/Stream.java b/src/org/ibex/io/Stream.java index 558e0ca..0d6c169 100644 --- a/src/org/ibex/io/Stream.java +++ b/src/org/ibex/io/Stream.java @@ -27,14 +27,16 @@ public class Stream { 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); } }