01: /*
02: * Copyright 2003-2006 Rick Knowles <winstone-devel at lists sourceforge net>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: */
07: package javax.servlet;
08:
09: /**
10: * Provides the base class for servlet request streams.
11: *
12: * @author <a href="mailto:rick_knowles@hotmail.com">Rick Knowles</a>
13: */
14: public abstract class ServletInputStream extends java.io.InputStream {
15: protected ServletInputStream() {
16: super ();
17: }
18:
19: public int readLine(byte[] b, int off, int len)
20: throws java.io.IOException {
21: if (b == null)
22: throw new IllegalArgumentException("null buffer");
23: else if (len + off > b.length)
24: throw new IllegalArgumentException(
25: "offset + length is greater than buffer length");
26:
27: int positionCounter = 0;
28: int charRead = read();
29: while (charRead != -1) {
30: b[off + positionCounter++] = (byte) charRead;
31: if ((charRead == '\n') || (off + positionCounter == len)) {
32: return positionCounter;
33: } else {
34: charRead = read();
35: }
36: }
37: return -1;
38: }
39:
40: }
|