KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > configuration > EncodingInfo


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 /*
19  * This code has been borrowed from the Apache Xerces project. We're copying the code to
20  * keep from adding a dependency on Xerces in the Geronimo kernel.
21  */

22
23 package org.apache.geronimo.system.configuration;
24
25 import java.io.OutputStream JavaDoc;
26 import java.io.OutputStreamWriter JavaDoc;
27 import java.io.UnsupportedEncodingException JavaDoc;
28 import java.io.Writer JavaDoc;
29
30 /**
31  * This class represents an encoding.
32  *
33  * @version $Id: EncodingInfo.java 482336 2006-12-04 20:12:19Z kevan $
34  */

35 public class EncodingInfo {
36
37     String JavaDoc name;
38     String JavaDoc javaName;
39     int lastPrintable;
40
41     /**
42      * Creates new <code>EncodingInfo</code> instance.
43      */

44     public EncodingInfo(String JavaDoc mimeName, String JavaDoc javaName, int lastPrintable) {
45         this.name = mimeName;
46         this.javaName = javaName == null ? mimeName : javaName;
47         this.lastPrintable = lastPrintable;
48     }
49
50     /**
51      * Creates new <code>EncodingInfo</code> instance.
52      */

53     public EncodingInfo(String JavaDoc mimeName, int lastPrintable) {
54         this(mimeName, mimeName, lastPrintable);
55     }
56
57     /**
58      * Returns a MIME charset name of this encoding.
59      */

60     public String JavaDoc getName() {
61         return this.name;
62     }
63
64     /**
65      * Returns a writer for this encoding based on
66      * an output stream.
67      *
68      * @return A suitable writer
69      * @exception UnsupportedEncodingException There is no convertor
70      * to support this encoding
71      */

72     public Writer JavaDoc getWriter(OutputStream JavaDoc output)
73         throws UnsupportedEncodingException JavaDoc {
74         if (this.javaName == null)
75             return new OutputStreamWriter JavaDoc(output);
76         return new OutputStreamWriter JavaDoc(output, this.javaName);
77     }
78     /**
79      * Checks whether the specified character is printable or not.
80      *
81      * @param ch a code point (0-0x10ffff)
82      */

83     public boolean isPrintable(int ch) {
84         return ch <= this.lastPrintable;
85     }
86 }
87
Popular Tags