/**
 * 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. 前端CSS技术全解(一)

    一.概述 1)用HTML完成样式工作 哪个标签有哪个属性难以记忆 需求变更影响较大(例如像修改成功法则以下的文字颜色需要修改4个地方) <h1 align="center"& ...

  2. Redis 学习笔记1:CentOS 6.7下安装Redis

    在linux环境搭建Redis环境,首先从官网(http://redis.io/)下载Redis 版本,本人使用的3.21版本. 1. 将redis 解压到  /usr/local目录下. [root ...

  3. UE4 读取本地图片

    参考链接:https://answers.unrealengine.com/questions/235086/texture-2d-shows-wrong-colors-from-jpeg-on-ht ...

  4. JAVA面向对象-----构造方法

    我们人出生的时候,有些人一出生之后再起名字的,但是有些人一旦出生就已经起好名字的.那么我们在java里面怎么在对象一旦创建就赋值呢? 构造方法作用 构造方法作用:对对象进行初始化. 构造函数与普通的函 ...

  5. Dynamics CRM2016 New features in Microsoft Dynamics CRM Online 2015 Update 1 are now available

    很多人看过Dynamics CRM Online 2015 Update 1后,被它新的一个界面风格所吸引,还有它的很多新增功能,虽然官网放出了些补丁,但最重要的Server补丁一直没出,包括我在内很 ...

  6. GSON TypeToken 解决泛型问题

    Java进阶(四)Java反射TypeToken解决泛型运行时类型擦除的问题解决 在开发时,遇到了下面这条语句,不懂,然习之. private List<MyZhuiHaoDetailModel ...

  7. UNIX网络编程——select函数的并发限制和 poll 函数应用举例

    一.用select实现的并发服务器,能达到的并发数,受两方面限制 1.一个进程能打开的最大文件描述符限制.这可以通过调整内核参数.可以通过ulimit -n来调整或者使用setrlimit函数设置,  ...

  8. Web开发学习之路--Eclipse+Tomcat+mysql之初体验

    学习了一段时间android,正好要用到android和服务器之间的交互,既然要学习android,那么就涉猎下服务器端的开发了,以前学过php,用thinkphp很快可以搭建起来,但是android ...

  9. 网站开发进阶(四十二)巧用clear:both

    网站开发进阶(四十二)巧用clear:both 前言 我们在制作网页中用div+css或者称xhtml+css都会遇到一些很诡异的情况,明明布局正确,但是整个画面却混乱起来了,有时候在IE6下看的很正 ...

  10. 解决ActionBar中的item不显示在ActionBar的问题

    今天在用ActionBar,需要增加一个菜单选项,按教程在/res/menu下对应的布局文件中添加了一个item,但是它却是显示在overflow中,而不是直接显示在ActionBar当中的.我的布局 ...