1 /* CRLFInputStream.java --
2 Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
41 import java
.io
.FilterInputStream
;
42 import java
.io
.InputStream
;
43 import java
.io
.IOException
;
46 * An input stream that filters out CR/LF pairs into LFs.
48 * @author Chris Burdess (dog@gnu.org)
50 public class CRLFInputStream
51 extends FilterInputStream
56 public static final int CR
= 13;
61 public static final int LF
= 10;
66 protected int buf
= -1;
69 * Buffer at time of mark.
71 protected int markBuf
= -1;
74 * Constructs a CR/LF input stream connected to the specified input
77 public CRLFInputStream(InputStream in
)
83 * Reads the next byte of data from this input stream.
84 * Returns -1 if the end of the stream has been reached.
85 * @exception IOException if an I/O error occurs
114 * Reads up to b.length bytes of data from this input stream into
116 * Returns -1 if the end of the stream has been reached.
117 * @exception IOException if an I/O error occurs
119 public int read(byte[] b
)
122 return read(b
, 0, b
.length
);
126 * Reads up to len bytes of data from this input stream into an
127 * array of bytes, starting at the specified offset.
128 * Returns -1 if the end of the stream has been reached.
129 * @exception IOException if an I/O error occurs
131 public int read(byte[] b
, int off
, int len
)
137 // Push buf onto start of byte array
144 int l
= super.read(b
, off
, len
);
145 l
= removeCRLF(b
, off
- shift
, l
);
150 * Indicates whether this stream supports the mark and reset methods.
152 public boolean markSupported()
154 return in
.markSupported();
158 * Marks the current position in this stream.
160 public void mark(int readlimit
)
167 * Repositions this stream to the position at the time the mark method was
177 private int removeCRLF(byte[] b
, int off
, int len
)
180 for (int i
= off
; i
< end
; i
++)
186 // This is the last byte, impossible to determine whether CRLF
190 else if (b
[i
+ 1] == LF
)
194 for (int j
= i
; j
< end
; j
++)