Search in sources :

Example 71 with RandomAccessInputStream

use of loci.common.RandomAccessInputStream in project bioformats by openmicroscopy.

the class ExtractFlexMetadata method main.

public static void main(String[] args) throws Exception {
    File dir;
    if (args.length != 1 || !(dir = new File(args[0])).canRead()) {
        System.out.println("Usage: java ExtractFlexMetadata dir");
        return;
    }
    for (File file : dir.listFiles()) {
        if (file.getName().endsWith(".flex")) {
            String id = file.getPath();
            int dot = id.lastIndexOf(".");
            String outId = (dot >= 0 ? id.substring(0, dot) : id) + ".xml";
            RandomAccessInputStream in = new RandomAccessInputStream(id);
            TiffParser parser = new TiffParser(in);
            IFD firstIFD = parser.getIFDs().get(0);
            String xml = firstIFD.getIFDTextValue(FlexReader.FLEX);
            in.close();
            FileWriter writer = new FileWriter(new File(outId));
            writer.write(xml);
            writer.close();
            System.out.println("Writing header of: " + id);
        }
    }
    System.out.println("Done");
}
Also used : IFD(loci.formats.tiff.IFD) FileWriter(java.io.FileWriter) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream) File(java.io.File)

Example 72 with RandomAccessInputStream

use of loci.common.RandomAccessInputStream in project bioformats by openmicroscopy.

the class CellVoyagerReader method initFile.

@Override
protected void initFile(final String id) throws FormatException, IOException {
    super.initFile(id);
    measurementFolder = new Location(id).getAbsoluteFile();
    if (!measurementFolder.exists()) {
        throw new IOException("File " + id + " does not exist.");
    }
    if (!measurementFolder.isDirectory()) {
        measurementFolder = measurementFolder.getParentFile();
        if (measurementFolder.getName().equals("Image")) {
            measurementFolder = measurementFolder.getParentFile();
        }
    }
    imageFolder = new Location(measurementFolder, "Image");
    measurementResultFile = new Location(measurementFolder, "MeasurementResult.xml");
    if (!measurementResultFile.exists()) {
        throw new IOException("Could not find " + measurementResultFile + " in folder.");
    }
    omeMeasurementFile = new Location(measurementFolder, "MeasurementResult.ome.xml");
    if (!omeMeasurementFile.exists()) {
        throw new IOException("Could not find " + omeMeasurementFile + " in folder.");
    }
    /*
     * Open MeasurementSettings file
     */
    RandomAccessInputStream result = new RandomAccessInputStream(measurementResultFile.getAbsolutePath());
    Document msDocument = null;
    try {
        msDocument = XMLTools.parseDOM(result);
    } catch (ParserConfigurationException e) {
        throw new IOException(e);
    } catch (SAXException e) {
        throw new IOException(e);
    } finally {
        result.close();
    }
    msDocument.getDocumentElement().normalize();
    /*
     * Check file version
     */
    final String fileVersionMajor = getChildText(msDocument.getDocumentElement(), new String[] { "FileVersion", "Major" });
    // Note the typo here.
    final String fileVersionMinor = getChildText(msDocument.getDocumentElement(), new String[] { "FileVersion", "Miner" });
    if (!fileVersionMajor.equals("1") || !fileVersionMinor.equals("0")) {
        LOGGER.warn("Detected a file version " + fileVersionMajor + "." + fileVersionMinor + ". This reader was built by reverse-engineering v1.0 files only. Errors might occur.");
    }
    /*
     * Open OME metadata file
     */
    RandomAccessInputStream measurement = new RandomAccessInputStream(omeMeasurementFile.getAbsolutePath());
    Document omeDocument = null;
    try {
        omeDocument = XMLTools.parseDOM(measurement);
    } catch (ParserConfigurationException e) {
        throw new IOException(e);
    } catch (SAXException e) {
        throw new IOException(e);
    } finally {
        measurement.close();
    }
    omeDocument.getDocumentElement().normalize();
    /*
     * Extract metadata from MeasurementSetting.xml & OME xml file. This is
     * where the core of parsing and fetching useful info happens
     */
    readInfo(msDocument, omeDocument);
}
Also used : IOException(java.io.IOException) RandomAccessInputStream(loci.common.RandomAccessInputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) Location(loci.common.Location) SAXException(org.xml.sax.SAXException)

Example 73 with RandomAccessInputStream

use of loci.common.RandomAccessInputStream in project bioformats by openmicroscopy.

the class CellomicsReader method openBytes.

/**
 * @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int)
 */
@Override
public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
    FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h);
    int[] zct = getZCTCoords(no);
    String file = files[getSeries() * getSizeC() + zct[1]];
    RandomAccessInputStream s = getDecompressedStream(file);
    int planeSize = FormatTools.getPlaneSize(this);
    s.seek(52 + zct[0] * planeSize);
    readPlane(s, x, y, w, h, buf);
    s.close();
    return buf;
}
Also used : RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 74 with RandomAccessInputStream

use of loci.common.RandomAccessInputStream in project bioformats by openmicroscopy.

the class CellomicsReader method getDecompressedStream.

private RandomAccessInputStream getDecompressedStream(String filename) throws FormatException, IOException {
    RandomAccessInputStream s = new RandomAccessInputStream(filename);
    if (checkSuffix(filename, "c01")) {
        LOGGER.info("Decompressing file");
        s.seek(4);
        ZlibCodec codec = new ZlibCodec();
        byte[] file = codec.decompress(s, null);
        s.close();
        return new RandomAccessInputStream(file);
    }
    return s;
}
Also used : ZlibCodec(loci.formats.codec.ZlibCodec) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 75 with RandomAccessInputStream

use of loci.common.RandomAccessInputStream in project bioformats by openmicroscopy.

the class DeltavisionReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    if (!checkSuffix(id, "dv")) {
        if (checkSuffix(id, "dv.log") || checkSuffix(id, "r3d.log")) {
            id = id.substring(0, id.lastIndexOf("."));
        } else if (id.endsWith("_log.txt")) {
            id = id.substring(0, id.lastIndexOf("_")) + ".dv";
        }
        Location file = new Location(id).getAbsoluteFile();
        if (!file.exists()) {
            Location dir = file.getParentFile();
            String[] list = dir.list(true);
            String name = file.getName();
            name = name.substring(0, name.lastIndexOf("."));
            for (String f : list) {
                if (checkSuffix(f, "dv") && f.startsWith(name)) {
                    id = new Location(dir, f).getAbsolutePath();
                    break;
                }
            }
        }
    }
    super.initFile(id);
    findLogFiles();
    in = new RandomAccessInputStream(currentId);
    initPixels();
    MetadataLevel metadataLevel = metadataOptions.getMetadataLevel();
    if (metadataLevel != MetadataLevel.MINIMUM) {
        initExtraMetadata();
    }
}
Also used : RandomAccessInputStream(loci.common.RandomAccessInputStream) Location(loci.common.Location)

Aggregations

RandomAccessInputStream (loci.common.RandomAccessInputStream)246 CoreMetadata (loci.formats.CoreMetadata)108 MetadataStore (loci.formats.meta.MetadataStore)97 FormatException (loci.formats.FormatException)75 TiffParser (loci.formats.tiff.TiffParser)56 IFD (loci.formats.tiff.IFD)51 Length (ome.units.quantity.Length)48 Location (loci.common.Location)47 IOException (java.io.IOException)46 ArrayList (java.util.ArrayList)30 Timestamp (ome.xml.model.primitives.Timestamp)28 Time (ome.units.quantity.Time)21 ByteArrayHandle (loci.common.ByteArrayHandle)18 IFDList (loci.formats.tiff.IFDList)16 CodecOptions (loci.formats.codec.CodecOptions)9 RandomAccessOutputStream (loci.common.RandomAccessOutputStream)8 ServiceException (loci.common.services.ServiceException)7 PhotoInterp (loci.formats.tiff.PhotoInterp)7 TiffSaver (loci.formats.tiff.TiffSaver)7 BufferedReader (java.io.BufferedReader)6