KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > util > MonitorRandomAccessContent


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.vfs.util;
17
18 import org.apache.commons.vfs.RandomAccessContent;
19
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22
23 /**
24  * An RandomAccessContent that provides end-of-stream monitoring.
25  *
26  * @author <a HREF="mailto:imario@apache.org">Mario Ivankovits</a>
27  */

28 public class MonitorRandomAccessContent implements RandomAccessContent
29 {
30     private final RandomAccessContent content;
31     private boolean finished;
32
33     public MonitorRandomAccessContent(final RandomAccessContent content)
34     {
35         this.content = content;
36     }
37
38     /**
39      * Called after this stream is closed. This implementation does nothing.
40      */

41     protected void onClose() throws IOException JavaDoc
42     {
43     }
44
45     /**
46      * Closes this content.
47      */

48     public void close() throws IOException JavaDoc
49     {
50         if (finished)
51         {
52             return;
53         }
54
55         // Close the output stream
56
IOException JavaDoc exc = null;
57         try
58         {
59             content.close();
60         }
61         catch (final IOException JavaDoc ioe)
62         {
63             exc = ioe;
64         }
65
66         // Notify of end of output
67
exc = null;
68         try
69         {
70             onClose();
71         }
72         catch (final IOException JavaDoc ioe)
73         {
74             exc = ioe;
75         }
76
77         finished = true;
78
79         if (exc != null)
80         {
81             throw exc;
82         }
83     }
84
85     public long getFilePointer() throws IOException JavaDoc
86     {
87         return content.getFilePointer();
88     }
89
90     public void seek(long pos) throws IOException JavaDoc
91     {
92         content.seek(pos);
93     }
94
95     public long length() throws IOException JavaDoc
96     {
97         return content.length();
98     }
99
100     public void write(int b) throws IOException JavaDoc
101     {
102         content.write(b);
103     }
104
105     public void write(byte[] b) throws IOException JavaDoc
106     {
107         content.write(b);
108     }
109
110     public void write(byte[] b, int off, int len) throws IOException JavaDoc
111     {
112         content.write(b, off, len);
113     }
114
115     public void writeBoolean(boolean v) throws IOException JavaDoc
116     {
117         content.writeBoolean(v);
118     }
119
120     public void writeByte(int v) throws IOException JavaDoc
121     {
122         content.writeByte(v);
123     }
124
125     public void writeShort(int v) throws IOException JavaDoc
126     {
127         content.writeShort(v);
128     }
129
130     public void writeChar(int v) throws IOException JavaDoc
131     {
132         content.writeChar(v);
133     }
134
135     public void writeInt(int v) throws IOException JavaDoc
136     {
137         content.writeInt(v);
138     }
139
140     public void writeLong(long v) throws IOException JavaDoc
141     {
142         content.writeLong(v);
143     }
144
145     public void writeFloat(float v) throws IOException JavaDoc
146     {
147         content.writeFloat(v);
148     }
149
150     public void writeDouble(double v) throws IOException JavaDoc
151     {
152         content.writeDouble(v);
153     }
154
155     public void writeBytes(String JavaDoc s) throws IOException JavaDoc
156     {
157         content.writeBytes(s);
158     }
159
160     public void writeChars(String JavaDoc s) throws IOException JavaDoc
161     {
162         content.writeChars(s);
163     }
164
165     public void writeUTF(String JavaDoc str) throws IOException JavaDoc
166     {
167         content.writeUTF(str);
168     }
169
170     public void readFully(byte[] b) throws IOException JavaDoc
171     {
172         content.readFully(b);
173     }
174
175     public void readFully(byte[] b, int off, int len) throws IOException JavaDoc
176     {
177         content.readFully(b, off, len);
178     }
179
180     public int skipBytes(int n) throws IOException JavaDoc
181     {
182         return content.skipBytes(n);
183     }
184
185     public boolean readBoolean() throws IOException JavaDoc
186     {
187         return content.readBoolean();
188     }
189
190     public byte readByte() throws IOException JavaDoc
191     {
192         return content.readByte();
193     }
194
195     public int readUnsignedByte() throws IOException JavaDoc
196     {
197         return content.readUnsignedByte();
198     }
199
200     public short readShort() throws IOException JavaDoc
201     {
202         return content.readShort();
203     }
204
205     public int readUnsignedShort() throws IOException JavaDoc
206     {
207         return content.readUnsignedShort();
208     }
209
210     public char readChar() throws IOException JavaDoc
211     {
212         return content.readChar();
213     }
214
215     public int readInt() throws IOException JavaDoc
216     {
217         return content.readInt();
218     }
219
220     public long readLong() throws IOException JavaDoc
221     {
222         return content.readLong();
223     }
224
225     public float readFloat() throws IOException JavaDoc
226     {
227         return content.readFloat();
228     }
229
230     public double readDouble() throws IOException JavaDoc
231     {
232         return content.readDouble();
233     }
234
235     public String JavaDoc readLine() throws IOException JavaDoc
236     {
237         return content.readLine();
238     }
239
240     public String JavaDoc readUTF() throws IOException JavaDoc
241     {
242         return content.readUTF();
243     }
244
245     public InputStream JavaDoc getInputStream() throws IOException JavaDoc
246     {
247         return content.getInputStream();
248     }
249 }
250
Popular Tags