KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tester > UpperCaseReader


1 /*
2  * Copyright 1999, 2000, 2001 ,2004 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
17 package org.apache.tester;
18
19
20 import java.io.*;
21 import java.util.*;
22 import javax.servlet.*;
23 import javax.servlet.http.*;
24
25
26 /**
27  * BufferedReader that converts all characters to upper case.
28  *
29  * @author Craig R. McClanahan
30  * @version $Revision: 1.2 $ $Date: 2004/02/27 14:58:57 $
31  */

32
33 public class UpperCaseReader extends BufferedReader {
34
35     public UpperCaseReader(BufferedReader reader) throws IOException {
36         super(reader);
37     }
38
39     public int read() throws IOException {
40         int c = super.read();
41         if (c < 0)
42             return (c);
43         char ch = (char) c;
44         if (Character.isLowerCase(ch))
45             ch = Character.toUpperCase(ch);
46         return ((int) ch);
47     }
48
49     public int read(char buf[], int off, int len) throws IOException {
50         int n = 0;
51         for (int i = off; i < (off + len); i++) {
52             int c = super.read();
53             if (c < 0) {
54                 if (n == 0)
55                     return (-1);
56                 break;
57             }
58             char ch = (char) c;
59             if (Character.isLowerCase(ch))
60                 ch = Character.toUpperCase(ch);
61             buf[i] = ch;
62             n++;
63         }
64         return (n);
65     }
66
67     public int read(char buf[]) throws IOException {
68         return (read(buf, 0, buf.length));
69     }
70
71 }
72
73
Popular Tags