snichol 2003/06/19 20:38:35
Modified: java/src/org/apache/soap/util/net Relay.java TcpTunnel.java TcpTunnelGui.java Log: Add TODO comment about finding workaround for TextArea#append bug in JDK later than 1.2.2 (on Win32, at least). Allow character encoding to assume for captured/displayed data to be specified on command line. If not specified, defaults to the previously hard-coded 8859_1. In my experience, UTF8 is much more common. Revision Changes Path 1.6 +29 -1 xml-soap/java/src/org/apache/soap/util/net/Relay.java Index: Relay.java =================================================================== RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/util/net/Relay.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Relay.java 11 Sep 2002 17:26:11 -0000 1.5 +++ Relay.java 20 Jun 2003 03:38:35 -0000 1.6 @@ -76,6 +76,7 @@ byte buf[] = new byte[BUFSIZ]; TextArea ta; OutputStream os; + String enc = "8859_1"; Relay (InputStream in, OutputStream out, TextArea ta) { this.in = in; @@ -89,6 +90,24 @@ this.os = os; } + Relay (InputStream in, OutputStream out, TextArea ta, String enc) { + this.in = in; + this.out = out; + this.ta = ta; + this.enc = enc; + } + + Relay (InputStream in, OutputStream out, OutputStream os, String enc) { + this.in = in; + this.out = out; + this.os = os; + this.enc = enc; + } + + public String getEncoding() { + return enc; + } + public void run () { int n; @@ -97,7 +116,12 @@ out.write (buf, 0, n); out.flush (); if (ta != null) { - ta.append (new String (buf, 0, n, "8859_1")); + // TODO: There is a "feature" of JDK later than 1.2.2 on Win32 + // that append does not quite correctly work. Specifically, + // getText delegates to the peer, which returns a string in + // which CR/LF are turned into just CR, so the length is off + // and text is actually inserted prior to the final characters. + ta.append (new String (buf, 0, n, enc)); } if (os != null) os.write(buf, 0, n); @@ -110,5 +134,9 @@ } catch (IOException e) { } } + } + + public void setEncoding(String enc) { + this.enc = enc; } } 1.5 +11 -4 xml-soap/java/src/org/apache/soap/util/net/TcpTunnel.java Index: TcpTunnel.java =================================================================== RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/util/net/TcpTunnel.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- TcpTunnel.java 11 Sep 2002 17:26:11 -0000 1.4 +++ TcpTunnel.java 20 Jun 2003 03:38:35 -0000 1.5 @@ -69,8 +69,8 @@ */ public class TcpTunnel { public static void main (String args[]) throws IOException { - if (args.length != 3) { - System.err.println ("Usage: java TcpTunnel listenport tunnelhost tunnelport"); + if (args.length != 3 && args.length != 4) { + System.err.println ("Usage: java TcpTunnel listenport tunnelhost tunnelport [encoding]"); System.exit (1); } @@ -78,6 +78,13 @@ String tunnelhost = args[1]; int tunnelport = Integer.parseInt (args[2]); + String enc; + if (args.length == 4) { + enc = args[3]; + } else { + enc = "8859_1"; + } + System.out.println ("TcpTunnel: ready to rock and roll on port " + listenport); @@ -94,8 +101,8 @@ tunnelhost); // relay the stuff thru - new Relay (sc.getInputStream(), st.getOutputStream(), System.out).start (); - new Relay (st.getInputStream(), sc.getOutputStream(), System.out).start (); + new Relay (sc.getInputStream(), st.getOutputStream(), System.out, enc).start (); + new Relay (st.getInputStream(), sc.getOutputStream(), System.out, enc).start (); // that's it .. they're off; now I go back to my stuff. } 1.4 +6 -4 xml-soap/java/src/org/apache/soap/util/net/TcpTunnelGui.java Index: TcpTunnelGui.java =================================================================== RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/util/net/TcpTunnelGui.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TcpTunnelGui.java 1 Sep 2000 03:53:06 -0000 1.3 +++ TcpTunnelGui.java 20 Jun 2003 03:38:35 -0000 1.4 @@ -164,9 +164,9 @@ } public static void main (String args[]) throws IOException { - if (args.length != 3) { + if (args.length != 3 && args.length != 4) { System.err.println ("Usage: java TcpTunnelGui listenport tunnelhost " + - "tunnelport"); + "tunnelport [encoding]"); System.exit (1); } @@ -176,6 +176,8 @@ final TcpTunnelGui ttg = new TcpTunnelGui (listenPort, tunnelHost, tunnelPort); + final String enc = (args.length == 4) ? args[3] : "8859_1"; + // create the server thread Thread server = new Thread () { public void run () { @@ -204,9 +206,9 @@ // relay the stuff thru new Relay (sc.getInputStream (), st.getOutputStream (), - ttg.getListenText ()).start (); + ttg.getListenText (), enc).start (); new Relay (st.getInputStream (), sc.getOutputStream (), - ttg.getTunnelText ()).start (); + ttg.getTunnelText (), enc).start (); // that's it .. they're off; now I go back to my stuff. } catch (Exception ee) {