1 /**
2 * AUTOHIT 2003
3 * Copyright Erich P Gatejen (c) 1989,1997,2003,2004
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Additional license information can be found in the documentation.
19 * @author Erich P Gatejen
20 */
21 package autohit.common.test;
22
23 import java.io.BufferedReader;
24 import java.io.BufferedWriter;
25 import java.io.FileWriter;
26 import java.io.InputStream;
27 import java.io.InputStreamReader;
28 import java.net.ServerSocket;
29 import java.net.Socket;
30
31 /**
32 * A simple CLI
33 *
34 * @author Erich P. Gatejen
35 * @version 1.0
36 * <i>Version History</i>
37 * <code>EPG - Initial - 25Apr03
38 *
39 */
40 public class HttpSink {
41
42 /**
43 * Globals
44 */
45
46 /**
47 * Help
48 */
49 static public void help() {
50 System.out.println("HttpSink outputfile");
51 System.out.println("outputfile = name of file to send data.");
52 }
53
54 /**
55 * main interface
56 */
57 public static void main(String[] args) {
58
59 // handle arguments
60 if (args.length < 1) {
61 System.out.println("No command");
62 help();
63 return;
64 }
65
66 try {
67
68 String outputfile = args[0];
69 BufferedWriter out = new BufferedWriter(new FileWriter(outputfile));
70 ServerSocket ss = new ServerSocket(80);
71 Socket s = ss.accept();
72 System.out.println("Accepted");
73
74 try {
75
76 InputStream ins = s.getInputStream();
77 BufferedReader in =
78 new BufferedReader(new InputStreamReader(ins));
79 String thang;
80
81 thang = in.readLine();
82 while (thang != null) {
83
84 out.write(thang);
85 thang = in.readLine();
86 }
87
88 } catch (Exception e) {
89 System.out.println("Exception in socket read");
90 e.printStackTrace();
91 }
92
93 out.close();
94
95 } catch (Exception e) {
96 e.printStackTrace();
97 }
98 }
99
100 }
|