Example usage for org.springframework.http HttpHeaders setContentLength

List of usage examples for org.springframework.http HttpHeaders setContentLength

Introduction

In this page you can find the example usage for org.springframework.http HttpHeaders setContentLength.

Prototype

public void setContentLength(long contentLength) 

Source Link

Document

Set the length of the body in bytes, as specified by the Content-Length header.

Usage

From source file:org.lightadmin.core.web.util.ResponseUtils.java

public static HttpHeaders octetStreamResponseHeader(MediaType mediaType, long length, String eTag) {
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentLength(length);
    responseHeaders.setContentType(mediaType);
    responseHeaders.setCacheControl("max-age");
    if (isNotBlank(eTag)) {
        responseHeaders.setETag(eTag);/*from   w  ww. j a v a 2 s  . co m*/
    }
    responseHeaders.set("Content-Disposition", "inline; filename=\"file.jpg\"");
    return responseHeaders;
}

From source file:org.focusns.common.web.WebUtils.java

public static <T> ResponseEntity<T> getResponseEntity(T body, MediaType mediaType) {
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(mediaType);
    if (body instanceof byte[]) {
        httpHeaders.setContentLength(((byte[]) body).length);
    }//from ww w.j  av a2  s  . c  om
    return new ResponseEntity<T>(body, httpHeaders, HttpStatus.OK);
}

From source file:aiai.ai.launchpad.server.ServerController.java

private static HttpHeaders getHeader(long length) {
    HttpHeaders header = new HttpHeaders();
    header.setContentLength(length);
    header.setCacheControl("max-age=0");
    header.setExpires(0);//w w w.j  a  v  a 2s. c o m
    header.setPragma("no-cache");

    return header;
}

From source file:com.highcharts.export.controller.ExportController.java

public static HttpHeaders httpHeaderAttachment(final String filename, final MimeType mime, final int fileSize) {
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.set("charset", "utf-8");
    responseHeaders.setContentType(MediaType.parseMediaType(mime.getType()));
    responseHeaders.setContentLength(fileSize);
    responseHeaders.set("Content-disposition",
            "attachment; filename=\"" + filename + "." + mime.name().toLowerCase() + "\"");
    return responseHeaders;
}

From source file:Highcharts.ExportController.java

public static HttpHeaders httpHeaderAttachment(final String filename, final MimeType mime, final int fileSize) {
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.set("charset", "utf-8");
        responseHeaders.setContentType(MediaType.parseMediaType(mime.getType()));
        responseHeaders.setContentLength(fileSize);
        responseHeaders.set("Content-disposition",
                "attachment; filename=\"" + filename + "." + mime.name().toLowerCase() + "\"");
        return responseHeaders;
    }//from  w  w w  . ja va  2 s . c  o  m

From source file:net.solarnetwork.node.setup.web.NodeCertificatesController.java

/**
 * Return a node's current certificate./*from w w  w  . j a  va2s.c  om*/
 * 
 * @return a map with the PEM encoded certificate on key {@code cert} if
 *         {@code download} is not <em>true</em>, otherwise the content is
 *         returned as a file attachment
 */
@RequestMapping(value = "/nodeCert", method = RequestMethod.GET)
@ResponseBody
public Object viewNodeCert(@RequestParam(value = "download", required = false) final Boolean download,
        @RequestParam(value = "chain", required = false) final Boolean asChain) {
    final String cert = (Boolean.TRUE.equals(asChain) ? pkiService.generateNodePKCS7CertificateChainString()
            : pkiService.generateNodePKCS7CertificateString());

    if (!Boolean.TRUE.equals(download)) {
        Map<String, Object> result = new HashMap<String, Object>(1);
        result.put("cert", cert);
        return result;
    }

    HttpHeaders headers = new HttpHeaders();
    headers.setContentLength(cert.length());
    headers.setContentType(MediaType.parseMediaType("application/x-pem-file"));
    headers.setLastModified(System.currentTimeMillis());
    headers.setCacheControl("no-cache");

    headers.set("Content-Disposition",
            "attachment; filename=solarnode-" + getIdentityService().getNodeId() + ".pem");

    return new ResponseEntity<String>(cert, headers, HttpStatus.OK);
}

From source file:jp.go.aist.six.util.core.web.spring.FileRequestCallback.java

public void doWithRequest(final ClientHttpRequest request) throws IOException {
    HttpHeaders headers = request.getHeaders();
    headers.setContentType(_mediaType);/*from w ww  .j  a  v  a  2  s  .  co m*/

    long size = IoUtil.copy(_file, request.getBody());
    headers.setContentLength(size);
}

From source file:jp.go.aist.six.util.core.web.spring.InputStreamRequestCallback.java

public void doWithRequest(final ClientHttpRequest request) throws IOException {
    HttpHeaders headers = request.getHeaders();
    headers.setContentType(_mediaType);//  w  w  w. jav  a  2s .  co  m

    long size = IoUtil.copy(_input, request.getBody());
    headers.setContentLength(size);
}

From source file:ar.com.aleatoria.ue.rest.AbstractBufferingClientHttpRequest.java

@Override
protected ClientHttpResponse executeInternal(HttpHeaders headers) throws IOException {
    byte[] bytes = this.bufferedOutput.toByteArray();
    if (headers.getContentLength() == -1) {
        headers.setContentLength(bytes.length);
    }/*from   w  ww  .j a  v  a 2s.c o m*/
    ClientHttpResponse result = executeInternal(headers, bytes);
    this.bufferedOutput = null;
    return result;
}

From source file:de.pksoftware.springstrap.sapi.controller.UpdateController.java

@RequestMapping(value = "/update-client", produces = "application/zip")
public HttpEntity<ByteArrayResource> updateClient() throws IOException, URISyntaxException {
    //String archiveFileName = clientSystemConfig.system.id + "-" + clientSystemConfig.system.version + ".zip";

    String archiveFileName = "springstrap-server.zip";

    //File file = new File("/home/pksoftware/dev-temp/ui5os-server-temp/" + archiveFileName);

    /*//  w ww.j  a  v  a 2 s  .  c  o m
    if(file.exists()){
       logger.info("Update already packaged: {}", file.getAbsolutePath());
               
       FileInputStream fin = new FileInputStream(file);
       byteArray = new byte[(int)file.length()];
               
       // Reads up to certain bytes of data from this input stream into an array of bytes.
       fin.read(byteArray);
               
       fin.close();
    }
    else{
    */
    logger.info("Building update package...");

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    WebappZipper zipper = new WebappZipper(outputStream, servletContext);

    zipper.addResource("classpath*:/webjar/**", false);

    //zipper.addResource("/system/**", servletContext);
    zipper.addResource("/apps/**", true);
    zipper.addResource("/lib/**", true);

    zipper.addResource("/admin.html", true);
    zipper.addResource("/account.html", true);
    zipper.addResource("/microapp.html", true);

    zipper.close();

    byteArray = outputStream.toByteArray();

    outputStream.close();

    /*
    FileOutputStream fop = new FileOutputStream(file);
    fop.write(byteArray);
    fop.flush();
    fop.close();
    */
    //}

    //Send response

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentLength(byteArray.length);
    headers.set("Content-Disposition", "attachment; filename=\"" + archiveFileName + "\"");

    return new HttpEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers);

}