blade.kit.http.RequestOutputStream Maven / Gradle / Ivy
package blade.kit.http;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
/**
* 请求输出流包装
*
* @author biezhi
* @since 1.0
*/
public class RequestOutputStream extends BufferedOutputStream {
final CharsetEncoder encoder;
/**
* Create request output stream
*
* @param stream
* @param charset
* @param bufferSize
*/
public RequestOutputStream(final OutputStream stream, final String charset, final int bufferSize) {
super(stream, bufferSize);
encoder = Charset.forName(HttpRequest.getValidCharset(charset)).newEncoder();
}
/**
* Write string to stream
*
* @param value
* @return this stream
* @throws IOException
*/
public RequestOutputStream write(final String value) throws IOException {
final ByteBuffer bytes = encoder.encode(CharBuffer.wrap(value));
super.write(bytes.array(), 0, bytes.limit());
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy