Search in sources :

Example 1 with JP2KFileBox

use of it.geosolutions.imageio.plugins.jp2k.box.JP2KFileBox in project imageio-ext by geosolutions-it.

the class JP2KFileWalker method init.

/**
 * Parses this file into a {@link TreeModel} object.
 */
private void init() {
    if (this.initialized)
        return;
    // //
    // 
    // create needed kakadu machinery
    // 
    // //
    familySource = new Jp2_family_src();
    final Jp2_input_box inputBox = new Jp2_input_box();
    final Jp2_locator locator = new Jp2_locator();
    List<? extends Throwable> exceptions = Collections.emptyList();
    try {
        // open the family
        familySource.Open(fileName);
        // create the needed objects
        final JP2KFileBox box = new JP2KFileBox();
        this.tree = new DefaultTreeModel(box);
        // Add a listener: a new instance of a JP2KTreeController on the tree
        final JP2KTreeController controller = new JP2KTreeController(this.tree);
        this.tree.addTreeModelListener(controller);
        // recursive parsing
        if (inputBox.Open(familySource, locator)) {
            parse(inputBox, box, 0);
        }
        controller.checkTreeConsistency();
        // clean up
        inputBox.Close();
    } catch (KduException e) {
        throw new RuntimeException("Error caused by a Kakadu exception during Box management! ", e);
    } finally {
        // clean up
        try {
            familySource.Close();
        } catch (Exception e) {
            if (LOGGER.isLoggable(Level.FINEST))
                LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e);
        }
        try {
            if (inputBox != null)
                inputBox.Close();
        } catch (Exception e) {
            if (LOGGER.isLoggable(Level.FINEST))
                LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e);
        }
    }
    if (!exceptions.isEmpty()) {
        // TODO Create a specific exception that wraps them all!
        throw new IllegalStateException("Tree Check failed");
    }
}
Also used : KduException(kdu_jni.KduException) Jp2_input_box(kdu_jni.Jp2_input_box) Jp2_locator(kdu_jni.Jp2_locator) JP2KFileBox(it.geosolutions.imageio.plugins.jp2k.box.JP2KFileBox) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Jp2_family_src(kdu_jni.Jp2_family_src) KduException(kdu_jni.KduException)

Aggregations

JP2KFileBox (it.geosolutions.imageio.plugins.jp2k.box.JP2KFileBox)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 Jp2_family_src (kdu_jni.Jp2_family_src)1 Jp2_input_box (kdu_jni.Jp2_input_box)1 Jp2_locator (kdu_jni.Jp2_locator)1 KduException (kdu_jni.KduException)1