1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.backsource.utils.io;
19 import java.io.*;
20 /***
21 * A simple IO helper that has bean arround some time.
22 *
23 * @author Peter Antman
24 * @version
25 */
26
27 public class IOHelper {
28 /***
29 * Totally static class.
30 */
31 private IOHelper() {
32
33 }
34
35 /***
36 * Connect an is and os, when the method returns the stuff will have
37 * been written to the os, be it a file or a byte[]. Its is up to the
38 * user to close() the streams, the os will have been flushed
39 */
40 public static void connect(InputStream is, OutputStream os) throws IOException {
41 byte[] buff = new byte[1024];
42 for(;;) {
43 int size = is.read( buff );
44 if (size == -1 ) {
45 break;
46 }
47 os.write(buff, 0, size);
48 }
49 os.flush();
50 }
51
52 /***
53 * Connect an reader and writer, when the method returns the stuff will have
54 * been written to the writer, be it a file or a char[]. Its is up to the
55 * user to close() the reader and writer, the writer will have been flushed
56 */
57 public static void connect(Reader reader, Writer writer) throws IOException {
58 char[] buff = new char[1024];
59 for(;;) {
60 int size = reader.read( buff );
61 if (size == -1 ) {
62 break;
63 }
64 writer.write(buff, 0, size);
65 }
66 writer.flush();
67 }
68
69
70 }