コード例 #1
0
  @Async
  @Override
  public void processImage(URI uri) throws Exception {
    File image = fileService.get(uri);
    final BufferedImage bufferedImage = ImageIO.read(image);

    for (ImageStyle imageStyle : imageStyles.values()) {
      BufferedImage styledImage = imageStyle.process(bufferedImage);
      File imageFile = fileService.create(buildGeneratedImagePath(imageStyle, uri));
      ImageIO.write(styledImage, FilenameUtils.getExtension(image.getName()), imageFile);
    }
  }
コード例 #2
0
ファイル: FileServiceTest.java プロジェクト: edenduthie/pals
  @Test
  public void saveFile() throws IOException {
    File file = new File(filename);
    Assert.assertTrue(file.exists());
    File copy = new File(copyFilename);
    FileUtils.copyFile(file, copy);

    PalsFile palsFile = fileService.createFile(copy);
    fileService.save(palsFile);
    palsFile = fileService.get(palsFile.getId());

    Assert.assertEquals(palsFile.getData().length(), 10314752);
    Assert.assertFalse(copy.exists());

    InputStream is = new FileInputStream(file);
    byte[] buffer = new byte[palsFile.getData().length()];
    is.read(buffer, 0, buffer.length);
    for (int i = 0; i < buffer.length; ++i) {
      Assert.assertEquals(buffer[i], palsFile.getData().getData()[i]);
    }
    is.close();

    fileService.deleteFile(palsFile);
  }