/** * Writes the contents from a byte array to a file. * * @param pFilename The name of the file to write to * @param pData The byte array to write * @return {@code true}, otherwise an IOException is thrown. * @throws IOException if an i/o error occurs during write. */ public static boolean write(String pFilename, byte[] pData) throws IOException { return write(new File(pFilename), pData); }
/** * Writes the contents from a byte array to a file. * * @param pFile The file to write to * @param pData The byte array to write * @return {@code true}, otherwise an IOException is thrown. * @throws IOException if an i/o error occurs during write. */ public static boolean write(File pFile, byte[] pData) throws IOException { boolean success = false; OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(pFile)); success = write(out, pData); } finally { close(out); } return success; }
@Test public void testSplit() throws IOException { InputStream inputStream = getClassLoaderResource("/contrib/tiff/multipage.tif").openStream(); File inputFile = File.createTempFile("imageiotest", "tif"); byte[] data = FileUtil.read(inputStream); FileUtil.write(inputFile, data); inputStream.close(); File outputDirectory = Files.createTempDirectory("imageio").toFile(); TIFFUtilities.split(inputFile, outputDirectory); ImageReader reader = ImageIO.getImageReadersByFormatName("TIF").next(); File[] outputFiles = outputDirectory.listFiles(); Assert.assertEquals(3, outputFiles.length); for (File outputFile : outputFiles) { ImageInputStream iis = ImageIO.createImageInputStream(outputFile); reader.setInput(iis); Assert.assertEquals(1, reader.getNumImages(true)); iis.close(); outputFile.delete(); } outputDirectory.delete(); inputFile.delete(); }
@Test public void testApplyOrientation() throws IOException { InputStream inputStream = getClassLoaderResource("/contrib/tiff/multipage.tif").openStream(); File inputFile = File.createTempFile("imageiotest", "tif"); byte[] data = FileUtil.read(inputStream); FileUtil.write(inputFile, data); inputStream.close(); BufferedImage image = ImageIO.read(inputFile); // rotate by 90� BufferedImage image90 = TIFFUtilities.applyOrientation(image, TIFFExtension.ORIENTATION_RIGHTTOP); // rotate by 270� BufferedImage image360 = TIFFUtilities.applyOrientation(image90, TIFFExtension.ORIENTATION_LEFTBOT); byte[] original = ((DataBufferByte) image.getData().getDataBuffer()).getData(); byte[] rotated = ((DataBufferByte) image360.getData().getDataBuffer()).getData(); Assert.assertArrayEquals(original, rotated); }
File inputFile = File.createTempFile("imageiotest", ".tif"); byte[] data = FileUtil.read(inputStream); FileUtil.write(inputFile, data); inputStream.close();
/** * Writes the contents from a byte array to a file. * * @param pFilename The name of the file to write to * @param pData The byte array to write * @return {@code true}, otherwise an IOException is thrown. * @throws IOException if an i/o error occurs during write. */ public static boolean write(String pFilename, byte[] pData) throws IOException { return write(new File(pFilename), pData); }
/** * Writes the contents from a byte array to a file. * * @param pFilename The name of the file to write to * @param pData The byte array to write * @return {@code true}, otherwise an IOException is thrown. * @throws IOException if an i/o error occurs during write. */ public static boolean write(String pFilename, byte[] pData) throws IOException { return write(new File(pFilename), pData); }
/** * Writes the contents from a byte array to a file. * * @param pFile The file to write to * @param pData The byte array to write * @return {@code true}, otherwise an IOException is thrown. * @throws IOException if an i/o error occurs during write. */ public static boolean write(File pFile, byte[] pData) throws IOException { boolean success = false; OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(pFile)); success = write(out, pData); } finally { close(out); } return success; }
/** * Writes the contents from a byte array to a file. * * @param pFile The file to write to * @param pData The byte array to write * @return {@code true}, otherwise an IOException is thrown. * @throws IOException if an i/o error occurs during write. */ public static boolean write(File pFile, byte[] pData) throws IOException { boolean success = false; OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(pFile)); success = write(out, pData); } finally { close(out); } return success; }
@Test public void testSplit() throws IOException { InputStream inputStream = getClassLoaderResource("/contrib/tiff/multipage.tif").openStream(); File inputFile = File.createTempFile("imageiotest", "tif"); byte[] data = FileUtil.read(inputStream); FileUtil.write(inputFile, data); inputStream.close(); File outputDirectory = Files.createTempDirectory("imageio").toFile(); TIFFUtilities.split(inputFile, outputDirectory); ImageReader reader = ImageIO.getImageReadersByFormatName("TIF").next(); File[] outputFiles = outputDirectory.listFiles(); Assert.assertEquals(3, outputFiles.length); for (File outputFile : outputFiles) { ImageInputStream iis = ImageIO.createImageInputStream(outputFile); reader.setInput(iis); Assert.assertEquals(1, reader.getNumImages(true)); iis.close(); outputFile.delete(); } outputDirectory.delete(); inputFile.delete(); }
@Test public void testApplyOrientation() throws IOException { InputStream inputStream = getClassLoaderResource("/contrib/tiff/multipage.tif").openStream(); File inputFile = File.createTempFile("imageiotest", "tif"); byte[] data = FileUtil.read(inputStream); FileUtil.write(inputFile, data); inputStream.close(); BufferedImage image = ImageIO.read(inputFile); // rotate by 90� BufferedImage image90 = TIFFUtilities.applyOrientation(image, TIFFExtension.ORIENTATION_RIGHTTOP); // rotate by 270� BufferedImage image360 = TIFFUtilities.applyOrientation(image90, TIFFExtension.ORIENTATION_LEFTBOT); byte[] original = ((DataBufferByte) image.getData().getDataBuffer()).getData(); byte[] rotated = ((DataBufferByte) image360.getData().getDataBuffer()).getData(); Assert.assertArrayEquals(original, rotated); }
File inputFile = File.createTempFile("imageiotest", ".tif"); byte[] data = FileUtil.read(inputStream); FileUtil.write(inputFile, data); inputStream.close();