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

The following examples show how to use org.springframework.http.MediaType#IMAGE_PNG_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: ServerController.java    From MapServer with GNU General Public License v3.0 6 votes vote down vote up
@RequestMapping(
        value = "/map/{type}/{x}/{y}/{z}",
        method = RequestMethod.GET,
        produces = { MediaType.IMAGE_JPEG_VALUE, MediaType.IMAGE_GIF_VALUE, MediaType.IMAGE_PNG_VALUE}
        )
public byte[] initMap(@PathVariable Integer x, @PathVariable Integer y,
                    @PathVariable Integer z, @PathVariable String type) throws IOException
{
    String path = InitUtils.getPathByType(InitUtils.getTypeByName(type));

    String imgPath = path + z + "/" + x + "/" + y + "/img.jpg";
    File file = new File(imgPath);
    FileInputStream inputStream = new FileInputStream(file);
    byte[] data = new byte[(int)file.length()];
    inputStream.read(data);
    inputStream.close();

    return data;
}
 
Example 2
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/node_threads.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] nodeDispatcherThreads() throws IOException {

    final String path = rrdPath(THREAD_RRD);
    final RrdGraphDef graphDef = baseGraph("Node Dispatcher Queue", "threads/sec");

    graphDef.datasource("threads", path, "nodeActiveThreads", ConsolFun.AVERAGE);
    graphDef.datasource("queue", path, "nodeWaiting", ConsolFun.AVERAGE);

    graphDef.line("threads", new Color(152, 175, 54), "Active Threads");
    graphDef.area("queue", new Color(74, 104, 15), "Queued Work");

    graphDef.comment("\\r");

    graphDef.gprint("threads", MAX, "Max Threads = %.3f%S");
    graphDef.gprint("threads", AVERAGE, "Avg Threads = %.3f%S\n");

    graphDef.gprint("queue", MAX, "Max Queued = %.3f%s");
    graphDef.gprint("queue", AVERAGE, "Avg Queued = %.3f%S\n");

    return createImage(graphDef);
}
 
Example 3
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/job_launch.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] jobLaunchGraph() throws IOException {

    final String path = rrdPath(PLOW_RRD);
    final RrdGraphDef graphDef = baseGraph("Job Launch", "jobs/sec");

    graphDef.datasource("linea", path, "jobLaunchCount", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "jobLaunchFailCount", ConsolFun.AVERAGE);
    graphDef.datasource("linec", path, "jobFinishCount", ConsolFun.AVERAGE);
    graphDef.datasource("lined", path, "jobKillCount", ConsolFun.AVERAGE);
    graphDef.area("linea", new Color(8, 175, 193), "Launched");
    graphDef.stack("linec", new Color(133, 225, 224), "Finished");
    graphDef.line("lineb", new Color(241, 93, 5), "Launch Fail", 2);
    graphDef.line("lined",  new Color(243, 165, 41), "Jobs Killed", 2);

    return createImage(graphDef);
}
 
Example 4
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/task_exec.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] taskCountsGraph() throws IOException {

    final String path = rrdPath(PLOW_RRD);
    final RrdGraphDef graphDef = baseGraph("Task Executions", "task/sec");

    graphDef.datasource("linea", path, "taskStartedCount", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "taskStartedFailCount", ConsolFun.AVERAGE);
    graphDef.datasource("linec", path, "taskStoppedCount", ConsolFun.AVERAGE);
    graphDef.datasource("lined", path, "taskStoppedFailCount", ConsolFun.AVERAGE);
    graphDef.area("linea", new Color(8, 175, 193), "Started");
    graphDef.stack("linec", new Color(133, 225, 224), "Stopped");
    graphDef.line("lineb", new Color(243, 165, 41), "Error Started", 2);
    graphDef.line("lined", new Color(241, 93, 5), "Error Stopped", 2);

    return createImage(graphDef);
}
 
Example 5
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/proc_dsp.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] procDispatcherStatsGraph() throws IOException {

    final String path = rrdPath(PLOW_RRD);
    final RrdGraphDef graphDef = baseGraph("Proc Dispatcher Traffic", "dps/sec");

    graphDef.datasource("linea", path, "procDispatchHit", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "procDispatchMiss", ConsolFun.AVERAGE);
    graphDef.datasource("linec", path, "procDispatchFail", ConsolFun.AVERAGE);
    graphDef.area("linea", new Color(152, 175, 54), "Hit");
    graphDef.area("lineb", new Color(74, 104, 15), "Miss");
    graphDef.area("linec", new Color(164, 11, 23), "Error");

    return createImage(graphDef);
}
 
Example 6
Source File: CaseDefinitionImageResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get a case definition image", tags = { "Case Definitions" })
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates request was successful and the case definitions are returned"),
        @ApiResponse(code = 404, message = "Indicates the requested case definition was not found.")
})
@GetMapping(value = "/cmmn-repository/case-definitions/{caseDefinitionId}/image", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<byte[]> getImageResource(@ApiParam(name = "caseDefinitionId") @PathVariable String caseDefinitionId) {
    CaseDefinition caseDefinition = getCaseDefinitionFromRequest(caseDefinitionId);
    InputStream imageStream = repositoryService.getCaseDiagram(caseDefinition.getId());

    if (imageStream != null) {
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.set("Content-Type", MediaType.IMAGE_PNG_VALUE);
        try {
            return new ResponseEntity<>(IOUtils.toByteArray(imageStream), responseHeaders, HttpStatus.OK);
        } catch (Exception e) {
            throw new FlowableException("Error reading image stream", e);
        }
    } else {
        throw new FlowableObjectNotFoundException("Case definition with id '" + caseDefinition.getId() + "' has no image.");
    }
}
 
Example 7
Source File: RrdGraphController.java    From plow with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/node_dsp.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] nodeDispatcherStatsGraph() throws IOException {

    final String path = rrdPath(PLOW_RRD);
    final RrdGraphDef graphDef = baseGraph("Node Dispatcher Traffic", "dps/sec");

    graphDef.datasource("linea", path, "nodeDispatchHit", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "nodeDispatchMiss", ConsolFun.AVERAGE);
    graphDef.datasource("linec", path, "nodeDispatchFail", ConsolFun.AVERAGE);
    graphDef.area("linea", new Color(152, 175, 54), "Hit");
    graphDef.area("lineb", new Color(74, 104, 15), "Miss");
    graphDef.area("linec", new Color(164, 11, 23), "Error");

    return createImage(graphDef);
}
 
Example 8
Source File: AvatarApiController.java    From lemon with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "{username}", produces = MediaType.IMAGE_PNG_VALUE)
public void avatar(
        @PathVariable("username") String username,
        @RequestParam(value = "width", required = false, defaultValue = "16") int width,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    String tenantId = tenantHolder.getTenantId();

    InputStream is = userAvatarService.viewAvatarByUsername(username,
            width, tenantId).getInputStream();

    response.setContentType("image/png");
    IOUtils.copy(is, response.getOutputStream());
}
 
Example 9
Source File: UserMvcTests.java    From jakduk-api with MIT License 5 votes vote down vote up
@Test
@WithMockUser
public void uploadUserPictureTest() throws Exception {

    UserPicture expectUserPicture = new UserPicture();
    expectUserPicture.setId(userPicture.getId());
    expectUserPicture.setStatus(Constants.GALLERY_STATUS_TYPE.TEMP);
    expectUserPicture.setContentType(userPicture.getContentType());

    when(userService.uploadUserPicture(anyString(), anyLong(), anyObject()))
            .thenReturn(expectUserPicture);

    byte[] ballBytes = new byte[]{
            (byte) 0x89, (byte) 0x50, (byte) 0x4e, (byte) 0x47, (byte) 0x0d, (byte) 0x0a, (byte) 0x1a, (byte) 0x0a, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0x0d, (byte) 0x49, (byte) 0x48, (byte) 0x44, (byte) 0x52, (byte) 0x00, (byte) 0x00
    };

    MockMultipartFile mockMultipartFile = new MockMultipartFile("file", "sample.png", MediaType.IMAGE_PNG_VALUE, ballBytes);

    mvc.perform(
            fileUpload("/api/user/picture")
                    .file(mockMultipartFile)
                    .with(csrf()))
            .andExpect(status().isOk())
            .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
            .andExpect(content().json(ObjectMapperUtils.writeValueAsString(expectUserPicture)))
            .andDo(
                    document("user-upload-picture",
                            requestParts(
                                    partWithName("file").description("멀티 파트 객체")
                            ),
                            responseFields(
                                    fieldWithPath("id").type(JsonFieldType.STRING).description("그림 ID"),
                                    fieldWithPath("status").type(JsonFieldType.STRING).description("그림 상태. " +
                                            Stream.of(Constants.GALLERY_STATUS_TYPE.values()).map(Enum::name).collect(Collectors.toList())),
                                    fieldWithPath("contentType").type(JsonFieldType.STRING).description("Content-Type. image/* 만 가능하다.")
                            )
                    ));
}
 
Example 10
Source File: RrdGraphController.java    From plow with Apache License 2.0 5 votes vote down vote up
@ResponseBody
@RequestMapping(value="/monitor/graphs/async_threads.png", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
public byte[] asyncWorkQueueThreads() throws IOException {

    final String path = rrdPath(THREAD_RRD);
    final RrdGraphDef graphDef = baseGraph("Async Work Queue", "threads/sec");

    graphDef.datasource("linea", path, "asyncActiveThreads", ConsolFun.AVERAGE);
    graphDef.datasource("lineb", path, "asyncWaiting", ConsolFun.AVERAGE);
    graphDef.area("lineb", new Color(74, 104, 15), "Queued Work");
    graphDef.line("linea", new Color(152, 175, 54), "Active Threads");

    return createImage(graphDef);
}
 
Example 11
Source File: TestController.java    From jframework with Apache License 2.0 5 votes vote down vote up
@GetMapping(value = "/image", produces = MediaType.IMAGE_PNG_VALUE)
public void getImage(HttpServletResponse response) throws IOException {
    try (FileInputStream fileInputStream = new FileInputStream(new File("src/main/resources/1.png"))) {
        response.setContentType(MediaType.IMAGE_PNG_VALUE);
        StreamUtils.copy(fileInputStream, response.getOutputStream());
    }
}
 
Example 12
Source File: BarcodesController.java    From tutorials with MIT License 4 votes vote down vote up
@GetMapping(value = "/barcode4j/upca/{barcode}", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> barcode4jUPCABarcode(@PathVariable("barcode") String barcode) {
    return okResponse(Barcode4jBarcodeGenerator.generateUPCABarcodeImage(barcode));
}
 
Example 13
Source File: BarcodesController.java    From tutorials with MIT License 4 votes vote down vote up
@PostMapping(value = "/barbecue/code128", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> barbecueCode128Barcode(@RequestBody String barcode) throws Exception {
    return okResponse(BarbecueBarcodeGenerator.generateCode128BarcodeImage(barcode));
}
 
Example 14
Source File: ApiModelResource.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * GET /editor/models/{modelId}/thumbnail -> Get process model thumbnail
 */
@GetMapping(value = "/editor/models/{modelId}/thumbnail", produces = MediaType.IMAGE_PNG_VALUE)
public byte[] getModelThumbnail(@PathVariable String modelId) {
    Model model = modelService.getModel(modelId);
    return model.getThumbnail();
}
 
Example 15
Source File: BarcodesController.java    From tutorials with MIT License 4 votes vote down vote up
@PostMapping(value = "/zxing/qrcode", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> zxingQRCode(@RequestBody String barcode) throws Exception {
    return okResponse(ZxingBarcodeGenerator.generateQRCodeImage(barcode));
}
 
Example 16
Source File: BarcodesController.java    From tutorials with MIT License 4 votes vote down vote up
@PostMapping(value = "/zxing/pdf417", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> zxingPDF417Barcode(@RequestBody String barcode) throws Exception {
    return okResponse(ZxingBarcodeGenerator.generatePDF417BarcodeImage(barcode));
}
 
Example 17
Source File: ModelResource.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * GET /rest/models/{modelId}/thumbnail -> Get process model thumbnail
 */
@RequestMapping(value = "/rest/models/{modelId}/thumbnail", method = RequestMethod.GET, produces = MediaType.IMAGE_PNG_VALUE)
public byte[] getModelThumbnail(@PathVariable String modelId) {
  return super.getModelThumbnail(modelId);
}
 
Example 18
Source File: BarcodesController.java    From tutorials with MIT License 4 votes vote down vote up
@PostMapping(value = "/zxing/code128", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> zxingCode128Barcode(@RequestBody String barcode) throws Exception {
    return okResponse(ZxingBarcodeGenerator.generateCode128BarcodeImage(barcode));
}
 
Example 19
Source File: KnoteJavaApplication.java    From knote-java with Apache License 2.0 4 votes vote down vote up
@GetMapping(value = "/img/{name}", produces = MediaType.IMAGE_PNG_VALUE)
public @ResponseBody byte[] getImageByName(@PathVariable String name) throws Exception {
    InputStream imageStream = minioClient.getObject(properties.getMinioBucket(), name);
    return IOUtils.toByteArray(imageStream);
}
 
Example 20
Source File: BarcodesController.java    From tutorials with MIT License 4 votes vote down vote up
@GetMapping(value = "/zxing/upca/{barcode}", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> zxingUPCABarcode(@PathVariable("barcode") String barcode) throws Exception {
    return okResponse(ZxingBarcodeGenerator.generateUPCABarcodeImage(barcode));
}