KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > invoice > applications > ObsInputStream


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2003 France Telecom R&D - INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: jorm-team@objectweb.org
21  *
22  */

23
24 package examples.invoice.applications;
25
26 import java.io.InputStream JavaDoc;
27 import java.io.OutputStream JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.File JavaDoc;
30 import java.io.FileInputStream JavaDoc;
31 import java.io.FileNotFoundException JavaDoc;
32
33 /**
34  * Observes an InputStream and redirect all read data to the standard
35  * OutputStream (System.out).
36  * @author P. Dechamboux
37  */

38 class ObsInputStream extends InputStream JavaDoc {
39     private InputStream JavaDoc in;
40
41     public static InputStream JavaDoc observes(String JavaDoc cmdfile) {
42         try {
43             return new ObsInputStream(new FileInputStream JavaDoc(new File JavaDoc(cmdfile)));
44         } catch (FileNotFoundException JavaDoc e) {
45             System.err.println("The commands file cannot be accessed!");
46             System.exit(-1);
47             return null;
48         }
49     }
50
51     public ObsInputStream(InputStream JavaDoc in) {
52         this.in = in;
53     }
54
55     public int available() throws IOException JavaDoc {
56         return in.available();
57     }
58
59     public void close() throws IOException JavaDoc {
60         in.close();
61     }
62
63     public void mark(int readlimit) {
64         in.mark(readlimit);
65     }
66
67     public boolean markSupported() {
68         return in.markSupported();
69     }
70
71     public int read() throws IOException JavaDoc {
72         int c;
73         c = in.read();
74         System.out.write(c);
75         return c;
76     }
77
78     public int read(byte[] b) throws IOException JavaDoc {
79         int size = in.read(b);
80         System.out.write(b, 0, size);
81         return size;
82     }
83
84     public int read(byte[] b, int off, int len) throws IOException JavaDoc {
85         int size = in.read(b, off, len);
86         System.out.write(b, off, size);
87         return size;
88     }
89
90     public void reset() throws IOException JavaDoc {
91         in.reset();
92     }
93
94     public long skip(long n) throws IOException JavaDoc {
95         return in.skip(n);
96     }
97 }
98
Popular Tags