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");
}
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);
}
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;
}
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;
}
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();
}
}
Aggregations