Search in sources :

Example 1 with TiffSaver

use of loci.formats.tiff.TiffSaver in project bioformats by openmicroscopy.

the class TiffPixelsTest method readSavedPlane.

// -- Helper method --
private byte[] readSavedPlane() throws FormatException, IOException {
    ByteArrayHandle savedData = new ByteArrayHandle();
    RandomAccessOutputStream out = new RandomAccessOutputStream(savedData);
    RandomAccessInputStream in = new RandomAccessInputStream(savedData);
    TiffSaver saver = new TiffSaver(out, savedData);
    // saver.setInputStream(in);
    saver.writeImage(data, ifd, 0, FormatTools.UINT16, false);
    out.close();
    TiffParser parser = new TiffParser(in);
    byte[] plane = new byte[data.length];
    parser.getSamples(ifd, plane);
    in.close();
    return plane;
}
Also used : RandomAccessOutputStream(loci.common.RandomAccessOutputStream) TiffSaver(loci.formats.tiff.TiffSaver) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream) ByteArrayHandle(loci.common.ByteArrayHandle)

Example 2 with TiffSaver

use of loci.formats.tiff.TiffSaver in project bioformats by openmicroscopy.

the class TiffSaverTest method testNullFilename.

@Test(expectedExceptions = { IllegalArgumentException.class })
public void testNullFilename() throws IOException {
    RandomAccessOutputStream a = new RandomAccessOutputStream(new ByteArrayHandle());
    String b = null;
    tiffSaver = new TiffSaver(a, b);
    tiffSaver.writeHeader();
}
Also used : RandomAccessOutputStream(loci.common.RandomAccessOutputStream) TiffSaver(loci.formats.tiff.TiffSaver) ByteArrayHandle(loci.common.ByteArrayHandle) Test(org.testng.annotations.Test)

Example 3 with TiffSaver

use of loci.formats.tiff.TiffSaver in project bioformats by openmicroscopy.

the class TiffSaverTest method testNullBytes.

@Test(expectedExceptions = { IllegalArgumentException.class })
public void testNullBytes() throws IOException {
    RandomAccessOutputStream a = new RandomAccessOutputStream(new ByteArrayHandle());
    ByteArrayHandle b = null;
    tiffSaver = new TiffSaver(a, b);
    tiffSaver.writeHeader();
}
Also used : RandomAccessOutputStream(loci.common.RandomAccessOutputStream) TiffSaver(loci.formats.tiff.TiffSaver) ByteArrayHandle(loci.common.ByteArrayHandle) Test(org.testng.annotations.Test)

Example 4 with TiffSaver

use of loci.formats.tiff.TiffSaver in project bioformats by openmicroscopy.

the class TiffSaverTest method testNullOutputStream.

@Test(expectedExceptions = { IllegalArgumentException.class })
public void testNullOutputStream() throws IOException {
    RandomAccessOutputStream a = null;
    String b = null;
    tiffSaver = new TiffSaver(a, b);
    tiffSaver.writeHeader();
}
Also used : RandomAccessOutputStream(loci.common.RandomAccessOutputStream) TiffSaver(loci.formats.tiff.TiffSaver) Test(org.testng.annotations.Test)

Example 5 with TiffSaver

use of loci.formats.tiff.TiffSaver in project bioformats by openmicroscopy.

the class TiffComment method overwriteComment.

/**
 * Overwrites the comment.
 *
 * @param file The path to the file to handle.
 * @param comment The new comment to write.
 */
private static void overwriteComment(String file, String comment) {
    RandomAccessInputStream in = null;
    RandomAccessOutputStream out = null;
    try {
        in = new RandomAccessInputStream(file);
        out = new RandomAccessOutputStream(file);
        TiffSaver saver = new TiffSaver(out, file);
        saver.overwriteComment(in, comment);
    } catch (Exception e) {
        System.out.println(e.toString());
    } finally {
        try {
            if (in != null)
                in.close();
        } catch (Exception e) {
        }
        try {
            if (out != null)
                out.close();
        } catch (Exception e) {
        }
    }
}
Also used : RandomAccessOutputStream(loci.common.RandomAccessOutputStream) TiffSaver(loci.formats.tiff.TiffSaver) RandomAccessInputStream(loci.common.RandomAccessInputStream) FormatException(loci.formats.FormatException) IOException(java.io.IOException)

Aggregations

TiffSaver (loci.formats.tiff.TiffSaver)10 RandomAccessOutputStream (loci.common.RandomAccessOutputStream)9 RandomAccessInputStream (loci.common.RandomAccessInputStream)7 ByteArrayHandle (loci.common.ByteArrayHandle)4 IOException (java.io.IOException)3 FormatException (loci.formats.FormatException)3 TiffParser (loci.formats.tiff.TiffParser)3 Test (org.testng.annotations.Test)3 IFD (loci.formats.tiff.IFD)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ImageReader (loci.formats.ImageReader)1 BeforeMethod (org.testng.annotations.BeforeMethod)1