@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); } }
@Override public void setContentLength(long length) { response.setContentLength(length); }
/** * This should be used when the size of the message body is known. For * performance reasons this should be used so the length of the output * is known. This ensures that Persistent HTTP (PHTTP) connections * can be maintained for both HTTP/1.0 and HTTP/1.1 clients. If the * length of the output is not known HTTP/1.0 clients will require a * connection close, which reduces performance (see RFC 2616). * <p> * This removes any previous Content-Length headers from the message * header. This will then set the appropriate Content-Length header with * the correct length. If a the Connection header is set with the close * token then the semantics of the connection are such that the server * will close it once the <code>OutputStream.close</code> is used. * * @param length this is the length of the HTTP message body */ public void setContentLength(long length) { response.setContentLength(length); }
/** * This should be used when the size of the message body is known. For * performance reasons this should be used so the length of the output * is known. This ensures that Persistent HTTP (PHTTP) connections * can be maintained for both HTTP/1.0 and HTTP/1.1 clients. If the * length of the output is not known HTTP/1.0 clients will require a * connection close, which reduces performance (see RFC 2616). * <p> * This removes any previous Content-Length headers from the message * header. This will then set the appropriate Content-Length header with * the correct length. If a the Connection header is set with the close * token then the semantics of the connection are such that the server * will close it once the <code>OutputStream.close</code> is used. * * @param length this is the length of the HTTP message body */ public void setContentLength(long length) { response.setContentLength(length); }
/** * This should be used when the size of the message body is known. For * performance reasons this should be used so the length of the output * is known. This ensures that Persistent HTTP (PHTTP) connections * can be maintained for both HTTP/1.0 and HTTP/1.1 clients. If the * length of the output is not known HTTP/1.0 clients will require a * connection close, which reduces performance (see RFC 2616). * <p> * This removes any previous Content-Length headers from the message * header. This will then set the appropriate Content-Length header with * the correct length. If a the Connection header is set with the close * token then the semantics of the connection are such that the server * will close it once the <code>OutputStream.close</code> is used. * * @param length this is the length of the HTTP message body */ public void setContentLength(long length) { response.setContentLength(length); }
@Override public void setContentLengthHeader(Long totalLength) { if( totalLength != null ) { int i = (int) totalLength.longValue(); baseResponse.setContentLength(i); } // String s = totalLength==null ? null : totalLength.toString(); // setResponseHeader( Header.CONTENT_LENGTH,s); }
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()); } }
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(); }
rsp.setContentLength(rb.length); rsp.getOutputStream().write(rb); rsp.getOutputStream().flush();
rsp.setDate("Date", time); rsp.setDate("Last-Modified", time); rsp.setContentLength(k.length); OutputStream out = rsp.getOutputStream(); IOUtils.write(k, out); rsp.setContentLength(rb.length); rsp.getOutputStream().write(rb); rsp.getOutputStream().flush();
rsp.setContentType("text/xml"); byte[] rb = rsString.getBytes(); rsp.setContentLength(rb.length); try { rsp.getOutputStream().write(rb);
@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); } }
response.setContentLength(rb.length); response.getOutputStream().write(rb); response.getOutputStream().flush(); response.setContentLength(rb.length); response.getOutputStream().write(rb); response.getOutputStream().flush(); } else { MetaFileStore.getMF(path).sync(); response.setContentLength(f.length()); this.downloadFile(f, request, response); response.setContentLength(f.length()); this.downloadFile(f, request, response); } else if (request.getTarget().startsWith(BLOCK_PATH)) { response.setDate("Date", time); response.setDate("Last-Modified", time); response.setContentLength(data.length); response.getByteChannel().write(ByteBuffer.wrap(data)); response.getByteChannel().close(); response.setDate("Date", time); response.setDate("Last-Modified", time); response.setContentLength(rslt.length); response.getByteChannel().write(ByteBuffer.wrap(rslt)); response.getByteChannel().close();
@Override public void writeResponseHead(org.restlet.data.Response restletResponse) throws IOException { // this.response.clear(); for (final Parameter header : getResponseHeaders()) { this.response.add(header.getName(), header.getValue()); } // Set the status this.response.setCode(getStatusCode()); this.response.setText(getReasonPhrase()); // Is this really required if (restletResponse.getEntity() == null) { this.response.setContentLength(0); } } }