Search in sources :

Example 1 with RandomAccessOutputStream

use of loci.common.RandomAccessOutputStream 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 RandomAccessOutputStream

use of loci.common.RandomAccessOutputStream 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 RandomAccessOutputStream

use of loci.common.RandomAccessOutputStream 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 RandomAccessOutputStream

use of loci.common.RandomAccessOutputStream 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 RandomAccessOutputStream

use of loci.common.RandomAccessOutputStream 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

RandomAccessOutputStream (loci.common.RandomAccessOutputStream)15 TiffSaver (loci.formats.tiff.TiffSaver)9 RandomAccessInputStream (loci.common.RandomAccessInputStream)8 ByteArrayHandle (loci.common.ByteArrayHandle)7 FormatException (loci.formats.FormatException)5 IOException (java.io.IOException)3 MetadataRetrieve (loci.formats.meta.MetadataRetrieve)3 Test (org.testng.annotations.Test)3 IFD (loci.formats.tiff.IFD)2 TiffParser (loci.formats.tiff.TiffParser)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 StringTokenizer (java.util.StringTokenizer)1 TreeSet (java.util.TreeSet)1 ImageReader (loci.formats.ImageReader)1 Time (ome.units.quantity.Time)1 BeforeMethod (org.testng.annotations.BeforeMethod)1