Example usage for org.springframework.http MediaType APPLICATION_OCTET_STREAM

List of usage examples for org.springframework.http MediaType APPLICATION_OCTET_STREAM

Introduction

In this page you can find the example usage for org.springframework.http MediaType APPLICATION_OCTET_STREAM.

Prototype

MediaType APPLICATION_OCTET_STREAM

To view the source code for org.springframework.http MediaType APPLICATION_OCTET_STREAM.

Click Source Link

Document

Public constant media type for application/octet-stream .

Usage

From source file:org.trustedanalytics.h2oscoringengine.publisher.PublisherIntegrationTest.java

private void setH2oServerExpectedCalls() throws IOException {
    h2oServerMock.expect(requestTo(testH2oServerUrl + getModelRequest)).andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess(prepareModelJavaFile(), MediaType.APPLICATION_OCTET_STREAM));
    h2oServerMock.expect(requestTo(testH2oServerUrl + getLibRequest)).andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess(prepareGenModelLib(), MediaType.APPLICATION_OCTET_STREAM));
}

From source file:com.netflix.genie.web.resources.handlers.GenieResourceHttpRequestHandlerUnitTests.java

/**
 * Make sure we can use the overridden set headers method properly for large file sizes.
 *
 * @throws IOException on error//from   ww  w  .  ja v a  2  s .com
 */
@Test
public void canSetHeaders() throws IOException {
    final HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    final Resource resource = Mockito.mock(Resource.class);
    final MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM;

    final long justRight = (long) Integer.MAX_VALUE;
    final long tooLong = (long) Integer.MAX_VALUE + 1;
    Mockito.when(resource.contentLength()).thenReturn(justRight).thenReturn(tooLong);

    this.handler.setHeaders(response, resource, mediaType);
    this.handler.setHeaders(response, resource, null);

    Mockito.verify(response, Mockito.times(1)).setContentLengthLong(justRight);
    Mockito.verify(response, Mockito.times(1)).setContentLengthLong(tooLong);
    Mockito.verify(response, Mockito.times(1)).setContentType(Mockito.anyString());
}

From source file:org.shaf.server.controller.CmdActionController.java

/**
 * Gets data from the server./*  w  w w  .j a v  a  2  s.co  m*/
 * 
 * @param storage
 *            the resource type.
 * @param alias
 *            the data alias.
 * @return the entity for downloading data.
 * @throws Exception
 *             if an error occurs.
 */
@RequestMapping(value = "/download/{storage}/{alias}", method = RequestMethod.GET)
public @ResponseBody ResponseEntity<InputStreamResource> onDownload(@PathVariable String storage,
        @PathVariable String alias) throws Exception {
    LOG.debug("CALL service: /cmd/download/{" + storage + "}/{" + alias + "}");

    Firewall firewall = super.getFirewall();
    String username = super.getUserName();
    StorageDriver driver = OPER.getStorageDriver(firewall, username, StorageType.CONSUMER, storage);

    HttpHeaders header = new HttpHeaders();
    header.setContentType(MediaType.APPLICATION_OCTET_STREAM);
    header.setContentLength(driver.getLength(alias));
    header.setContentDispositionFormData("attachment", alias);

    return new ResponseEntity<InputStreamResource>(new InputStreamResource(driver.getInputStream(alias)),
            header, HttpStatus.OK);
}

From source file:com.yyl.common.utils.excel.ExcelTools.java

public static ResponseEntity<byte[]> export(ByteArrayOutputStream bOutputStream, String fileName) {
    try {//from w w  w . ja  v  a  2  s  .c  om
        fileName = new String((fileName + DateUtils.formatDate(new Date(), "yyyy-MM-dd") + ".xls").getBytes(),
                "iso-8859-1");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    HttpHeaders headers = new HttpHeaders();
    headers.setContentDispositionFormData("attachment", fileName);
    headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);

    return new ResponseEntity<byte[]>(bOutputStream.toByteArray(), headers, HttpStatus.CREATED);
}

From source file:com.jaspersoft.android.sdk.client.JsRestClient.java

/**
 * Downloads specified report attachment, once a report has been generated, and keeps it in memory as a byte array.
 *
 * @param uuid Universally Unique Identifier. As a side effect of storing the report output in the user session,
 *             the UUID in the URI is visible only to the currently logged in user.
 * @param name One of the file names specified in the report xml. If the file parameter is not specified,
 *             the service returns the report descriptor.
 * @return Attachment file as byte array stored in memory.
 * @throws RestClientException thrown by RestTemplate whenever it encounters client-side HTTP errors
 *///from   w  w  w .ja  v  a 2  s .  c  om
public byte[] getReportAttachment(String uuid, String name) throws RestClientException {
    String fullUri = restServicesUrl + REST_REPORT_URI + "/{uuid}?file={name}";
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAccept(singletonList(MediaType.APPLICATION_OCTET_STREAM));
    ResponseEntity<byte[]> entity = restTemplate.exchange(fullUri, HttpMethod.GET,
            new HttpEntity<byte[]>(requestHeaders), byte[].class, uuid, name);
    return entity.getBody();
}

From source file:cn.edu.henu.rjxy.lms.controller.TeaController.java

@RequestMapping("teacher/download")
public ResponseEntity<byte[]> download(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    String term = request.getParameter("term");
    String courseName = request.getParameter("courseName");
    String workid = request.getParameter("workid");
    String sn = getCurrentUsername();
    String collage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege();
    String teacherName = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName();
    String path = getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/"
            + teacherName + "/" + courseName + "/" + workid + "/"; // 
    String fileNamelast = workid + ".zip";//??
    file(getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/" + teacherName + "/"
            + "");
    String compress = getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/"
            + teacherName + "/" + "" + "/" + fileNamelast;
    //?//from   w ww. j  ava  2s . c om
    ZipCompressor zc = new ZipCompressor(compress);//?   
    zc.compress(path, "", ""); //???
    //?

    File file = new File(compress);
    HttpHeaders headers = new HttpHeaders();
    String fileName = new String(fileNamelast.getBytes("UTF-8"), "iso-8859-1");//???  
    headers.setContentDispositionFormData("attachment", fileName);
    headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
    return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED);
}

From source file:cn.edu.henu.rjxy.lms.controller.TeaController.java

@RequestMapping("teacher/downloadclas")
public ResponseEntity<byte[]> downloadclass(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    String term = request.getParameter("term");
    String courseName = request.getParameter("courseName");
    String workid = request.getParameter("workid");
    String classname = request.getParameter("classname");
    String sn = getCurrentUsername();
    String collage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege();
    String teacherName = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName();
    String path = getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/"
            + teacherName + "/" + courseName + "/" + workid + "/" + classname + "/"; // 
    String fileNamelast = classname + ".zip";//??
    file(getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/" + teacherName + "/"
            + "");
    String compress = getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/"
            + teacherName + "/" + "" + "/" + fileNamelast;
    //?/*w w w .j a v  a2 s . com*/
    ZipCompressor zc = new ZipCompressor(compress);//?   
    zc.compress(path, "", ""); //???
    //?

    File file = new File(compress);
    HttpHeaders headers = new HttpHeaders();
    String fileName = new String(fileNamelast.getBytes("UTF-8"), "iso-8859-1");//???  
    headers.setContentDispositionFormData("attachment", fileName);
    headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
    return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED);
}

From source file:com.oriental.manage.controller.merchant.settleManage.MerchantContranctController.java

@RequestMapping("/downEnclosure")
@RequiresPermissions("org-contaract_down")
public ResponseEntity<byte[]> downEnclosure(String id) {

    try {/*from  w  w w  . j a v a 2  s.  co m*/
        ContractInfo contractInfo = contractService.queryById(id);
        String path = downloadTempDir.concat("/").concat(contractInfo.getCompanyCode()).concat("/");
        FileUtilsExt.writeFile(path);
        String[] pathList = { contractInfo.getDfsBankFile(), contractInfo.getDfsBizLicenseCert(),
                contractInfo.getDfsContAttach(), contractInfo.getDfsOpenBankCert(),
                contractInfo.getDfsOrganizationCodeCert(), contractInfo.getDfsRatePayerCert(),
                contractInfo.getDfsTaxRegisterCert() };
        for (String dfsPath : pathList) {
            if (StringUtils.isNotBlank(dfsPath)) {
                DfsFileInfo dfsFileInfo = new DfsFileInfo();
                dfsFileInfo.setDfsFullFilename(dfsPath);
                List<DfsFileInfo> fileInfoList = iDfsFileInfoService.searchDfsFileInfo(dfsFileInfo);
                if (null != fileInfoList && fileInfoList.size() > 0) {
                    DfsFileInfo dfsFileInfo1 = fileInfoList.get(0);
                    fastDFSPoolUtil.download(dfsFileInfo1.getDfsGroupname(), dfsFileInfo1.getDfsFullFilename(),
                            path.concat(dfsFileInfo1.getLocalFilename()));
                }
            }
        }
        String localFileName = downloadTempDir.concat("/").concat(contractInfo.getCompanyCode())
                .concat("???.zip");
        FileUtilsExt.zipFile(Arrays.asList(new File(path).listFiles()), localFileName);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        headers.setContentDispositionFormData("attachment", new String(
                contractInfo.getCompanyCode().concat("???.zip").getBytes("UTF-8"), "ISO-8859-1"));
        return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(new File(localFileName)), headers,
                HttpStatus.CREATED);
    } catch (Exception e) {
        log.error("", e);
    }
    return null;
}

From source file:com.sitewhere.rest.client.SiteWhereClient.java

protected <S, T> S sendBinary(String url, HttpMethod method, T input, Class<S> clazz, Map<String, String> vars)
        throws SiteWhereSystemException {
    try {/*from   ww w .  ja  v  a  2 s  .  c  o  m*/
        HttpHeaders headers = new HttpHeaders();
        headers.add("Authorization", getAuthHeader());
        headers.add(ISiteWhereWebConstants.HEADER_TENANT_TOKEN, getTenantAuthToken());
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        HttpEntity<T> entity = new HttpEntity<T>(input, headers);
        ResponseEntity<S> response = getClient().exchange(url, method, entity, clazz, vars);
        return response.getBody();
    } catch (ResourceAccessException e) {
        if (e.getCause() instanceof SiteWhereSystemException) {
            throw (SiteWhereSystemException) e.getCause();
        }
        throw new RuntimeException(e);
    }
}

From source file:com.yqboots.fss.web.controller.FileItemController.java

@PreAuthorize(FileItemPermissions.READ)
@RequestMapping(params = { WebKeys.ID, WebKeys.ACTION_DOWNLOAD }, method = RequestMethod.GET)
public HttpEntity<byte[]> download(@RequestParam(WebKeys.ID) final String path) throws IOException {
    return FileWebUtils.downloadFile(fileItemManager.getFullPath(path), MediaType.APPLICATION_OCTET_STREAM);
}