home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / binaries / Windows / jsdk / src / javax / servlet / ServletInputStream.java < prev    next >
Encoding:
Java Source  |  1997-07-18  |  2.5 KB  |  79 lines

  1. /*
  2.  * @(#)ServletInputStream.java    1.11 97/05/22
  3.  * 
  4.  * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.0
  20.  */
  21.  
  22. package javax.servlet;
  23.  
  24. import java.io.InputStream;
  25. import java.io.IOException;
  26.  
  27. /**
  28.  * 
  29.  * An input stream for reading servlet requests, it provides an
  30.  * efficient readLine method.  This is an abstract class, to be
  31.  * implemented by a network services writer.  For some application
  32.  * protocols, such as the HTTP POST and PUT methods, servlet writers
  33.  * use the input stream to get data from clients.  They access the
  34.  * input stream via the ServletRequest's getInputStream method,
  35.  * available from within the servlet's service method.  Subclasses of
  36.  * ServletInputStream must provide an implementation of the read()
  37.  * method.
  38.  *
  39.  * @see java.io.InputStream#read() 
  40.  *
  41.  * @version    1.11, 05/22/97
  42.  * @author David Connelly
  43.  */
  44. public abstract
  45. class ServletInputStream extends InputStream {
  46.  
  47.     /**
  48.      * The default constructor does no work.
  49.      */
  50.     protected ServletInputStream () { }
  51.  
  52.  
  53.     /**
  54.      * Starting at the specified offset, reads into the given array of
  55.      * bytes until all requested bytes have been read or a '\n' is
  56.      * encountered, in which case the '\n' is read into the array as well.
  57.      * @param b the buffer into which the data is read
  58.      * @param off the start offset of the data
  59.      * @param len the maximum number of bytes to read
  60.      * @return the actual number of bytes read, or -1 if the end of the
  61.      *         stream is reached
  62.      * @exception IOException if an I/O error has occurred
  63.      */
  64.     public int readLine(byte[] b, int off, int len) throws IOException {
  65.     if (len <= 0) {
  66.         return 0;
  67.     }
  68.     int count = 0, c;
  69.     while ((c = read()) != -1) {
  70.         b[off++] = (byte)c;
  71.         count++;
  72.         if (c == '\n') {
  73.         break;
  74.         }
  75.     }
  76.     return count > 0 ? count : -1;
  77.     }
  78. }
  79.