/**
 * Provides an output stream for sending binary data to the
 * client. A <code>ServletOutputStream</code> object is normally retrieved
 * via the {@link ServletResponse#getOutputStream} method.
 *
 * <p>This is an abstract class that the servlet container implements.
 * Subclasses of this class
 * must implement the <code>java.io.OutputStream.write(int)</code>
 * method.
 *
 *
 * @author 	Various
 * @version 	$Version$
 *
 * @see 	ServletResponse
 *
 */
//提供一个输出流来发送二进制数据给客户端,Servlet容器会实现这个类,这个类的子类一定要实现java.io.OutputStream.write(int)方法
public abstract class ServletOutputStream extends OutputStream {

    private static final String LSTRING_FILE = "javax.servlet.LocalStrings";
    private static ResourceBundle lStrings =
	ResourceBundle.getBundle(LSTRING_FILE);
    /**
     * Does nothing, because this is an abstract class.
     */
    //抽象类的构造函数
    protected ServletOutputStream() { }
    /**
     * Writes a <code>String</code> to the client,
     * without a carriage return-line feed (CRLF)
     * character at the end.
     * @param s			the <code>String</code> to send to the client
     * @exception IOException 	if an input or output exception occurred
     */
    //向客户端写string
    public void print(String s) throws IOException {
    	if (s==null) s="null";
    	int len = s.length();
    	for (int i = 0; i < len; i++) {
    		char c = s.charAt (i);
    		// XXX NOTE:  This is clearly incorrect for many strings,
    		// but is the only consistent approach within the current
    		// servlet framework.  It must suffice until servlet output
    		// streams properly encode their output.
    		//
    		if ((c & 0xff00) != 0) {	// high order byte must be zero
    			String errMsg = lStrings.getString("err.not_iso8859_1");
    			Object[] errArgs = new Object[1];
    			errArgs[0] = new Character(c);
    			errMsg = MessageFormat.format(errMsg, errArgs);
    			throw new CharConversionException(errMsg);
    		}
    		write (c);
    	}
    }
    /**
     * Writes a <code>boolean</code> value to the client,
     * with no carriage return-line feed (CRLF)
     * character at the end.
     * @param b			the <code>boolean</code> value
     *				to send to the client
     * @exception IOException 	if an input or output exception occurred
     */
    //向客户端写boolean
    public void print(boolean b) throws IOException {
    	String msg;
    	if (b) {
	    msg = lStrings.getString("value.true");
    	} else {
	    msg = lStrings.getString("value.false");
    	}
    	print(msg);
    }
    /**
     * Writes a character to the client,
     * with no carriage return-line feed (CRLF)
     * at the end.
     * @param c			the character to send to the client
     * @exception IOException 	if an input or output exception occurred
     */
    //向客户端写字符
    public void print(char c) throws IOException {
    	print(String.valueOf(c));
    }
    /**
     * Writes an int to the client,
     * with no carriage return-line feed (CRLF)
     * at the end.
     * @param i			the int to send to the client
     * @exception IOException 	if an input or output exception occurred
     */
    //写int
    public void print(int i) throws IOException {
    	print(String.valueOf(i));
    }
    /**
     * Writes a <code>long</code> value to the client,
     * with no carriage return-line feed (CRLF) at the end.
     * @param l			the <code>long</code> value
     *				to send to the client
     * @exception IOException 	if an input or output exception
     *				occurred
     */
    //写long
    public void print(long l) throws IOException {
    	print(String.valueOf(l));
    }
    /**
     * Writes a <code>float</code> value to the client,
     * with no carriage return-line feed (CRLF) at the end.
     * @param f			the <code>float</code> value
     *				to send to the client
     * @exception IOException	if an input or output exception occurred
     */
    //写float
    public void print(float f) throws IOException {
    	print(String.valueOf(f));
    }
    /**
     * Writes a <code>double</code> value to the client,
     * with no carriage return-line feed (CRLF) at the end.
     * @param d			the <code>double</code> value
     *				to send to the client
     * @exception IOException 	if an input or output exception occurred
     */
    //写double
    public void print(double d) throws IOException {
    	print(String.valueOf(d));
    }
    /**
     * Writes a carriage return-line feed (CRLF)
     * to the client.
     * @exception IOException 	if an input or output exception occurred
     */
    //换行
    public void println() throws IOException {
    	print("\r\n");
    }
    /**
     * Writes a <code>String</code> to the client,
     * followed by a carriage return-line feed (CRLF).
     * @param s			the <code>String</code> to write to the client
     * @exception IOException 	if an input or output exception occurred
     */
   //写string并回车
    public void println(String s) throws IOException {
    	print(s);
    	println();
    }
    /**
     * Writes a <code>boolean</code> value to the client,
     * followed by a
     * carriage return-line feed (CRLF).
     * @param b			the <code>boolean</code> value
     *				to write to the client
     * @exception IOException 	if an input or output exception occurred
     */
    //boolean 回车
    public void println(boolean b) throws IOException {
    	print(b);
    	println();
    }
    /**
     * Writes a character to the client, followed by a carriage
     * return-line feed (CRLF).
     * @param c			the character to write to the client
     * @exception IOException 	if an input or output exception occurred
     */
    //字符 回车
    public void println(char c) throws IOException {
    	print(c);
    	println();
    }
    /**
     * Writes an int to the client, followed by a
     * carriage return-line feed (CRLF) character.
     * @param i			the int to write to the client
     * @exception IOException 	if an input or output exception occurred
     */
    //int 回车
    public void println(int i) throws IOException {
    	print(i);
    	println();
    }
    /**
     * Writes a <code>long</code> value to the client, followed by a
     * carriage return-line feed (CRLF).
     * @param l			the <code>long</code> value to write to the client
     * @exception IOException 	if an input or output exception occurred
     */
    //long 回车
    public void println(long l) throws IOException {
    	print(l);
    	println();
    }
    /**
     * Writes a <code>float</code> value to the client,
     * followed by a carriage return-line feed (CRLF).
     * @param f			the <code>float</code> value to write to the client
     * @exception IOException 	if an input or output exception 			occurred
     */
    //float 回车
    public void println(float f) throws IOException {
    	print(f);
    	println();
    }
    /**
     * Writes a <code>double</code> value to the client,
     * followed by a carriage return-line feed (CRLF).
     * @param d			the <code>double</code> value	to write to the client
     * @exception IOException 	if an input or output exception occurred
     */
    //double 回车
    public void println(double d) throws IOException {
    	print(d);
    	println();
    }
}

Java-ServletOutputStream的更多相关文章

  1. Spark案例分析

    一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...

  2. java.lang.NoClassDefFoundError: javax/servlet/ServletOutputStream

    扩展阅读:https://blog.csdn.net/kimylrong/article/details/50353161

  3. Java 条形码 二维码 的生成与解析

    Barcode简介 Barcode是由一组按一定编码规则排列的条,空符号,用以表示一定的字符,数字及符号组成的,一种机器可读的数据表示方式. Barcode的形式多种多样,按照它们的外观分类: Lin ...

  4. Java Servlet规范

    截自网址:http://blog.csdn.net/u010391029/article/details/46521051 JavaServlet Specification  Version 2.3 ...

  5. solve the problem of 'java web project cannot display verification code'

    my java code of the function: package com.util; import java.awt.Color; import java.awt.Font; import ...

  6. java web学习总结(十八) -------------------过滤器的高级使用

    在filter中可以得到代表用户请求和响应的request.response对象,因此在编程中可以使用Decorator(装饰器)模式对request.response对象进行包装,再把包装对象传给目 ...

  7. java web学习总结(八) -------------------HttpServletResponse对象(二)

    一.HttpServletResponse常见应用--生成验证码 1.1.生成随机图片用作验证码 生成图片主要用到了一个BufferedImage类,

  8. java系统高并发解决方案-转

    转载博客地址:http://blog.csdn.net/zxl333/article/details/8685157 一个小型的网站,比如个人网站,可以使用最简单的html静态页面就实现了,配合一些图 ...

  9. JAVA文件下载功能问题解决日志

    今天给报告系统做了个下载功能,遇到了挺多问题,通过查资料一一解决了. 1.首先遇到的问题是:java后台的输出流输出之后,没有任何报错,浏览器端不弹出保存文件的对话框,原本是ajax请求到后台的con ...

  10. Java基础知识:代理

    一.代理的概念 动态代理技术是整个java技术中最重要的一个技术,它是学习java框架的基础,不会动态代理技术,那么在学习Spring这些框架时是学不明白的. 动态代理技术就是用来产生一个对象的代理对 ...

随机推荐

  1. 打开CMDLINE中的 ” earlyprink “ 参数

    点击打开链接 解决问题的过程中,好文章推荐,都保存在火狐wilson_sq@qq.com记录中~~~~~~~~grep -r "earlyprintk" kernelkernel/ ...

  2. 初识Java多线程编程

    Java 多线程编程 Java给多线程编程提供了内置的支持.一个多线程程序包含两个或多个能并发运行的部分.程序的每一部分都称作一个线程,并且每个线程定义了一个独立的执行路径. 多线程是多任务的一种特别 ...

  3. XMPP(一)-openfire服务端的安装和搭建

    XMPP全称:可扩展通讯和表示协议 简介:可扩展通讯和表示协议 (XMPP) 可用于服务类实时通讯.表示和需求响应服务中的XML数据元流式传输.XMPP以Jabber协议为基础,而Jabber是即时通 ...

  4. Hadoop MapReduce工作原理

    在学习Hadoop,慢慢的从使用到原理,逐层的深入吧 第一部分:MapReduce工作原理   MapReduce 角色 •Client :作业提交发起者. •JobTracker: 初始化作业,分配 ...

  5. FFmpeg源代码简单分析:结构体成员管理系统-AVClass

    ===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...

  6. H5、React Native、Native应用对比分析

    每日更新关注:http://weibo.com/hanjunqiang  新浪微博!iOS开发者交流QQ群: 446310206 "存在即合理".凡是存在的,都是合乎规律的.任何新 ...

  7. 05 Activity 回传数据

    当从一个Activity跳转到第二个Activity后然 让其处理完业务逻辑回传数据给第一个Activity: 回传调用方法顺序: onActivityResult--->>onResta ...

  8. Dynamics CRM 2015Online Update1 new feature之表单页Tabs切换

    CRM2011的界面相对于CRM4.0进行了比较大的改动,N久没见过4.0的界面了所以忘了表单是什么样子的了,但2011的表单中若含有多个tab的话,是可以通过左侧栏进行切换,话说2013的界面相对2 ...

  9. JS 可变参数

     JS可变参数的方法不需要参数,同时,我们应该注意在写JS文件的时候避免定义arguments变量. <html> <head> <title>Javascri ...

  10. OC语言编写:为视图添加丝滑的水波纹

    先看一下最终效果图: 首先我们可以把如此丝滑的水波纹拆分一下下: 一条规律的曲线. 曲线匀速向右移动. 曲线下方的位置用颜色填充. 于是先来一条曲线吧. 对于需要产生波动如此规律的曲线,我们首先想到的 ...