KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > util > io > GenericDecoder


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

18 package org.apache.batik.util.io;
19
20 import java.io.BufferedReader JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.InputStream JavaDoc;
23 import java.io.InputStreamReader JavaDoc;
24 import java.io.Reader JavaDoc;
25
26 /**
27  * This class delegates to a reader the decoding of an input stream.
28  *
29  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
30  * @version $Id: GenericDecoder.java,v 1.4 2004/08/18 07:15:58 vhardy Exp $
31  */

32 public class GenericDecoder implements CharDecoder {
33
34     /**
35      * The reader used to decode the stream.
36      */

37     protected Reader JavaDoc reader;
38
39     /**
40      * Creates a new GenericDecoder.
41      * @param is The input stream to decode.
42      * @param enc The Java encoding name.
43      */

44     public GenericDecoder(InputStream JavaDoc is, String JavaDoc enc) throws IOException JavaDoc {
45         reader = new InputStreamReader JavaDoc(is, enc);
46         reader = new BufferedReader JavaDoc(reader);
47     }
48
49     /**
50      * Creates a new GenericDecoder.
51      * @param r The reader to use.
52      */

53     public GenericDecoder(Reader JavaDoc r) {
54         reader = r;
55         if (!(r instanceof BufferedReader JavaDoc)) {
56             reader = new BufferedReader JavaDoc(reader);
57         }
58     }
59
60     /**
61      * Reads the next character.
62      * @return a character or END_OF_STREAM.
63      */

64     public int readChar() throws IOException JavaDoc {
65         return reader.read();
66     }
67
68     /**
69      * Disposes the associated resources.
70      */

71     public void dispose() throws IOException JavaDoc {
72         reader.close();
73         reader = null;
74     }
75 }
76
Popular Tags