01: package vicazh.hyperpool.stream.net;
02:
03: import java.io.*;
04: import vicazh.hyperpool.Start;
05: import java.net.*;
06: import java.util.logging.*;
07: import vicazh.hyperpool.stream.*;
08:
09: public class Transfer {
10: public static void run(InputStream inputstream,
11: OutputStream outputstream) {
12: try {
13: int i;
14: while ((i = inputstream.read()) != -1) {
15: Thread.yield();
16: outputstream.write(i);
17: try {
18: i = inputstream.available();
19: } catch (IOException e) {
20: break;
21: }
22: if (i == 0)
23: outputstream.flush();
24: }
25: outputstream.flush();
26: } catch (SocketException e) {
27: } catch (SocketTimeoutException e) {
28: } catch (UnknownHostException e) {
29: } catch (BreakException e) {
30: } catch (Exception e) {
31: Start.logger.log(Level.SEVERE, e.getMessage(), e);
32: }
33: try {
34: inputstream.close();
35: } catch (Exception e) {
36: }
37: try {
38: outputstream.close();
39: } catch (Exception e) {
40: }
41: }
42:
43: public static void start(final InputStream inputstream,
44: final OutputStream outputstream) {
45: new Thread() {
46: public void run() {
47: Transfer.run(inputstream, outputstream);
48: }
49: }.start();
50: }
51:
52: public static void run(DatagramPacket packet,
53: OutputStream outputstream) {
54: Start.logger.finest("length:" + packet.getLength());
55: try {
56: for (int i = 0; i < packet.getLength(); i++) {
57: Thread.yield();
58: outputstream.write(packet.getData()[i]);
59: }
60: outputstream.flush();
61: } catch (SocketException e) {
62: } catch (SocketTimeoutException e) {
63: } catch (UnknownHostException e) {
64: } catch (BreakException e) {
65: } catch (Exception e) {
66: Start.logger.log(Level.SEVERE, e.getMessage(), e);
67: }
68: }
69: }
|