KickJava   Java API By Example, From Geeks To Geeks.

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


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.IOException JavaDoc;
21 import java.io.Reader JavaDoc;
22
23 /**
24  * This class represents a reader which normalizes the line break: \n,
25  * \r, \r\n are replaced by \n. The methods of this reader are not
26  * synchronized. The input is buffered.
27  *
28  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
29  * @version $Id: NormalizingReader.java,v 1.4 2004/08/18 07:15:58 vhardy Exp $
30  */

31 public abstract class NormalizingReader extends Reader JavaDoc {
32
33     /**
34      * Read characters into a portion of an array.
35      * @param cbuf Destination buffer
36      * @param off Offset at which to start writing characters
37      * @param len Maximum number of characters to read
38      * @return The number of characters read, or -1 if the end of the
39      * stream has been reached
40      */

41     public int read(char cbuf[], int off, int len) throws IOException JavaDoc {
42         if (len == 0) {
43             return 0;
44         }
45
46         int c = read();
47         if (c == -1) {
48             return -1;
49         }
50         int result = 0;
51         do {
52             cbuf[result + off] = (char)c;
53             result++;
54             c = read();
55         } while (c != -1 && result < len);
56         return result;
57     }
58
59     /**
60      * Returns the current line in the stream.
61      */

62     public abstract int getLine();
63
64     /**
65      * Returns the current column in the stream.
66      */

67     public abstract int getColumn();
68
69 }
70
Popular Tags