本文整理了Java中org.simpleframework.http.Response.getOutputStream
方法的一些代码示例,展示了Response.getOutputStream
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getOutputStream
方法的具体详情如下:
包路径:org.simpleframework.http.Response
类名称:Response
方法名:getOutputStream
[英]Used to write a message body with the Response
. The semantics of this OutputStream
will be determined by the HTTP version of the client, and whether or not the content length has been set, through the setContentLength
method. If the length of the output is not known then the output is chunked for HTTP/1.1 clients and closed for HTTP/1.0 clients.
[中]用于编写带有[$0$]的消息正文。此OutputStream
的语义将由客户端的HTTP版本以及是否通过setContentLength
方法设置了内容长度来确定。如果输出的长度未知,则HTTP/1.1客户端的输出将分块,HTTP/1.0客户端的输出将关闭。
代码示例来源:origin: mpetazzoni/ttorrent
@Override
public void serveResponse(int code, String description, ByteBuffer responseData) {
response.setCode(code);
response.setText(description);
try {
responseData.rewind();
final WritableByteChannel channel = Channels.newChannel(response.getOutputStream());
channel.write(responseData);
} catch (IOException e) {
e.printStackTrace();
}
}
};
代码示例来源:origin: jersey/jersey
@Override
public OutputStream writeResponseStatusAndHeaders(final long contentLength,
final ContainerResponse context) throws ContainerException {
final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo();
final int code = statusInfo.getStatusCode();
final String reason = statusInfo.getReasonPhrase() == null
? Status.getDescription(code)
: statusInfo.getReasonPhrase();
response.setCode(code);
response.setDescription(reason);
if (contentLength != -1) {
response.setContentLength(contentLength);
}
for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) {
for (final String value : e.getValue()) {
response.addValue(e.getKey(), value);
}
}
try {
return response.getOutputStream();
} catch (final IOException ioe) {
throw new ContainerException("Error during writing out the response headers.", ioe);
}
}
代码示例来源:origin: mpetazzoni/ttorrent
body = response.getOutputStream();
代码示例来源:origin: SonarSource/sonarqube
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(resp.getOutputStream());
gzipOutputStream.write("GZIP response".getBytes());
gzipOutputStream.close();
代码示例来源:origin: CodeStory/fluent-http
@Override
public OutputStream outputStream() throws IOException {
return response.getOutputStream();
}
代码示例来源:origin: restx/restx
@Override
protected OutputStream doGetOutputStream() throws IOException {
return response.getOutputStream();
}
代码示例来源:origin: io.restx/restx-server-simple
@Override
protected OutputStream doGetOutputStream() throws IOException {
return response.getOutputStream();
}
代码示例来源:origin: org.restlet/org.restlet.ext.simple
/**
* Returns the response stream if it exists.
*
* @return The response stream if it exists.
*/
@Override
public OutputStream getResponseEntityStream() {
try {
return this.response.getOutputStream();
} catch (Exception ex) {
return null;
}
}
代码示例来源:origin: ngallagher/simpleframework
/**
* Used to write a message body with the <code>Response</code>. The
* semantics of this <code>OutputStream</code> will be determined
* by the HTTP version of the client, and whether or not the content
* length has been set, through the <code>setContentLength</code>
* method. If the length of the output is not known then the output
* is chunked for HTTP/1.1 clients and closed for HTTP/1.0 clients.
* The <code>OutputStream</code> issued must be thread safe so that
* it can be used in a concurrent environment.
*
* @exception IOException this is thrown if there was an I/O error
*
* @return an output stream used to write the response body
*/
public OutputStream getOutputStream() throws IOException {
return response.getOutputStream();
}
代码示例来源:origin: org.simpleframework/simple
/**
* Used to write a message body with the <code>Response</code>. The
* semantics of this <code>OutputStream</code> will be determined
* by the HTTP version of the client, and whether or not the content
* length has been set, through the <code>setContentLength</code>
* method. If the length of the output is not known then the output
* is chunked for HTTP/1.1 clients and closed for HTTP/1.0 clients.
* The <code>OutputStream</code> issued must be thread safe so that
* it can be used in a concurrent environment.
*
* @exception IOException this is thrown if there was an I/O error
*
* @return an output stream used to write the response body
*/
public OutputStream getOutputStream() throws IOException {
return response.getOutputStream();
}
代码示例来源:origin: org.simpleframework/simple-http
/**
* Used to write a message body with the <code>Response</code>. The
* semantics of this <code>OutputStream</code> will be determined
* by the HTTP version of the client, and whether or not the content
* length has been set, through the <code>setContentLength</code>
* method. If the length of the output is not known then the output
* is chunked for HTTP/1.1 clients and closed for HTTP/1.0 clients.
* The <code>OutputStream</code> issued must be thread safe so that
* it can be used in a concurrent environment.
*
* @exception IOException this is thrown if there was an I/O error
*
* @return an output stream used to write the response body
*/
public OutputStream getOutputStream() throws IOException {
return response.getOutputStream();
}
代码示例来源:origin: ngallagher/simpleframework
/**
* Used to write a message body with the <code>Response</code>. The
* semantics of this <code>OutputStream</code> will be determined
* by the HTTP version of the client, and whether or not the content
* length has been set, through the <code>setContentLength</code>
* method. If the length of the output is not known then the output
* is chunked for HTTP/1.1 clients and closed for HTTP/1.0 clients.
* The <code>OutputStream</code> issued must be thread safe so that
* it can be used in a concurrent environment.
* <p>
* This will ensure that there is buffering done so that the output
* can be reset using the <code>reset</code> method. This will
* enable the specified number of bytes to be written without
* committing the response. This specified size is the minimum size
* that the response buffer must be.
*
* @param size the minimum size that the response buffer must be
*
* @return an output stream used to write the response body
*
* @exception IOException this is thrown if there was an I/O error
*/
public OutputStream getOutputStream(int size) throws IOException {
return response.getOutputStream(size);
}
代码示例来源:origin: miltonio/milton2
@Override
public OutputStream getOutputStream() {
try {
return baseResponse.getOutputStream();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
代码示例来源:origin: org.simpleframework/simple-http
/**
* Used to write a message body with the <code>Response</code>. The
* semantics of this <code>OutputStream</code> will be determined
* by the HTTP version of the client, and whether or not the content
* length has been set, through the <code>setContentLength</code>
* method. If the length of the output is not known then the output
* is chunked for HTTP/1.1 clients and closed for HTTP/1.0 clients.
* The <code>OutputStream</code> issued must be thread safe so that
* it can be used in a concurrent environment.
* <p>
* This will ensure that there is buffering done so that the output
* can be reset using the <code>reset</code> method. This will
* enable the specified number of bytes to be written without
* committing the response. This specified size is the minimum size
* that the response buffer must be.
*
* @param size the minimum size that the response buffer must be
*
* @return an output stream used to write the response body
*
* @exception IOException this is thrown if there was an I/O error
*/
public OutputStream getOutputStream(int size) throws IOException {
return response.getOutputStream(size);
}
代码示例来源:origin: ngallagher/simpleframework
public OutputStreamCapture(Response resp) throws Exception {
this.real = resp.getOutputStream();
this.body = new ByteArrayOutputStream();
}
代码示例来源:origin: org.simpleframework/simple
/**
* Used to write a message body with the <code>Response</code>. The
* semantics of this <code>OutputStream</code> will be determined
* by the HTTP version of the client, and whether or not the content
* length has been set, through the <code>setContentLength</code>
* method. If the length of the output is not known then the output
* is chunked for HTTP/1.1 clients and closed for HTTP/1.0 clients.
* The <code>OutputStream</code> issued must be thread safe so that
* it can be used in a concurrent environment.
* <p>
* This will ensure that there is buffering done so that the output
* can be reset using the <code>reset</code> method. This will
* enable the specified number of bytes to be written without
* committing the response. This specified size is the minimum size
* that the response buffer must be.
*
* @param size the minimum size that the response buffer must be
*
* @return an output stream used to write the response body
*
* @exception IOException this is thrown if there was an I/O error
*/
public OutputStream getOutputStream(int size) throws IOException {
return response.getOutputStream(size);
}
代码示例来源:origin: lantunes/fixd
private OutputStream sendContent(Response resp, String contentType) throws IOException {
OutputStream out = resp.getOutputStream();
addStandardHeaders(resp, contentType);
byte[] buffer = new byte[1024];
int len;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
out.flush();
return out;
}
代码示例来源:origin: opendedup/sdfs
private void downloadFile(File f, Request request, Response response) throws IOException {
if (f.exists()) {
response.setContentType("application/octet-stream");
response.addValue("Server", "SDFS Management Server");
response.setContentLength(f.length());
InputStream in = new FileInputStream(f);
OutputStream out = response.getOutputStream();
byte[] buf = new byte[32768];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.flush();
in.close();
out.close();
} else {
response.setCode(404);
PrintStream body = response.getPrintStream();
body.println("could not find " + f.getPath());
body.close();
SDFSLogger.getLog().warn("unable to find " + f.getPath());
}
}
代码示例来源:origin: com.sun.jersey.contribs/jersey-simple-server
public OutputStream writeStatusAndHeaders(long contentLength, ContainerResponse cResponse) throws IOException {
int code = cResponse.getStatus();
String text = Status.getDescription(code);
String method = request.getMethod();
response.setCode(code);
response.setDescription(text);
if (!method.equalsIgnoreCase("HEAD") && contentLength != -1 && contentLength < Integer.MAX_VALUE) {
response.setContentLength((int) contentLength);
}
for (Map.Entry<String, List<Object>> e : cResponse.getHttpHeaders().entrySet()) {
for (Object value : e.getValue()) {
response.setValue(e.getKey(), ContainerResponse.getHeaderValue(value));
}
}
return response.getOutputStream();
}
代码示例来源:origin: org.glassfish.jersey.containers/jersey-container-simple-http
@Override
public OutputStream writeResponseStatusAndHeaders(final long contentLength,
final ContainerResponse context) throws ContainerException {
final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo();
final int code = statusInfo.getStatusCode();
final String reason = statusInfo.getReasonPhrase() == null
? Status.getDescription(code)
: statusInfo.getReasonPhrase();
response.setCode(code);
response.setDescription(reason);
if (contentLength != -1) {
response.setContentLength(contentLength);
}
for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) {
for (final String value : e.getValue()) {
response.addValue(e.getKey(), value);
}
}
try {
return response.getOutputStream();
} catch (final IOException ioe) {
throw new ContainerException("Error during writing out the response headers.", ioe);
}
}
内容来源于网络,如有侵权,请联系作者删除!