I did not test it because I do not have an environment on this computer, but logically it should work as follows: read it as an input stream and let your method return @ResponseBody byte []
@GET @Path("/app") public @ResponseBody byte[] getFullImage(@Context UriInfo info) throws MalformedURLException, IOException { String objectKey = info.getQueryParameters().getFirst("path"); BufferedImage image = resizeImage(300, 300, objectKey); ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", os); InputStream is = new ByteArrayInputStream(os.toByteArray()); return IOUtils.toByteArray(is); }
UPDATE depending on @Habooltak Ana's suggestion there is no need to create an input stream, the code should look like this
@GET @Path("/app") public @ResponseBody byte[] getFullImage(@Context UriInfo info) throws MalformedURLException, IOException { String objectKey = info.getQueryParameters().getFirst("path"); BufferedImage image = resizeImage(300, 300, objectKey); ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", os); return os.toByteArray(); }
source share