本文整理了Java中org.glassfish.grizzly.http.server.Response.setContentLength
方法的一些代码示例,展示了Response.setContentLength
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.setContentLength
方法的具体详情如下:
包路径:org.glassfish.grizzly.http.server.Response
类名称:Response
方法名:setContentLength
[英]Set the content length (in bytes) for this Response. If the length
argument is negative - then org.glassfish.grizzly.http.HttpPacketcontent-length value will be reset to -1 and Content-Length header (if present) will be removed.
[中]设置此响应的内容长度(字节)。如果length
参数为负,则为org。玻璃鱼。灰熊http。HttpPacketcontent-length值将重置为-1,内容长度标题(如果存在)将被删除。
代码示例来源:origin: javaee/grizzly
/**
* {@inheritDoc}
*/
@Override
public void setContentLength(int len) {
if (isCommitted())
return;
response.setContentLength(len);
}
代码示例来源:origin: javaee/grizzly
/**
* {@inheritDoc}
*/
@Override
public void setContentLength(int len) {
if (isCommitted())
return;
response.setContentLength(len);
}
代码示例来源:origin: javaee/grizzly
/**
* {@inheritDoc}
*/
@Override
public void setContentLength(int len) {
if (isCommitted())
return;
response.setContentLength(len);
}
代码示例来源:origin: org.glassfish.grizzly/grizzly-websockets-server
/**
* {@inheritDoc}
*/
@Override
public void setContentLength(int len) {
if (isCommitted())
return;
response.setContentLength(len);
}
代码示例来源:origin: javaee/grizzly
/**
* {@inheritDoc}
*/
@Override
public void setContentLength(int len) {
if (isCommitted())
return;
response.setContentLength(len);
}
代码示例来源:origin: javaee/grizzly
/**
* {@inheritDoc}
*/
@Override
public void setContentLength(int len) {
if (isCommitted())
return;
response.setContentLength(len);
}
代码示例来源: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: 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: org.glassfish.main.core/kernel
/**
*
*/
private void sendStatusNotDAS(Request req, Response res) {
byte[] bytes;
try {
String html = Utils.packageResource2String("statusNotDAS.html");
OutputBuffer ob = getOutputBuffer(res);
// Replace locale specific Strings
String localHtml = replaceTokens(html, bundle);
bytes = localHtml.getBytes("UTF-8");
res.setContentLength(bytes.length);
ob.write(bytes, 0, bytes.length);
ob.flush();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
代码示例来源:origin: org.glassfish.main.core/kernel
/**
*
*/
private void sendStatusPage(Request req, Response res) {
byte[] bytes;
try {
OutputBuffer ob = getOutputBuffer(res);
// Replace locale specific Strings
String localHtml = replaceTokens(statusHtml, bundle);
// Replace state token
String status = getStateMsg().getI18NKey();
try {
// Try to get a localized version of this key
status = bundle.getString(status);
} catch (MissingResourceException ex) {
// Use the non-localized String version of the status
status = getStateMsg().toString();
}
String locationUrl = req.getScheme()
+ "://" + req.getServerName()
+ ':' + req.getServerPort() + "/login.jsf";
localHtml = localHtml.replace(REDIRECT_TOKEN, locationUrl);
bytes = localHtml.replace(STATUS_TOKEN, status).getBytes("UTF-8");
res.setContentLength(bytes.length);
ob.write(bytes, 0, bytes.length);
ob.flush();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
代码示例来源:origin: ch.squaredesk.nova/http
try (NIOWriter out = response.getNIOWriter()) {
response.setContentType("application/json");
response.setContentLength(replyInfo._1.length());
int statusCode;
if (replyInfo._2 == null) {
代码示例来源: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();
}
}
代码示例来源: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: org.glassfish.main.core/kernel
res.setContentLength(bytes.length);
ob.write(bytes, 0, bytes.length);
ob.flush();
内容来源于网络,如有侵权,请联系作者删除!