Java Code Examples for org.springframework.http.MediaType#APPLICATION_OCTET_STREAM_VALUE

The following examples show how to use org.springframework.http.MediaType#APPLICATION_OCTET_STREAM_VALUE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegistryAPI.java    From openvsx with Eclipse Public License 2.0 6 votes vote down vote up
@PostMapping(
    path = "/api/-/publish",
    consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE,
    produces = MediaType.APPLICATION_JSON_VALUE
)
public ExtensionJson publish(InputStream content,
                             @RequestParam String token) {
    try {
        return local.publish(content, token);
    } catch (ErrorResultException exc) {
        return ExtensionJson.error(exc.getMessage());
    }
}
 
Example 2
Source File: ImageGalleryController.java    From fredbet with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
@GetMapping(value = "/download/all", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<byte[]> downloadAllImagesAsZip() {
    final String zipFileName = "allImages.zip";
    byte[] zipFile = downloadService.downloadAllImagesAsZipFile();
    if (zipFile == null) {
        return ResponseEntity.notFound().build();
    }

    return ResponseEntity.ok().header("Content-Type", MediaType.APPLICATION_OCTET_STREAM_VALUE)
            .header("Content-Disposition", "inline; filename=\"" + zipFileName + "\"").body(zipFile);
}
 
Example 3
Source File: BackupController.java    From halo with GNU General Public License v3.0 6 votes vote down vote up
@GetMapping("work-dir/{fileName:.+}")
@ApiOperation("Downloads a work directory backup file")
@DisableOnCondition
public ResponseEntity<Resource> downloadBackup(@PathVariable("fileName") String fileName, HttpServletRequest request) {
    log.info("Try to download backup file: [{}]", fileName);

    // Load file as resource
    Resource backupResource = backupService.loadFileAsResource(haloProperties.getBackupDir(), fileName);

    String contentType = MediaType.APPLICATION_OCTET_STREAM_VALUE;
    // Try to determine file's content type
    try {
        contentType = request.getServletContext().getMimeType(backupResource.getFile().getAbsolutePath());
    } catch (IOException e) {
        log.warn("Could not determine file type", e);
        // Ignore this error
    }

    return ResponseEntity.ok()
        .contentType(MediaType.parseMediaType(contentType))
        .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + backupResource.getFilename() + "\"")
        .body(backupResource);
}
 
Example 4
Source File: BackupController.java    From halo with GNU General Public License v3.0 6 votes vote down vote up
@GetMapping("data/{fileName:.+}")
@ApiOperation("Downloads a exported data")
@DisableOnCondition
public ResponseEntity<Resource> downloadExportedData(@PathVariable("fileName") String fileName, HttpServletRequest request) {
    log.info("Try to download exported data file: [{}]", fileName);

    // Load exported data as resource
    Resource exportDataResource = backupService.loadFileAsResource(haloProperties.getDataExportDir(), fileName);

    String contentType = MediaType.APPLICATION_OCTET_STREAM_VALUE;
    // Try to determine file's content type
    try {
        contentType = request.getServletContext().getMimeType(exportDataResource.getFile().getAbsolutePath());
    } catch (IOException e) {
        log.warn("Could not determine file type", e);
    }

    return ResponseEntity.ok()
        .contentType(MediaType.parseMediaType(contentType))
        .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + exportDataResource.getFilename() + "\"")
        .body(exportDataResource);
}
 
Example 5
Source File: RestComponents.java    From NFVO with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new Service. This generates a new AES Key that can be used for registering the
 * Service.
 *
 * @param projectId
 * @param serviceCreateBody
 * @return
 * @throws IOException
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeySpecException
 */
@ApiOperation(
    value = "Create Service",
    notes =
        "Enable a new Service. This generates a new AES Key that must be used in the Service SDK")
@RequestMapping(
    value = "/services/create",
    method = RequestMethod.POST,
    consumes = MediaType.APPLICATION_JSON_VALUE,
    produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseStatus(HttpStatus.CREATED)
@PreAuthorize("hasAnyRole('ROLE_ADMIN')")
public String createService(
    @RequestHeader(value = "project-id") String projectId,
    @RequestBody @Valid ServiceCreateBody serviceCreateBody)
    throws NotFoundException, MissingParameterException {
  String serviceName = serviceCreateBody.getName();
  List<String> projects = serviceCreateBody.getRoles();
  return componentManager.createService(serviceName, projectId, projects);
}
 
Example 6
Source File: HelloController.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@PostMapping(value = "/files", produces = { MediaType.APPLICATION_JSON_VALUE}, consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
@Operation(summary = "files")
public Flux<Void> handleFileUpload(
		@RequestPart("files") @Parameter(description = "files",
				content = @Content(mediaType = MediaType.APPLICATION_OCTET_STREAM_VALUE))
				Flux<FilePart> filePartFux) throws IOException {
	File tmp = File.createTempFile("tmp", "");
	return filePartFux.flatMap(filePart -> {
		Path path = Paths.get(tmp.toString() + filePart.filename());
		System.out.println(path);
		return filePart.transferTo(path);
	});
}
 
Example 7
Source File: TestController.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@PutMapping(value = "/1", consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public byte[] response(@RequestBody byte[] requestBody) {
	if (!Arrays.equals(this.request, requestBody)) {
		throw new IllegalStateException("Invalid request body");
	}
	return this.response;
}
 
Example 8
Source File: DownloadController.java    From cymbal with Apache License 2.0 5 votes vote down vote up
@GetMapping(value = "/download/{fileName}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
public InputStreamSource downloadTemplate(final HttpServletRequest request, final HttpServletResponse response,
        @PathVariable String fileName) {
    if ("Template".equalsIgnoreCase(fileName)) {
        response.setHeader("Content-Disposition", "attachment;filename=node-upload-template.xlsx");
        return new InputStreamResource(this.getFileInputStream("static/doc/node-upload-template.xlsx"));
    } else if ("help-doc".equalsIgnoreCase(fileName)) {
        response.setHeader("Content-Disposition", "attachment;filename=cymbal-manual.docx");
        return new InputStreamResource(this.getFileInputStream("static/doc/cymbal-manual.docx"));
    }
    return null;
}
 
Example 9
Source File: ResourceController.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/{name}/{profile}/**", params = "useDefaultLabel",
		produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public byte[] binary(@PathVariable String name, @PathVariable String profile,
		ServletWebRequest request) throws IOException {
	String path = getFilePath(request, name, profile, null);
	return binary(request, name, profile, null, path);
}
 
Example 10
Source File: RestMain.java    From NFVO with Apache License 2.0 5 votes vote down vote up
@RequestMapping(
    value = "openbaton-rc",
    method = RequestMethod.GET,
    produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public String getOpenRCFile(@RequestHeader("project-id") String projectId)
    throws NotFoundException {
  return getOpenRcFile(projectId);
}
 
Example 11
Source File: MiddlewareResource.java    From heimdall with Apache License 2.0 5 votes vote down vote up
/**
 * Saves a {@link Middleware}.
 *
 * @param apiId				The Api Id
 * @param file					{@link MultipartFile} of the Api
 * @param middlewareDTO		{@link MiddlewareDTO}
 * @return						{@link ResponseEntity}
 */
@ResponseBody
@ApiOperation(value = "Save a new Middleware")
@PostMapping(consumes = {MediaType.APPLICATION_JSON_UTF8_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_OCTET_STREAM_VALUE })
@PreAuthorize(ConstantsPrivilege.PRIVILEGE_CREATE_MIDDLEWARE)
public ResponseEntity<?> save(@PathVariable("apiId") Long apiId,
          @RequestParam("file") MultipartFile file,
          @Valid
          MiddlewareDTO middlewareDTO) {

     Middleware middleware = middlewareService.save(apiId, middlewareDTO, file);

     return ResponseEntity.created(URI.create(String.format("/%s/%s/%s/%s", "api", apiId.toString(), "middlewares", middleware.getId().toString()))).build();
}
 
Example 12
Source File: MiddlewareResource.java    From heimdall with Apache License 2.0 5 votes vote down vote up
/**
 * Downloads a {@link Middleware} file by its Id and {@link Api} Id.
 *
 * @param apiId				The Api Id
 * @param middlewareId			The Middleware Id
 * @return						{@link ResponseEntity}
 */
@ApiOperation(value = "Download Middleware file by id", response = Api.class)
@GetMapping(value = "/download/{middlewareId}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@PreAuthorize(ConstantsPrivilege.PRIVILEGE_READ_MIDDLEWARE)
public ResponseEntity<?> downloadFileById(@PathVariable("apiId") Long apiId, @PathVariable("middlewareId") Long middlewareId){

     Middleware middleware = middlewareService.find(apiId, middlewareId);
     ByteArrayResource resource = new ByteArrayResource(middleware.getFile());

     return ResponseEntity.ok()
             .contentType(MediaType.APPLICATION_OCTET_STREAM)
             .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + middleware.getName() + "-" +  middleware.getVersion() + "." + middleware.getType())
             .header("filename", middleware.getName() + "-" +  middleware.getVersion() + "." + middleware.getType())
             .body(resource);
}
 
Example 13
Source File: FunctionController.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
@PostMapping(path = "/**", consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> post(ServerWebExchange request) {
	FunctionWrapper wrapper = wrapper(request);
	return this.processor.post(wrapper, request);
}
 
Example 14
Source File: JobRestControllerIntegrationTest.java    From genie with Apache License 2.0 4 votes vote down vote up
@Test
void canSubmitJobWithAttachments() throws Exception {
    Assumptions.assumeTrue(SystemUtils.IS_OS_UNIX);

    final List<ClusterCriteria> clusterCriteriaList = Lists.newArrayList(
        new ClusterCriteria(Sets.newHashSet(LOCALHOST_CLUSTER_TAG))
    );

    final String setUpFile = this.getResourceURI(BASE_DIR + "job" + FILE_DELIMITER + "jobsetupfile");

    final File attachment1File = this.resourceLoader
        .getResource(BASE_DIR + "job/query.sql")
        .getFile();

    final MockMultipartFile attachment1;
    try (InputStream is = new FileInputStream(attachment1File)) {
        attachment1 = new MockMultipartFile(
            "attachment",
            attachment1File.getName(),
            MediaType.APPLICATION_OCTET_STREAM_VALUE,
            is
        );
    }

    final File attachment2File = this.resourceLoader
        .getResource(BASE_DIR + "job/query2.sql")
        .getFile();

    final MockMultipartFile attachment2;
    try (InputStream is = new FileInputStream(attachment2File)) {
        attachment2 = new MockMultipartFile(
            "attachment",
            attachment2File.getName(),
            MediaType.APPLICATION_OCTET_STREAM_VALUE,
            is
        );
    }
    final Set<String> commandCriteria = Sets.newHashSet(BASH_COMMAND_TAG);
    final JobRequest jobRequest = new JobRequest.Builder(
        JOB_NAME,
        JOB_USER,
        JOB_VERSION,
        clusterCriteriaList,
        commandCriteria
    )
        .withCommandArgs(SLEEP_AND_ECHO_COMMAND_ARGS)
        .withDisableLogArchival(true)
        .withSetupFile(setUpFile)
        .withDescription(JOB_DESCRIPTION)
        .build();

    this.waitForDone(this.submitJob(4, jobRequest, Lists.newArrayList(attachment1, attachment2)));
}
 
Example 15
Source File: RequestMonitor.java    From curl with The Unlicense 4 votes vote down vote up
@RequestMapping (value = "/public/data", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE, method = RequestMethod.POST)
@ResponseStatus (code = HttpStatus.OK)
@ResponseBody
public byte[] data (final HttpServletRequest request) throws IOException {
    return this.logRequest (request, IOUtils.toString (request.getInputStream ())).getBytes ();
}
 
Example 16
Source File: IResourceVersioning.java    From entando-components with GNU Lesser General Public License v3.0 4 votes vote down vote up
@ApiOperation(value = "GET trashed resource", nickname = "deleteTrashedResource", tags = {
        "resource-versioning-controller"})
@GetMapping(value = "/{resourceId}/{size}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@RestAccessControl(permission = Permission.CONTENT_EDITOR)
ResponseEntity getTrashedResource(@PathVariable(value = "resourceId") String resourceId,
        @PathVariable(value = "size") Integer size);
 
Example 17
Source File: JettyClientHttpRequest.java    From java-technology-stack with MIT License 4 votes vote down vote up
private String getContentType() {
	MediaType contentType = getHeaders().getContentType();
	return contentType != null ? contentType.toString() : MediaType.APPLICATION_OCTET_STREAM_VALUE;
}
 
Example 18
Source File: DataProducerController.java    From tutorials with MIT License 4 votes vote down vote up
@GetMapping(value = "/get-file", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public @ResponseBody byte[] getFile() throws IOException {
    final InputStream in = getClass().getResourceAsStream("/com/baeldung/produceimage/data.txt");
    return IOUtils.toByteArray(in);
}
 
Example 19
Source File: ExampleController.java    From logbook with MIT License 4 votes vote down vote up
@RequestMapping(path = "/binary", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<String> binary() {
    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
    return new ResponseEntity<>("Hello", headers, HttpStatus.OK);
}
 
Example 20
Source File: JettyClientHttpRequest.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private String getContentType() {
	MediaType contentType = getHeaders().getContentType();
	return contentType != null ? contentType.toString() : MediaType.APPLICATION_OCTET_STREAM_VALUE;
}