本文整理了Java中org.simpleframework.http.Response.getPrintStream
方法的一些代码示例,展示了Response.getPrintStream
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getPrintStream
方法的具体详情如下:
包路径:org.simpleframework.http.Response
类名称:Response
方法名:getPrintStream
[英]This method is provided for convenience so that the HTTP content can be written using the print
methods provided by the PrintStream
. This will basically wrap the getOutputStream
with a buffer size of zero.
The retrieved PrintStream
uses the charset used to describe the content, with the Content-Type header. This will check the charset parameter of the contents MIME type. So if the Content-Type was text/plain; charset=UTF-8
the resulting PrintStream
would encode the written data using the UTF-8 encoding scheme. Care must be taken to ensure that bytes written to the stream are correctly encoded.
Implementations of the Response
must guarantee that this can be invoked repeatedly without effecting any issued OutputStream
or PrintStream
object.
[中]提供此方法是为了方便起见,因此可以使用PrintStream
提供的print
方法编写HTTP内容。这将基本上以零缓冲区大小包装getOutputStream
。
检索到的PrintStream
使用用于描述内容的字符集和内容类型标题。这将检查contents MIME类型的charset参数。因此,如果内容类型为text/plain; charset=UTF-8
,则生成的PrintStream
将使用UTF-8编码方案对写入的数据进行编码。必须注意确保写入流的字节正确编码。Response
的实现必须保证可以重复调用它,而不会影响任何已发布的OutputStream
或PrintStream
对象。
代码示例来源:origin: SonarSource/sonarqube
gzipOutputStream.close();
} else {
resp.getPrintStream().append("agent=" + req.getValues("User-Agent").get(0));
代码示例来源:origin: org.simpleframework/simple
/**
* This method is provided for convenience so that the HTTP content
* can be written using the <code>print</code> methods provided by
* the <code>PrintStream</code>. This will basically wrap the
* <code>getOutputStream</code> with a buffer size of zero.
* <p>
* The retrieved <code>PrintStream</code> uses the charset used to
* describe the content, with the Content-Type header. This will
* check the charset parameter of the contents MIME type. So if
* the Content-Type was <code>text/plain; charset=UTF-8</code> the
* resulting <code>PrintStream</code> would encode the written data
* using the UTF-8 encoding scheme. Care must be taken to ensure
* that bytes written to the stream are correctly encoded.
* <p>
* Implementations of the <code>Response</code> must guarantee
* that this can be invoked repeatedly without effecting any issued
* <code>OutputStream</code> or <code>PrintStream</code> object.
*
* @return a print stream used for writing the response body
*
* @exception IOException this is thrown if there was an I/O error
*/
public PrintStream getPrintStream() throws IOException {
return response.getPrintStream();
}
代码示例来源:origin: org.simpleframework/simple-http
/**
* This method is provided for convenience so that the HTTP content
* can be written using the <code>print</code> methods provided by
* the <code>PrintStream</code>. This will basically wrap the
* <code>getOutputStream</code> with a buffer size of zero.
* <p>
* The retrieved <code>PrintStream</code> uses the charset used to
* describe the content, with the Content-Type header. This will
* check the charset parameter of the contents MIME type. So if
* the Content-Type was <code>text/plain; charset=UTF-8</code> the
* resulting <code>PrintStream</code> would encode the written data
* using the UTF-8 encoding scheme. Care must be taken to ensure
* that bytes written to the stream are correctly encoded.
* <p>
* Implementations of the <code>Response</code> must guarantee
* that this can be invoked repeatedly without effecting any issued
* <code>OutputStream</code> or <code>PrintStream</code> object.
*
* @return a print stream used for writing the response body
*
* @exception IOException this is thrown if there was an I/O error
*/
public PrintStream getPrintStream() throws IOException {
return response.getPrintStream();
}
代码示例来源:origin: ngallagher/simpleframework
/**
* This method is provided for convenience so that the HTTP content
* can be written using the <code>print</code> methods provided by
* the <code>PrintStream</code>. This will basically wrap the
* <code>getOutputStream</code> with a buffer size of zero.
* <p>
* The retrieved <code>PrintStream</code> uses the charset used to
* describe the content, with the Content-Type header. This will
* check the charset parameter of the contents MIME type. So if
* the Content-Type was <code>text/plain; charset=UTF-8</code> the
* resulting <code>PrintStream</code> would encode the written data
* using the UTF-8 encoding scheme. Care must be taken to ensure
* that bytes written to the stream are correctly encoded.
* <p>
* Implementations of the <code>Response</code> must guarantee
* that this can be invoked repeatedly without effecting any issued
* <code>OutputStream</code> or <code>PrintStream</code> object.
*
* @return a print stream used for writing the response body
*
* @exception IOException this is thrown if there was an I/O error
*/
public PrintStream getPrintStream() throws IOException {
return response.getPrintStream();
}
代码示例来源:origin: org.simpleframework/simple
/**
* This method is provided for convenience so that the HTTP content
* can be written using the <code>print</code> methods provided by
* the <code>PrintStream</code>. This will basically wrap the
* <code>getOutputStream</code> with a specified buffer size.
* <p>
* The retrieved <code>PrintStream</code> uses the charset used to
* describe the content, with the Content-Type header. This will
* check the charset parameter of the contents MIME type. So if
* the Content-Type was <code>text/plain; charset=UTF-8</code> the
* resulting <code>PrintStream</code> would encode the written data
* using the UTF-8 encoding scheme. Care must be taken to ensure
* that bytes written to the stream are correctly encoded.
* <p>
* Implementations of the <code>Response</code> must guarantee
* that this can be invoked repeatedly without effecting any issued
* <code>OutputStream</code> or <code>PrintStream</code> object.
*
* @param size the minimum size that the response buffer must be
*
* @return a print stream used for writing the response body
*
* @exception IOException this is thrown if there was an I/O error
*/
public PrintStream getPrintStream(int size) throws IOException {
return response.getPrintStream(size);
}
代码示例来源:origin: org.simpleframework/simple-http
/**
* This method is provided for convenience so that the HTTP content
* can be written using the <code>print</code> methods provided by
* the <code>PrintStream</code>. This will basically wrap the
* <code>getOutputStream</code> with a specified buffer size.
* <p>
* The retrieved <code>PrintStream</code> uses the charset used to
* describe the content, with the Content-Type header. This will
* check the charset parameter of the contents MIME type. So if
* the Content-Type was <code>text/plain; charset=UTF-8</code> the
* resulting <code>PrintStream</code> would encode the written data
* using the UTF-8 encoding scheme. Care must be taken to ensure
* that bytes written to the stream are correctly encoded.
* <p>
* Implementations of the <code>Response</code> must guarantee
* that this can be invoked repeatedly without effecting any issued
* <code>OutputStream</code> or <code>PrintStream</code> object.
*
* @param size the minimum size that the response buffer must be
*
* @return a print stream used for writing the response body
*
* @exception IOException this is thrown if there was an I/O error
*/
public PrintStream getPrintStream(int size) throws IOException {
return response.getPrintStream(size);
}
代码示例来源:origin: ngallagher/simpleframework
/**
* This method is provided for convenience so that the HTTP content
* can be written using the <code>print</code> methods provided by
* the <code>PrintStream</code>. This will basically wrap the
* <code>getOutputStream</code> with a specified buffer size.
* <p>
* The retrieved <code>PrintStream</code> uses the charset used to
* describe the content, with the Content-Type header. This will
* check the charset parameter of the contents MIME type. So if
* the Content-Type was <code>text/plain; charset=UTF-8</code> the
* resulting <code>PrintStream</code> would encode the written data
* using the UTF-8 encoding scheme. Care must be taken to ensure
* that bytes written to the stream are correctly encoded.
* <p>
* Implementations of the <code>Response</code> must guarantee
* that this can be invoked repeatedly without effecting any issued
* <code>OutputStream</code> or <code>PrintStream</code> object.
*
* @param size the minimum size that the response buffer must be
*
* @return a print stream used for writing the response body
*
* @exception IOException this is thrown if there was an I/O error
*/
public PrintStream getPrintStream(int size) throws IOException {
return response.getPrintStream(size);
}
代码示例来源:origin: lantunes/fixd
private PrintStream printBody(Response response, String contentType) throws IOException {
PrintStream ps = response.getPrintStream();
addStandardHeaders(response, contentType);
ps.println(body);
ps.flush();
return ps;
}
}
代码示例来源:origin: lantunes/fixd
@Override
public void run() {
try {
if (times > -1 && count >= times) {
timer.cancel();
timer.purge();
subscriberResponse.getPrintStream().close();
return;
}
responseBody.send(subscriberResponse, responseContentType);
count++;
} catch (Exception e) {
logger.error("error sending async response at fixed rate", e);
}
}
}, 0, periodInMillis);
代码示例来源:origin: kristofa/mock-http-server
private void errorResponse(final Response response, final int httpCode, final String message) {
response.setCode(httpCode);
response.set(CONTENT_TYPE, "text/plain;charset=utf-8");
PrintStream body;
try {
body = response.getPrintStream();
body.print(message);
body.close();
} catch (final IOException e) {
throw new IllegalStateException("Exception when building response.", e);
}
}
代码示例来源:origin: io.restx/restx-server-simple
@Override
public void handle(Request request, Response response) {
try {
if (request.getTarget().startsWith(routerPath)) {
router.route(
new SimpleRestxRequest(httpSettings, routerPath, request), new SimpleRestxResponse(response));
} else {
response.getPrintStream().print("Not found...");
response.getPrintStream().close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
代码示例来源:origin: restx/restx
@Override
public void handle(Request request, Response response) {
try {
if (request.getTarget().startsWith(routerPath)) {
router.route(
new SimpleRestxRequest(httpSettings, routerPath, request), new SimpleRestxResponse(response));
} else {
response.getPrintStream().print("Not found...");
response.getPrintStream().close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
代码示例来源: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: openpreserve/pagelyzer
public void handle(Request request, Response response) {
try {
PrintStream body = response.getPrintStream();
long time = System.currentTimeMillis();
String msg="";
代码示例来源:origin: zanata/zanata-platform
@Override
public void handle(Request request, Response response) {
try {
PrintStream body = response.getPrintStream();
long time = System.currentTimeMillis();
response.setStatus(status);
response.setContentType("text/plain");
response.setDate("Date", time);
response.setDate("Last-Modified", time);
log.info("mock container returning: status [{}], content [{}]",
status, responseContent);
body.println(responseContent);
body.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: qos-ch/logback-extensions
public void handle(Request request, Response response) {
try {
PrintStream body = response.getPrintStream();
long time = System.currentTimeMillis();
代码示例来源:origin: lantunes/fixd
subscriberResponse.getPrintStream().close();
break;
代码示例来源:origin: org.kie.remote/kie-remote-client
public void handle( Request req, Response resp ) {
try {
PrintStream out = resp.getPrintStream(1024);
String address = req.getAddress().toString();
if( address.equals(DEFAULT_ENPOINT) ) {
String content = readInputStreamAsString(req.getInputStream());
JaxbCommandsRequest cmdsReq = (JaxbCommandsRequest) jaxbSerializationProvider.deserialize(content);
String [] headerNames = {
TEST_HEADER_NAME,
ANOTHER_TEST_HEADER_NAME,
NOT_SENT_HEADER_NAME
};
List<String> headerValues = new ArrayList<String>();
for( String headerName : headerNames ) {
String headerVal = req.getValue(headerName);
if( headerVal != null ) {
headerValues.add(headerVal);
}
}
String output = handleJaxbCommandsRequest(cmdsReq, headerValues);
resp.setCode(HttpURLConnection.HTTP_OK);
out.print(output);
} else {
resp.setCode(HttpURLConnection.HTTP_BAD_REQUEST);
}
out.close();
} catch( Exception e ) {
e.printStackTrace();
}
}
代码示例来源:origin: zanata/zanata-platform
@Override
public void handle(Request request, Response response) {
try {
PrintStream body = response.getPrintStream();
long time = System.currentTimeMillis();
response.setValue("Content-Type", "text/plain");
response.setContentType("application/xml;charset=utf-8");
response.setDate("Date", time);
response.setDate("Last-Modified", time);
String path = request.getAddress().getPath().getPath();
log.trace("request path is {}", path);
StatusAndContent statusAndContent = tryMatchPath(path);
Status status = statusAndContent.status;
response.setStatus(status);
String content = statusAndContent.content;
log.trace("mock container returning: status [{}], content [{}]",
status, content);
body.println(content);
body.close();
} catch (Exception e) {
e.printStackTrace();
response.setStatus(Status.INTERNAL_SERVER_ERROR);
try {
response.close();
} catch (IOException e1) {
throw new RuntimeException(e1);
}
}
}
代码示例来源:origin: org.kie.remote/kie-remote-client
public void handle( Request req, Response resp ) {
try {
PrintStream out = resp.getPrintStream(1024);
String address = req.getAddress().toString();
if( address.equals(REDIRECT_PATH) ) {
内容来源于网络,如有侵权,请联系作者删除!