use of loci.common.services.ServiceException in project bioformats by openmicroscopy.
the class OMEXMLWriter method close.
/* @see loci.formats.IFormatHandler#close() */
@Override
public void close() throws IOException {
if (out != null) {
out.writeBytes(xmlFragments.get(xmlFragments.size() - 1));
}
if (getMetadataOptions().isValidate()) {
try {
MetadataRetrieve r = getMetadataRetrieve();
String omexml = service.getOMEXML(r);
service.validateOMEXML(omexml);
} catch (ServiceException | NullPointerException e) {
LOGGER.warn("OMEXMLService unable to create OME-XML metadata object.", e);
}
}
super.close();
xmlFragments = null;
service = null;
}
use of loci.common.services.ServiceException in project bioformats by openmicroscopy.
the class MakeTestOmeTiff method createWriter.
private OMETiffWriter createWriter(final String name, final CoreMetadata info, final String id) throws FormatException, IOException {
final OMETiffWriter out = new OMETiffWriter();
try {
out.setMetadataRetrieve(createMetadata(name, info));
} catch (final DependencyException e) {
throw new FormatException(e);
} catch (final ServiceException e) {
throw new FormatException(e);
} catch (final EnumerationException e) {
throw new FormatException(e);
}
ensureNonExisting(id);
out.setId(id);
return out;
}
use of loci.common.services.ServiceException in project bioformats by openmicroscopy.
the class EightBitLosslessJPEG2000Test method setUp.
@BeforeMethod
public void setUp() throws Exception {
for (byte v = Byte.MIN_VALUE; v < Byte.MAX_VALUE; v++) {
int index = v + Byte.MAX_VALUE + 1;
pixels[index][0] = v;
String file = index + ".jp2";
File tempFile = File.createTempFile("test", ".jp2");
tempFile.deleteOnExit();
Location.mapId(file, tempFile.getAbsolutePath());
files.add(file);
IMetadata metadata;
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
metadata = service.createOMEXMLMetadata();
} catch (DependencyException exc) {
throw new FormatException("Could not create OME-XML store.", exc);
} catch (ServiceException exc) {
throw new FormatException("Could not create OME-XML store.", exc);
}
MetadataTools.populateMetadata(metadata, 0, "foo", false, "XYCZT", "uint8", 1, 1, 1, 1, 1, 1);
IFormatWriter writer = new JPEG2000Writer();
writer.setMetadataRetrieve(metadata);
writer.setId(file);
writer.saveBytes(0, pixels[index]);
writer.close();
}
}
use of loci.common.services.ServiceException in project bioformats by openmicroscopy.
the class OMETiffWriter method getOMEXML.
private String getOMEXML(String file) throws FormatException, IOException {
// generate UUID and add to OME element
String uuid = "urn:uuid:" + getUUID(new Location(file).getName());
omeMeta.setUUID(uuid);
OMEXMLMetadataRoot root = (OMEXMLMetadataRoot) omeMeta.getRoot();
root.setCreator(FormatTools.CREATOR);
String xml;
try {
xml = service.getOMEXML(omeMeta);
} catch (ServiceException se) {
throw new FormatException(se);
}
return xml;
}
use of loci.common.services.ServiceException in project bioformats by openmicroscopy.
the class EXIFServiceImpl method initialize.
// -- EXIFService API methods --
@Override
public void initialize(String file) throws ServiceException, IOException {
try {
File jpegFile = new File(file);
Metadata metadata = ImageMetadataReader.readMetadata(jpegFile);
directory = metadata.getDirectory(ExifSubIFDDirectory.class);
} catch (Throwable e) {
throw new ServiceException("Could not read EXIF data", e);
}
}
Aggregations