本文整理了Java中org.glassfish.grizzly.http.server.Response.getOutputStream
方法的一些代码示例,展示了Response.getOutputStream
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getOutputStream
方法的具体详情如下:
包路径:org.glassfish.grizzly.http.server.Response
类名称:Response
方法名:getOutputStream
[英]Return the OutputStream associated with this Response.
By default the returned NIOOutputStream will work as blocking java.io.OutputStream, but it will be possible to call NIOOutputStream#canWrite() or NIOOutputStream#notifyCanWrite(org.glassfish.grizzly.WriteHandler) to avoid blocking.
[中]返回与此响应关联的OutputStream。
默认情况下,返回的NIOOutputStream将用作阻塞java。伊奥。OutputStream,但可以调用NIOOutputStream#canWrite()或NIOOutputStream#notifyCanWrite(org.glassfish.grizzly.WriteHandler)以避免阻塞。
代码示例来源:origin: opentripplanner/OpenTripPlanner
public void writeJson (Response response, Object object) throws IOException {
mapper.writeValue(response.getOutputStream(), object);
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
OutputStream os = wr.response.getOutputStream();
mapper.writeValue(os, tasks);
os.close();
代码示例来源:origin: opentripplanner/OpenTripPlanner
OutputStream out = response.getOutputStream();
mapper.writeValue(out, tasks);
response.resume();
代码示例来源:origin: jersey/jersey
response.setStatus(HttpStatus.OK_200);
response.setContentType(mediaType);
ReaderWriter.writeTo(fileStream, response.getOutputStream());
代码示例来源:origin: jersey/jersey
@Override
public OutputStream writeResponseStatusAndHeaders(final long contentLength,
final ContainerResponse context)
throws ContainerException {
try {
final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo();
if (statusInfo.getReasonPhrase() == null) {
grizzlyResponse.setStatus(statusInfo.getStatusCode());
} else {
grizzlyResponse.setStatus(statusInfo.getStatusCode(), statusInfo.getReasonPhrase());
}
grizzlyResponse.setContentLengthLong(contentLength);
for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) {
for (final String value : e.getValue()) {
grizzlyResponse.addHeader(e.getKey(), value);
}
}
return grizzlyResponse.getOutputStream();
} finally {
logger.debugLog("{0} - writeResponseStatusAndHeaders() called", name);
}
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
OutputStream os = response.getOutputStream();
mapper.writeValue(os, ret);
os.close();
suspendedProducerResponse.getOutputStream());
} catch (IOException ioex) {
代码示例来源:origin: miltonio/milton2
@Override
public OutputStream getOutputStream() {
return r.getOutputStream();
}
代码示例来源:origin: miltonio/milton2
@Override
public void sendError(Status status, String message) {
try {
r.sendError(status.code, message);
}catch(java.lang.IllegalStateException e) {
log.error("Failed to send error, response already commited", e.getMessage());
} catch (IOException ex) {
log.error("Failed to send error", ex);
}
try {
r.getOutputStream().close();
log.info("Closed outputstream after sendError");
} catch (Throwable e) {
log.warn("Failed to close outputstream after sendError");
}
}
代码示例来源:origin: com.xebialabs.restito/restito
/**
* Writes bytes content to response
*/
public static Action bytesContent(final byte[] content) {
return new Action(response -> {
response.setContentLength(content.length);
try {
response.getOutputStream().write(content);
} catch (IOException e) {
throw new RuntimeException("Can not write resource content for restito stubbing.");
}
return response;
});
}
代码示例来源:origin: javaee/grizzly
@NotNull
@Override
public OutputStream getOutput() throws IOException {
response.setStatus(status);
if (responseHeaders != null) {
for (Map.Entry<String, List<String>> entry : responseHeaders.entrySet()) {
String name = entry.getKey();
if (name == null) {
continue;
}
if (name.equalsIgnoreCase("Content-Type") || name.equalsIgnoreCase("Content-Length")) {
continue; // ignore headers that interfere with the operation
}
for (String value : entry.getValue()) {
response.addHeader(name, value);
}
}
}
return response.getOutputStream();
}
代码示例来源:origin: org.glassfish.main.core/kernel
private void handleResourceRequest(Request req, Response res)
throws IOException {
String resourcePath = RESOURCE_PACKAGE + req.getRequestURI();
ClassLoader loader = AdminConsoleAdapter.class.getClassLoader();
InputStream in = null;
try {
in = loader.getResourceAsStream(resourcePath);
if (in == null) {
logger.log(Level.WARNING, KernelLoggerInfo.consoleResourceNotFound, resourcePath);
return;
}
byte[] buf = new byte[512];
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
for (int i = in.read(buf); i != -1; i = in.read(buf)) {
baos.write(buf, 0, i);
}
String contentType = getContentType(resourcePath);
if (contentType != null) {
res.setContentType(contentType);
}
res.setContentLength(baos.size());
OutputStream out = res.getOutputStream();
baos.writeTo(out);
out.flush();
} finally {
if (in != null) {
in.close();
}
}
}
代码示例来源:origin: com.conveyal/osm-lib
int suffixIndex = uri.lastIndexOf('.');
String fileType = uri.substring(suffixIndex);
OutputStream outStream = response.getOutputStream();
try {
String[] coords = uri.substring(1, suffixIndex).split("[,;]");
代码示例来源:origin: org.glassfish.grizzly/grizzly-http-server
} catch (IllegalStateException ise1) {
try {
getOutputStream().write(sb.toString().getBytes(
org.glassfish.grizzly.http.util.Constants.DEFAULT_HTTP_CHARSET));
} catch (IllegalStateException ise2) {
代码示例来源:origin: javaee/grizzly
} catch (IllegalStateException ise1) {
try {
getOutputStream().write(sb.toString().getBytes(
org.glassfish.grizzly.http.util.Constants.DEFAULT_HTTP_CHARSET));
} catch (IllegalStateException ise2) {
代码示例来源:origin: javaee/grizzly
} catch (IllegalStateException ise1) {
try {
getOutputStream().write(sb.toString().getBytes(
org.glassfish.grizzly.http.util.Constants.DEFAULT_HTTP_CHARSET));
} catch (IllegalStateException ise2) {
代码示例来源:origin: javaee/grizzly
} catch (IllegalStateException ise1) {
try {
getOutputStream().write(sb.toString().getBytes(
org.glassfish.grizzly.http.util.Constants.DEFAULT_HTTP_CHARSET));
} catch (IllegalStateException ise2) {
代码示例来源:origin: org.glassfish.main.core/kernel
private void reportAuthFailure(final Response res,
final ActionReport report,
final String msgKey,
final String msg,
final int httpStatus,
final String headerName,
final String headerValue) throws IOException {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
final String messageForResponse = adminStrings.getLocalString(msgKey, msg);
report.setMessage(messageForResponse);
report.setActionDescription("Authentication error");
res.setStatus(httpStatus, messageForResponse);
if (headerName != null) {
res.setHeader(headerName, headerValue);
}
res.setContentType(report.getContentType());
report.writeReport(res.getOutputStream());
res.getOutputStream().flush();
res.finish();
}
代码示例来源:origin: org.glassfish.jersey.containers/jersey-container-grizzly2-http
@Override
public OutputStream writeResponseStatusAndHeaders(final long contentLength,
final ContainerResponse context)
throws ContainerException {
try {
final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo();
if (statusInfo.getReasonPhrase() == null) {
grizzlyResponse.setStatus(statusInfo.getStatusCode());
} else {
grizzlyResponse.setStatus(statusInfo.getStatusCode(), statusInfo.getReasonPhrase());
}
grizzlyResponse.setContentLengthLong(contentLength);
for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) {
for (final String value : e.getValue()) {
grizzlyResponse.addHeader(e.getKey(), value);
}
}
return grizzlyResponse.getOutputStream();
} finally {
logger.debugLog("{0} - writeResponseStatusAndHeaders() called", name);
}
}
代码示例来源:origin: jersey/jersey-1.x
@Override
public OutputStream writeStatusAndHeaders(final long contentLength,
final ContainerResponse cResponse) throws IOException {
final javax.ws.rs.core.Response.StatusType statusInfo = cResponse.getStatusType();
if (statusInfo.getReasonPhrase() == null) {
response.setStatus(statusInfo.getStatusCode());
} else {
response.setStatus(statusInfo.getStatusCode(), statusInfo.getReasonPhrase());
}
if (contentLength != -1 && contentLength < Integer.MAX_VALUE) {
response.setContentLength((int) contentLength);
}
for (final Map.Entry<String, List<Object>> e : cResponse.getHttpHeaders().entrySet()) {
for (final Object value : e.getValue()) {
response.addHeader(e.getKey(),
ContainerResponse.getHeaderValue(value));
}
}
final String contentType = response.getHeader("Content-Type");
if (contentType != null) {
response.setContentType(contentType);
}
return response.getOutputStream();
}
}
代码示例来源:origin: com.sun.jersey/jersey-grizzly2
@Override
public OutputStream writeStatusAndHeaders(final long contentLength,
final ContainerResponse cResponse) throws IOException {
final javax.ws.rs.core.Response.StatusType statusInfo = cResponse.getStatusType();
if (statusInfo.getReasonPhrase() == null) {
response.setStatus(statusInfo.getStatusCode());
} else {
response.setStatus(statusInfo.getStatusCode(), statusInfo.getReasonPhrase());
}
if (contentLength != -1 && contentLength < Integer.MAX_VALUE) {
response.setContentLength((int) contentLength);
}
for (final Map.Entry<String, List<Object>> e : cResponse.getHttpHeaders().entrySet()) {
for (final Object value : e.getValue()) {
response.addHeader(e.getKey(),
ContainerResponse.getHeaderValue(value));
}
}
final String contentType = response.getHeader("Content-Type");
if (contentType != null) {
response.setContentType(contentType);
}
return response.getOutputStream();
}
}
内容来源于网络,如有侵权,请联系作者删除!