home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 September / PCWorld_2000-09_cd.bin / Komunik / sambar / _setup.1 / javaeng.jar / javax / servlet / ServletOutputStream.java < prev    next >
Text File  |  2000-04-03  |  6KB  |  263 lines

  1. /*
  2.  * ServletOutputStream.java -- OutputStream for writing servlet responses
  3.  *
  4.  * Copyright (c) 1998, 1999 by Free Software Foundation, Inc.
  5.  * Written by Paul Siegmann (pauls@euronet.nl)
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU Library General Public License as published
  9.  * by the Free Software Foundation, version 2. (see COPYING.LIB)
  10.  *
  11.  * This program 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
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software Foundation
  18.  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
  19.  */
  20.  
  21. package javax.servlet;
  22.  
  23. import java.io.IOException;
  24. import java.io.OutputStream;
  25.  
  26. /**
  27.  * Used to write output from a Servlet to the client.
  28.  * Servlet engines should provide a subclass of ServletOutputStream that
  29.  * implements <code>OutputStream.write(int)</code>.
  30.  * <p>
  31.  * Note that I (MJW) do not understand how the <code>print</code> methods work
  32.  * when the stream uses something else then a simple ASCII character encoding.
  33.  * It seems saver to use <code>ServletResponse.getWriter()</code> for all
  34.  * output that is not binary.
  35.  *
  36. #ifdef SERVLET_2_0
  37.  * @version Servlet API 2.0 
  38. #endif
  39. #ifdef SERVLET_2_1
  40.  * @version Servlet API 2.1
  41. #endif
  42. #ifdef SERVLET_2_2
  43.  * @version Servlet API 2.2
  44. #endif
  45.  * @since Servlet API 1.0
  46.  * @author Paul Siegmann (pauls@euronet.nl)
  47.  */
  48.  
  49. public abstract class ServletOutputStream
  50.     extends OutputStream 
  51. {
  52.     private static String STRING_TRUE = "true";
  53.     private static String STRING_FALSE = "false";
  54.     
  55.     protected ServletOutputStream() {
  56.     }
  57.  
  58.     /**
  59.      * Writes a String.
  60.      *
  61.      * @since Servlet API 1.0
  62.      *
  63.      * @param value the String to be printed
  64.      * @exception IOException if an I/O exception occurs
  65.      */
  66.     public void print(String value) throws IOException {
  67.         for(int i = 0; i < value.length(); i++) {
  68.             write((int)value.charAt(i));
  69.         }
  70.     }
  71.  
  72.  
  73.     /**
  74.      * Writes a boolean.
  75.      *
  76.      * @since Servlet API 1.0
  77.      *
  78.      * @param value the boolean to be printed
  79.      * @exception IOException if an I/O exception occurs
  80.      */
  81.     public void print(boolean value) throws IOException {
  82.         if(value) {
  83.             print(STRING_TRUE);
  84.         } else {
  85.             print(STRING_FALSE);
  86.         }
  87.     }
  88.  
  89.  
  90.     /**
  91.      * Writes a single char.
  92.      *
  93.      * @since Servlet API 1.0
  94.      *
  95.      * @param value the char to be printed
  96.      * @exception IOException if an I/O exception occurs
  97.      */
  98.     public void print(char value) throws IOException {
  99.         print(String.valueOf(value));
  100.     }
  101.  
  102.  
  103.     /**
  104.      * Writes an int.
  105.      *
  106.      * @since Servlet API 1.0
  107.      *
  108.      * @param value the int to be printed
  109.      * @exception IOException if an I/O exception occurs
  110.      */
  111.     public void print(int value) throws IOException {
  112.         print(String.valueOf(value));
  113.     }
  114.  
  115.  
  116.     /**
  117.      * Writes a long.
  118.      *
  119.      * @since Servlet API 1.0
  120.      *
  121.      * @param value the long to be printed
  122.      * @exception IOException if an I/O exception occurs
  123.      */
  124.     public void print(long value) throws IOException {
  125.         print(String.valueOf(value));
  126.     }
  127.  
  128.  
  129.     /**
  130.      * Writes a float.
  131.      *
  132.      * @since Servlet API 1.0
  133.      *
  134.      * @param value the float to be printed
  135.      * @exception IOException if an I/O exception occurs
  136.      */
  137.     public void print(float value) throws IOException {
  138.         print(String.valueOf(value));
  139.     }
  140.  
  141.  
  142.     /**
  143.      * Writes a double.
  144.      *
  145.      * @since Servlet API 1.0
  146.      *
  147.      * @param value the double to be printed
  148.      * @exception IOException if an I/O exception occurs
  149.      */
  150.     public void print(double value) throws IOException {
  151.         print(String.valueOf(value));
  152.     }
  153.  
  154.  
  155.     /**
  156.      * Writes a CRLF.
  157.      *
  158.      * @since Servlet API 1.0
  159.      *
  160.      * @exception IOException if an I/O exception occurs
  161.      */
  162.     public void println() throws IOException {
  163.         print("\r\n");
  164.     }
  165.  
  166.     /**
  167.      * Writes a String followed by a CRLF.
  168.      *
  169.      * @since Servlet API 1.0
  170.      *
  171.      * @param value the String to be printed
  172.      * @exception IOException if an I/O exception occurs
  173.      */
  174.     public void println(String value) throws IOException {
  175.         print(value);
  176.         println();
  177.     }
  178.  
  179.  
  180.     /**
  181.      * Writes a boolean followed by a CRLF.
  182.      *
  183.      * @since Servlet API 1.0
  184.      *
  185.      * @param value the boolean to be printed
  186.      * @exception IOException if an I/O exception occurs
  187.      */
  188.     public void println(boolean value) throws IOException {
  189.         print(value);
  190.         println();
  191.     }
  192.  
  193.  
  194.     /**
  195.      * Writes a single char followed by a CRLF.
  196.      *
  197.      * @since Servlet API 1.0
  198.      *
  199.      * @param value the char to be printed
  200.      * @exception IOException if an I/O exception occurs
  201.      */
  202.     public void println(char value) throws IOException {
  203.         print(value);
  204.         println();
  205.     }
  206.  
  207.  
  208.     /**
  209.      * Writes an int followed by a CRLF.
  210.      *
  211.      * @since Servlet API 1.0
  212.      *
  213.      * @param value the int to be printed
  214.      * @exception IOException if an I/O exception occurs
  215.      */
  216.     public void println(int value) throws IOException {
  217.         print(value);
  218.         println();
  219.     }
  220.  
  221.  
  222.     /**
  223.      * Writes a long followed by a CRLF.
  224.      *
  225.      * @since Servlet API 1.0
  226.      *
  227.      * @param value the long to be printed
  228.      * @exception IOException if an I/O exception occurs
  229.      */
  230.     public void println(long value) throws IOException {
  231.         print(value);
  232.         println();
  233.     }
  234.  
  235.  
  236.     /**
  237.      * Writes a float followed by a CRLF.
  238.      *
  239.      * @since Servlet API 1.0
  240.      *
  241.      * @param value the float to be printed
  242.      * @exception IOException if an I/O exception occurs
  243.      */
  244.     public void println(float value) throws IOException {
  245.         print(value);
  246.         println();
  247.     }
  248.  
  249.  
  250.     /**
  251.      * Writes a double followed by a CRLF.
  252.      *
  253.      * @since Servlet API 1.0
  254.      *
  255.      * @param value the double to be printed
  256.      * @exception IOException if an I/O exception occurs
  257.      */
  258.     public void println(double value) throws IOException {
  259.         print(value);
  260.         println();
  261.     }
  262. }
  263.