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