Search in sources :

Example 46 with ServiceException

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;
}
Also used : ServiceException(loci.common.services.ServiceException) MetadataRetrieve(loci.formats.meta.MetadataRetrieve)

Example 47 with ServiceException

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;
}
Also used : OMETiffWriter(loci.formats.out.OMETiffWriter) ServiceException(loci.common.services.ServiceException) DependencyException(loci.common.services.DependencyException) EnumerationException(ome.xml.model.enums.EnumerationException) FormatException(loci.formats.FormatException)

Example 48 with ServiceException

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();
    }
}
Also used : IFormatWriter(loci.formats.IFormatWriter) JPEG2000Writer(loci.formats.out.JPEG2000Writer) IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) DependencyException(loci.common.services.DependencyException) File(java.io.File) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 49 with ServiceException

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;
}
Also used : ServiceException(loci.common.services.ServiceException) OMEXMLMetadataRoot(ome.xml.meta.OMEXMLMetadataRoot) FormatException(loci.formats.FormatException) Location(loci.common.Location)

Example 50 with ServiceException

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);
    }
}
Also used : ExifSubIFDDirectory(com.drew.metadata.exif.ExifSubIFDDirectory) ServiceException(loci.common.services.ServiceException) Metadata(com.drew.metadata.Metadata) File(java.io.File)

Aggregations

ServiceException (loci.common.services.ServiceException)54 FormatException (loci.formats.FormatException)40 DependencyException (loci.common.services.DependencyException)34 ServiceFactory (loci.common.services.ServiceFactory)30 OMEXMLService (loci.formats.services.OMEXMLService)29 IOException (java.io.IOException)21 IMetadata (loci.formats.meta.IMetadata)16 OMEXMLMetadata (loci.formats.ome.OMEXMLMetadata)12 Location (loci.common.Location)11 PositiveInteger (ome.xml.model.primitives.PositiveInteger)11 File (java.io.File)10 ImageReader (loci.formats.ImageReader)10 MetadataStore (loci.formats.meta.MetadataStore)10 CoreMetadata (loci.formats.CoreMetadata)9 OMEXMLMetadataRoot (ome.xml.meta.OMEXMLMetadataRoot)9 EnumerationException (ome.xml.model.enums.EnumerationException)9 RandomAccessInputStream (loci.common.RandomAccessInputStream)7 MissingLibraryException (loci.formats.MissingLibraryException)7 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)6 SAXException (org.xml.sax.SAXException)6