[Japi-cvs] SF.net SVN: japi: [514] libs/net/trunk/src
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2007-07-07 09:49:55
|
Revision: 514 http://svn.sourceforge.net/japi/?rev=514&view=rev Author: christianhujer Date: 2007-07-07 02:49:53 -0700 (Sat, 07 Jul 2007) Log Message: ----------- Moved Forwarder to libs-net. Modified Paths: -------------- libs/net/trunk/libs-net.iml Added Paths: ----------- libs/net/trunk/src/net/ libs/net/trunk/src/net/sf/ libs/net/trunk/src/net/sf/japi/ libs/net/trunk/src/net/sf/japi/net/ libs/net/trunk/src/net/sf/japi/net/Forwarder.java Removed Paths: ------------- historic/trunk/src/app/net/sf/japi/net/Forwarder.java Deleted: historic/trunk/src/app/net/sf/japi/net/Forwarder.java =================================================================== --- historic/trunk/src/app/net/sf/japi/net/Forwarder.java 2007-07-07 09:48:21 UTC (rev 513) +++ historic/trunk/src/app/net/sf/japi/net/Forwarder.java 2007-07-07 09:49:53 UTC (rev 514) @@ -1,94 +0,0 @@ -/* - * JAPI - (Yet another (hopefully) useful) Java API - * - * Copyright (C) 2006 Christian Hujer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -package net.sf.japi.net; - -import java.net.ServerSocket; -import java.net.Socket; -import java.io.IOException; -import net.sf.japi.io.Copier; - -/** This class forwards incoming TCP connections to another host and port. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - */ -public class Forwarder implements Runnable { - - /** Main program. - * @param args command line arguments (currently ignored) - */ - public static void main(final String... args) throws IOException { - ServerSocket serverSocket = null; - serverSocket = new ServerSocket(Integer.parseInt(args[0])); - while (true) { - final Socket server = serverSocket.accept(); - Socket client = null; - try { - client = new Socket(args[1], Integer.parseInt(args[2])); - new Forwarder(client, server).start(); - } catch (final IOException e) { - //noinspection CatchGenericClass,OverlyBroadCatchBlock - try { server.close(); } catch (final Exception ignore) { /* ignore */ } - //noinspection CatchGenericClass,OverlyBroadCatchBlock - try { client.close(); } catch (final Exception ignore) { /* ignore */ } - } - } - } - - /** First socket. */ - private final Socket s1; - - /** Second socket. */ - private final Socket s2; - - /** Create a new Forwarder. - * @param s1 first socket - * @param s2 second socket - */ - public Forwarder(final Socket s1, final Socket s2) { - this.s1 = s1; - this.s2 = s2; - } - - /** Start the forwarder. */ - public void start() { - new Thread(this).start(); - } - - /** {@inheritDoc} */ - public void run() { - try { - final Thread c1 = new Copier(s1.getInputStream(), s2.getOutputStream()).start(); - final Thread c2 = new Copier(s2.getInputStream(), s1.getOutputStream()).start(); - c1.join(); - c2.join(); - } catch (final InterruptedException ignore) { - /* ignore */ - } catch (final IOException e) { - e.printStackTrace(); //TODO - } finally { - //noinspection CatchGenericClass,OverlyBroadCatchBlock - try { s1.close(); } catch (final Exception ignore) { /* ignore */ } - //noinspection CatchGenericClass,OverlyBroadCatchBlock - try { s2.close(); } catch (final Exception ignore) { /* ignore */ } - } - } - -} // class Forwarder Modified: libs/net/trunk/libs-net.iml =================================================================== --- libs/net/trunk/libs-net.iml 2007-07-07 09:48:21 UTC (rev 513) +++ libs/net/trunk/libs-net.iml 2007-07-07 09:49:53 UTC (rev 514) @@ -8,6 +8,7 @@ </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="libs-io" /> <orderEntryProperties /> </component> <component name="copyright"> Added: libs/net/trunk/src/net/sf/japi/net/Forwarder.java =================================================================== --- libs/net/trunk/src/net/sf/japi/net/Forwarder.java (rev 0) +++ libs/net/trunk/src/net/sf/japi/net/Forwarder.java 2007-07-07 09:49:53 UTC (rev 514) @@ -0,0 +1,94 @@ +/* + * JAPI - (Yet another (hopefully) useful) Java API + * + * Copyright (C) 2006 Christian Hujer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +package net.sf.japi.net; + +import java.net.ServerSocket; +import java.net.Socket; +import java.io.IOException; +import net.sf.japi.io.Copier; + +/** This class forwards incoming TCP connections to another host and port. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class Forwarder implements Runnable { + + /** Main program. + * @param args command line arguments (currently ignored) + */ + public static void main(final String... args) throws IOException { + ServerSocket serverSocket = null; + serverSocket = new ServerSocket(Integer.parseInt(args[0])); + while (true) { + final Socket server = serverSocket.accept(); + Socket client = null; + try { + client = new Socket(args[1], Integer.parseInt(args[2])); + new Forwarder(client, server).start(); + } catch (final IOException e) { + //noinspection CatchGenericClass,OverlyBroadCatchBlock + try { server.close(); } catch (final Exception ignore) { /* ignore */ } + //noinspection CatchGenericClass,OverlyBroadCatchBlock + try { client.close(); } catch (final Exception ignore) { /* ignore */ } + } + } + } + + /** First socket. */ + private final Socket s1; + + /** Second socket. */ + private final Socket s2; + + /** Create a new Forwarder. + * @param s1 first socket + * @param s2 second socket + */ + public Forwarder(final Socket s1, final Socket s2) { + this.s1 = s1; + this.s2 = s2; + } + + /** Start the forwarder. */ + public void start() { + new Thread(this).start(); + } + + /** {@inheritDoc} */ + public void run() { + try { + final Thread c1 = new Copier(s1.getInputStream(), s2.getOutputStream()).start(); + final Thread c2 = new Copier(s2.getInputStream(), s1.getOutputStream()).start(); + c1.join(); + c2.join(); + } catch (final InterruptedException ignore) { + /* ignore */ + } catch (final IOException e) { + e.printStackTrace(); //TODO + } finally { + //noinspection CatchGenericClass,OverlyBroadCatchBlock + try { s1.close(); } catch (final Exception ignore) { /* ignore */ } + //noinspection CatchGenericClass,OverlyBroadCatchBlock + try { s2.close(); } catch (final Exception ignore) { /* ignore */ } + } + } + +} // class Forwarder Property changes on: libs/net/trunk/src/net/sf/japi/net/Forwarder.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |