home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / Main.bin / ServletInputStream.java < prev    next >
Text File  |  1998-04-21  |  3KB  |  78 lines

  1. /*
  2.  * @(#)ServletInputStream.java    1.12 97/07/15
  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.12, 07/15/97
  42.  */
  43. public abstract
  44. class ServletInputStream extends InputStream {
  45.  
  46.     /**
  47.      * The default constructor does no work.
  48.      */
  49.     protected ServletInputStream () { }
  50.  
  51.  
  52.     /**
  53.      * Starting at the specified offset, reads into the given array of
  54.      * bytes until all requested bytes have been read or a '\n' is
  55.      * encountered, in which case the '\n' is read into the array as well.
  56.      * @param b the buffer into which the data is read
  57.      * @param off the start offset of the data
  58.      * @param len the maximum number of bytes to read
  59.      * @return the actual number of bytes read, or -1 if the end of the
  60.      *         stream is reached
  61.      * @exception IOException if an I/O error has occurred
  62.      */
  63.     public int readLine(byte[] b, int off, int len) throws IOException {
  64.     if (len <= 0) {
  65.         return 0;
  66.     }
  67.     int count = 0, c;
  68.     while ((c = read()) != -1) {
  69.         b[off++] = (byte)c;
  70.         count++;
  71.         if (c == '\n') {
  72.         break;
  73.         }
  74.     }
  75.     return count > 0 ? count : -1;
  76.     }
  77. }
  78.