package com.test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.servlet.ServletOutputStream;
public class BufferedOutputStream extends ServletOutputStream {
private ByteArrayOutputStream outputStream = null;
public BufferedOutputStream(){
outputStream = new ByteArrayOutputStream(1024);
}
/**
* Writes the specified byte to this output stream. The general
* contract for <code>write</code> is that one byte is written
* to the output stream. The byte to be written is the eight
* low-order bits of the argument <code>b</code>. The 24
* high-order bits of <code>b</code> are ignored.
* <p>
* Subclasses of <code>OutputStream</code> must provide an
* implementation for this method.
*
* @param b the <code>byte</code>.
* @exception IOException if an I/O error occurs. In particular,
* an <code>IOException</code> may be thrown if the
* output stream has been closed.
*/
public void write(int b) throws IOException {
outputStream.write(b);
}
/**
* Writes <code>b.length</code> bytes from the specified byte array
* to this output stream. The general contract for <code>write(b)</code>
* is that it should have exactly the same effect as the call
* <code>write(b, 0, b.length)</code>.
*
* @param b the data.
* @exception IOException if an I/O error occurs.
* @see java.io.OutputStream#write(byte[], int, int)
*/
public void write(byte b[]) throws IOException {
outputStream.write(b);
}
/**
* Writes <code>len</code> bytes from the specified byte array
* starting at offset <code>off</code> to this output stream.
* The general contract for <code>write(b, off, len)</code> is that
* some of the bytes in the array <code>b</code> are written to the
* output stream in order; element <code>b[off]</code> is the first
* byte written and <code>b[off+len-1]</code> is the last byte written
* by this operation.
* <p>
* The <code>write</code> method of <code>OutputStream</code> calls
* the write method of one argument on each of the bytes to be
* written out. Subclasses are encouraged to override this method and
* provide a more efficient implementation.
* <p>
* If <code>b</code> is <code>null</code>, a
* <code>NullPointerException</code> is thrown.
* <p>
* If <code>off</code> is negative, or <code>len</code> is negative, or
* <code>off+len</code> is greater than the length of the array
* <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown.
*
* @param b the data.
* @param off the start offset in the data.
* @param len the number of bytes to write.
* @exception IOException if an I/O error occurs. In particular,
* an <code>IOException</code> is thrown if the output
* stream is closed.
*/
public void write(byte b[], int off, int len) throws IOException {
outputStream.write(b, off, len);
}
/**
* 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
*
*/
public void print(String s) throws IOException {
print(s, "UTF-8");
}
public void print(String s, String charsetName) throws IOException {
/*
* 解决中文乱码问题
*/
outputStream.write(s.getBytes(charsetName));
}
/**
* 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
*
*/
public void print(boolean b) throws IOException {
print(b?"true":"false");
}
/**
* 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
*
*/
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
*
*/
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
*
*
*/
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
*
*/
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
*
*/
public void println(String s){
println(s, "UTF-8");
}
public void println(String s, String charsetName){
/*
* 解决中文乱码问题
*/
try {
print(s,charsetName);
println();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/**
*
* Writes a <code>boolean</code> value to the client,
* followed by a
* carriage return-line feed (CRLF).
*
*
* @param b th
java实现gzip ajax请求gzip压缩
5星 · 超过95%的资源 需积分: 50 180 浏览量
2017-05-13
19:30:43
上传
评论
收藏 572KB ZIP 举报
grace.free
- 粉丝: 598
- 资源: 82
最新资源
- Screenshot_20240509_034911_com.tencent.mtt.jpg
- 基于python实现的医学影像体脂分割+源代码+文档说明(课程设计)
- 基于python实现的医学影像(MIR, CT )图像分割源码+文档说明(高分课程设计)
- 基于python+JavaScript实现的医学影像分割+源代码+文档说明+截图演示+数据(高分毕业设计)
- 基于U-net+pytorch实现的医学影像分割python源码+文档说明+数据+界面截图+博客介绍
- 课程设计-基于Pytorch实现MNIST数据集的手写数字识别源码+数据(Gui界面)+文档说明+模型
- 软件开发国家标准.xls
- pytorch-CNN-SBATM-ubuntudemo
- matplotlibdemo
- pytorch-CNN-dht11温湿度传感器笔记
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈