当前位置: 首页>>代码示例>>Java>>正文


Java MediaType.APPLICATION_OCTET_STREAM_VALUE属性代码示例

本文整理汇总了Java中org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE属性的典型用法代码示例。如果您正苦于以下问题:Java MediaType.APPLICATION_OCTET_STREAM_VALUE属性的具体用法?Java MediaType.APPLICATION_OCTET_STREAM_VALUE怎么用?Java MediaType.APPLICATION_OCTET_STREAM_VALUE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.springframework.http.MediaType的用法示例。


在下文中一共展示了MediaType.APPLICATION_OCTET_STREAM_VALUE属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDown

@RequestMapping(value = "/test2.xlsx", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
byte[] testDown() throws IOException, InvalidFormatException {
    Workbook workbook = new SXSSFWorkbook();
    Sheet sheet = workbook.createSheet();
    for (int i = 0; i < 60000; i++) {
        Row newRow = sheet.createRow(i);
        for (int j = 0; j < 100; j++) {
            newRow.createCell(j).setCellValue("test" + Math.random());
        }
    }
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    workbook.write(os);
    byte[] bytes = os.toByteArray();
    return bytes;
}
 
开发者ID:Yuiffy,项目名称:file-download-upload-zip-demo,代码行数:16,代码来源:FileController.java

示例2: download

@RequestMapping(method = POST, path = "/download", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public void download(HttpServletResponse res, @RequestParam String url) throws IOException, InterruptedException, TimeoutException {
    URL target = new URL(url);
    String filename = mtdl.download(target);
    File file = new File(filename);

    res.setHeader("Content-disposition", "attachment; filename=\"" + filename + "\"");
    res.setContentLengthLong(FileUtils.sizeOf(file));
    IOUtils.copy(new FileInputStream(filename), res.getOutputStream());
    res.flushBuffer();

    FileUtils.deleteQuietly(file);
}
 
开发者ID:kamax-io,项目名称:mytube-dl,代码行数:13,代码来源:DownloadController.java

示例3: get

@RequestMapping(value = "/files/{uuid:[\\w-]{36}}", method = RequestMethod.GET, produces = {MediaType.APPLICATION_OCTET_STREAM_VALUE})
public void get(@PathVariable(name = "uuid") String uuid, HttpServletResponse resp) throws IOException {
	net.bndy.wf.modules.core.models.File f = this.fileService.getByUuid(uuid);
	if (f != null && this.applicationConfig.getUploadPath() != null && !applicationConfig.getUploadPath().isEmpty()) {
		String filePath = Paths.get(this.applicationConfig.getUploadPath(), f.getPath()).toAbsolutePath().toString();
		FileCopyUtils.copy(new FileInputStream(filePath), resp.getOutputStream());
		resp.flushBuffer();
	}
}
 
开发者ID:bndynet,项目名称:web-framework-for-java,代码行数:9,代码来源:HomeController.java

示例4: downloadLogFile

@CsapDoc ( notes = {
		"Download service log file.",
		"Note: agent api only."
} , linkTests = {
		"CsAgent Warnings"
} , linkPostParams = {
		USERID_PASS_PARAMS
				+ "serviceName_port=CsAgent_8011,fileName=warnings.log"
} )
@RequestMapping ( value = "/service/log/download" , produces = MediaType.APPLICATION_OCTET_STREAM_VALUE )
public FileSystemResource downloadLogFile (
											@RequestParam ( "serviceName_port" ) String serviceName_port,
											@RequestParam ( "fileName" ) String fileName,
											@RequestParam ( SpringAuthCachingFilter.USERID ) String userid,
											@RequestParam ( SpringAuthCachingFilter.PASSWORD ) String inputPass,
											HttpServletResponse response ) {

	logger.info( "{} Downloading {} file: {}", userid, serviceName_port, fileName );

	// Hook since tomcat chokes on urlencoded /
	File logFileRequested = new File( csapApp.getLogDir( serviceName_port ) + "/"
			+ fileName.replaceAll( "_slash_", "/" ) );

	if ( !logFileRequested.exists() ) {
		throw new RuntimeException( "File not found" + logFileRequested.getAbsolutePath() );
	}
	// HttpServletResponse response
	// String mt = new
	// MimetypesFileTypeMap().getContentType(logFileRequested);

	// logger.info("File type: {}" , mt) ;
	response.setHeader( "Content-Disposition", "attachment;filename=" + fileName );
	FileSystemResource theFile = new FileSystemResource( logFileRequested );

	return theFile;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:36,代码来源:AgentApi.java

示例5: downloadServiceFile

@CsapDoc ( notes = {
		"/service/file/download - download files from the service folder in $PROCESSING",
		"Note: agent api only."
} , linkTests = {
		"CsAgent start file"
} , linkPaths = {
		"/service/file/download"
} , linkPostParams = {
		USERID_PASS_PARAMS
				+ "serviceName_port=CsAgent_8011,fileName=CsAgent_8011_start.log"
} )
@RequestMapping ( value = "/service/file/download" , produces = MediaType.APPLICATION_OCTET_STREAM_VALUE )
public FileSystemResource downloadServiceFile (
												@RequestParam ( "serviceName_port" ) String serviceName_port,
												@RequestParam ( "fileName" ) String fileName,
												@RequestParam ( SpringAuthCachingFilter.USERID ) String userid,
												@RequestParam ( SpringAuthCachingFilter.PASSWORD ) String inputPass,
												HttpServletResponse response ) {

	logger.info( "{} Downloading {} file: {}", userid, serviceName_port, fileName );

	// Hook since tomcat chokes on urlencoded /
	File serviceFile = new File( csapApp.getWorkingDirectory( serviceName_port ) + "/"
			+ fileName.replaceAll( "_slash_", "/" ) );

	if ( !serviceFile.exists() ) {
		throw new RuntimeException( "File not found: " + serviceFile.getAbsolutePath() );
	}

	response.setHeader( "Content-Disposition", "attachment;filename=" + fileName );
	FileSystemResource theFile = new FileSystemResource( serviceFile );

	return theFile;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:34,代码来源:AgentApi.java

示例6: responseOctetStream

@GetMapping(value = "/get/octetStream", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<InputStream> responseOctetStream() throws IOException {
  File tmpFile = new File("/tmp/" + UUID.randomUUID().toString() + ".log");
  tmpFile.createNewFile();
  Path path = Paths.get(tmpFile.getAbsolutePath());
  ByteArrayResource resource = new ByteArrayResource(Files.readAllBytes(path));
  return ResponseEntity.ok()
      .contentLength(tmpFile.length())
      .contentType(MediaType.parseMediaType("application/octet-stream"))
      .body(resource.getInputStream());
}
 
开发者ID:lord-of-code,项目名称:loc-framework,代码行数:11,代码来源:LocAccessLogTest.java


注:本文中的org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。