01: /*
02:
03: Licensed to the Apache Software Foundation (ASF) under one or more
04: contributor license agreements. See the NOTICE file distributed with
05: this work for additional information regarding copyright ownership.
06: The ASF licenses this file to You under the Apache License, Version 2.0
07: (the "License"); you may not use this file except in compliance with
08: the License. You may obtain a copy of the License at
09:
10: http://www.apache.org/licenses/LICENSE-2.0
11:
12: Unless required by applicable law or agreed to in writing, software
13: distributed under the License is distributed on an "AS IS" BASIS,
14: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: See the License for the specific language governing permissions and
16: limitations under the License.
17:
18: */
19: package org.apache.batik.util.io;
20:
21: import java.io.IOException;
22: import java.io.Reader;
23:
24: /**
25: * This class represents a reader which normalizes the line break: \n,
26: * \r, \r\n are replaced by \n. The methods of this reader are not
27: * synchronized. The input is buffered.
28: *
29: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
30: * @version $Id: NormalizingReader.java 478169 2006-11-22 14:23:24Z dvholten $
31: */
32: public abstract class NormalizingReader extends Reader {
33:
34: /**
35: * Read characters into a portion of an array.
36: * @param cbuf Destination buffer
37: * @param off Offset at which to start writing characters
38: * @param len Maximum number of characters to read
39: * @return The number of characters read, or -1 if the end of the
40: * stream has been reached
41: */
42: public int read(char[] cbuf, int off, int len) throws IOException {
43: if (len == 0) {
44: return 0;
45: }
46:
47: int c = read();
48: if (c == -1) {
49: return -1;
50: }
51: int result = 0;
52: do {
53: cbuf[result + off] = (char) c;
54: result++;
55: c = read();
56: } while (c != -1 && result < len);
57: return result;
58: }
59:
60: /**
61: * Returns the current line in the stream.
62: */
63: public abstract int getLine();
64:
65: /**
66: * Returns the current column in the stream.
67: */
68: public abstract int getColumn();
69:
70: }
|