Thumbnails.of(new InputStream[] { new ByteArrayInputStream(original) }).size(w, h).toOutputStream(baos);
@RequestMapping({"/image"})
public void image(HttpServletResponse resp, @RequestParam(value="path", defaultValue="") String filePath, @RequestParam(value="group", defaultValue="") String group, @RequestParam(value="w", defaultValue="") Integer width, @RequestParam(value="h", defaultValue="") Integer height, @RequestParam(value="type", defaultValue="") String compressType)
{
logger.debug("loading img file '{}'", filePath);
if (StringUtils.isEmpty(filePath))
{
resp.setStatus(404);
return;
}
boolean successed = false;
FastdfsStorage storage = null;
try
{
storage = this.fastdfsContext.getStorage();
byte[] bytes = storage.downFile(group, filePath);
if (bytes != null)
{
if ((width != null) && (height != null) && (width.intValue() >= 0) && (height.intValue() >= 0)) {
bytes = DefaultImageCompresserFactory.get(compressType).deal(bytes, width.intValue(), height.intValue());
}
resp.setHeader("Content-Length", Integer.toString(bytes.length));
resp.getOutputStream().write(bytes);
successed = true;
}
}
catch (FastdfsException e)
{
logger.debug("loading fastdfs file group#'{}' file#'{}' fail", new Object[] { group, filePath, e });
}
catch (IOException e)
{
logger.debug("response write error : {}", e.getMessage(), e);
}
catch (CompressException e)
{
logger.debug("image bytes compress fail ", e);
}
finally
{
if (storage != null) {
storage.close();
}
}
if (!successed) {
resp.setStatus(404);
}
}