import java.io.InputStream;
import java.io.IOException;

/**
 * Provides an input stream for reading binary data from a client
 * request, including an efficient <code>readLine</code> method
 * for reading data one line at a time. With some protocols, such
 * as HTTP POST and PUT, a <code>ServletInputStream</code>
 * object can be used to read data sent from the client.
 * <p>A <code>ServletInputStream</code> object is normally retrieved via
 * the {@link ServletRequest#getInputStream} method.
 * <p>This is an abstract class that a servlet container implements.
 * Subclasses of this class
 * must implement the <code>java.io.InputStream.read()</code> method.
 * @author 	Various
 * @version 	$Version$
 * @see		ServletRequest
 */

public abstract class ServletInputStream extends InputStream {

    /**
     * Does nothing, because this is an abstract class.
     *
     */
	//抽象类,空构造函数
    protected ServletInputStream() { }

    /**
     * Reads the input stream, one line at a time. Starting at an
     * offset, reads bytes into an array, until it reads a certain number
     * of bytes or reaches a newline character, which it reads into the
     * array as well.
     * <p>This method returns -1 if it reaches the end of the input
     * stream before reading the maximum number of bytes.
     * @param b 		an array of bytes into which data is read
     * @param off 		an integer specifying the character at which this method begins reading
     * @param len		an integer specifying the maximum number of bytes to read
     * @return			an integer specifying the actual number of bytes  read, or -1 if the end of the stream is reached
     * @exception IOException	if an input or output exception has occurred
     */

    public int readLine(byte[] b, int off, int len) throws IOException {

	if (len <= 0) {
	    return 0;
	}
	int count = 0, c;

	while ((c = read()) != -1) {
	    b[off++] = (byte)c;
	    count++;
	    if (c == '\n' || count == len) {
		break;
	    }
	}
	return count > 0 ? count : -1;
    }
}

Java-ServletInputStream的更多相关文章

  1. Spark案例分析

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

  2. Solr7部署报错:java.lang.NoSuchMethodError: javax.servlet.ServletInputStream.isFinished()Z

    错误信息: Servlet.service() for servlet [default] in context with path [/solr] threw exception [Filter e ...

  3. java.lang.NoClassDefFoundError: javax/servlet/ServletInputStream

    转自:https://blog.csdn.net/y970105/article/details/355401 进入 tomcat根目录/lib/servlet-api.jar复制出来,放到JDK_P ...

  4. JAVA过滤器

    对于get请求和post请求全局过滤: 自己创建一个类,实现HttpServletRequestWrapper接口 package com.dh.deno; import java.io.Buffer ...

  5. Android使用HttpURLConnection通过POST方式发送java序列化对象

    使用HttpURLConnection类不仅可以向WebService发送字符串,还可以发送序列化的java对象,实现Android手机和服务器之间的数据交互. Android端代码: public ...

  6. [Java面试三]JavaWeb基础知识总结.

    1.web服务器与HTTP协议 Web服务器 l WEB,在英语中web即表示网页的意思,它用于表示Internet主机上供外界访问的资源. l Internet上供外界访问的Web资源分为: • 静 ...

  7. Java Web之请求和响应

    Servlet最主要作用就是处理客户端请求并作出回应,为此,针对每次请求,Web容器在调用service()之前都会创建两个对象,分别是HttpServletRequest和HttpServletRe ...

  8. Flash 二进制传图片到后台Java服务器接收

    需求:把客户端处理过的图片返还给服务器Flash端代码 01 package {02     import com.adobe.images.JPGEncoder;    03     import  ...

  9. Java中实现文件上传下载的三种解决方案

    第一点:Java代码实现文件上传 FormFile file=manform.getFile(); String newfileName = null; String newpathname=null ...

  10. 【原创】用JAVA实现大文件上传及显示进度信息

    用JAVA实现大文件上传及显示进度信息 ---解析HTTP MultiPart协议 (本文提供全部源码下载,请访问 https://github.com/grayprince/UploadBigFil ...

随机推荐

  1. 【SSH系列】深入浅出SpringMvc+入门Demo

    Spring MVC框架是有一个MVC框架,通过实现Model-View-Controller模式来很好地将数据.业务与展现进行分离.从这样一个角度来说,Spring MVC和Struts.Strut ...

  2. springMVC源码分析--HandlerMethod

    在之前的博客中我们已经接触过HandlerMethod,接下来我们简单介绍一下HandlerMethod,简单来说HandlerMethod包含的信息包括类.方法和参数的一个信息类,通过其两个构造函数 ...

  3. Android Studio提交库至Bintray jCenter从入门到放弃

    文:http://blog.csdn.net/sk719887916/article/details/52473914 作者:Tamic 详细文章请看:[Gradle系列]Gradle发布module ...

  4. Python实现数据库一键导出为Excel表格

    依赖 Python2711 xlwt MySQLdb 数据库相关 连接 获取字段信息 获取数据 Excel基础 workbook sheet 案例 封装 封装之后 测试结果 总结 数据库数据导出为ex ...

  5. SQLite 表达式(http://www.w3cschool.cc/sqlite/sqlite-expressions.html)

    SQLite 表达式 表达式是一个或多个值.运算符和计算值的SQL函数的组合. SQL 表达式与公式类似,都写在查询语言中.您还可以使用特定的数据集来查询数据库. 语法 假设 SELECT 语句的基本 ...

  6. actionbar详解(二)

    经过前面两篇文章的学习,我想大家对ActionBar都已经有一个相对较为深刻的理解了.唯一欠缺的是,前面我们都只是学习了理论知识而已,虽然知识点已经掌握了,但是真正投入到项目实战当中时会不会掉链子还很 ...

  7. [shiro学习笔记]第三节 使用myeclipse导入apache shiro中的QuikStart example例子

    本文地址:http://blog.csdn.net/sushengmiyan/article/details/40149131 shiro官网:http://shiro.apache.org/ shi ...

  8. iOS的settings bundle中开关按钮(Toggle Switch)取不到值的问题

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 在Xcode7.2中设置App的settings bundle ...

  9. Volley,小并发网络请求的好帮手

    不得不说,当不了解一件事情的时候,就会像当然的认为,其很神秘.但是当真正的接触到了这些神秘的item,就不会有这种感觉了.作为一个android开发新手的我,刚接触到了Volley这个开源的网络请求框 ...

  10. Oracle dblink详解

     database link概述 database link是定义一个数据库到另一个数据库的路径的对象,database link允许你查询远程表及执行远程程序.在任何分布式环境里,databas ...