本文整理汇总了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;
}
示例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);
}
示例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();
}
}
示例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;
}
示例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;
}
示例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());
}