All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.youthlin.mvc.servlet.NoBodyOutputStream Maven / Gradle / Ivy

package com.youthlin.mvc.servlet;

import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ResourceBundle;

/**
 * Servlet output stream that gobbles up all its data.
 * 

* 创建:youthlin.chen * 时间:2017-08-17 00:27 * * @see javax.servlet.http.HttpServlet */ class NoBodyOutputStream extends ServletOutputStream { private static final String LSTRING_FILE = "javax.servlet.http.LocalStrings"; private static ResourceBundle lStrings = ResourceBundle.getBundle(LSTRING_FILE); private int contentLength = 0; // file private NoBodyOutputStream() { } // file private int getContentLength() { return contentLength; } @Override public void write(int b) { contentLength++; } @Override public void write(byte buf[], int offset, int len) throws IOException { if (buf == null) { throw new NullPointerException(lStrings.getString("err.io.nullArray")); } if (offset < 0 || len < 0 || offset + len > buf.length) { String msg = lStrings.getString("err.io.indexOutOfBounds"); Object[] msgArgs = new Object[3]; msgArgs[0] = offset; msgArgs[1] = len; msgArgs[2] = buf.length; msg = MessageFormat.format(msg, msgArgs); throw new IndexOutOfBoundsException(msg); } contentLength += len; } public boolean isReady() { return false; } public void setWriteListener(WriteListener writeListener) { } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy