use of kdu_jni.Jp2_locator in project imageio-ext by geosolutions-it.
the class LazyJP2KBox method clone.
@Override
public Object clone() {
// LazyJP2KBox newBox = (LazyJP2KBox)super.clone();
Jp2_locator locator = new Jp2_locator();
try {
final long filePos = this.locator.Get_file_pos();
locator.Set_file_pos(filePos);
// return newBox;
return new LazyJP2KBox(filename, type, locator);
} catch (KduException e) {
throw new RuntimeException("Error caused by a Kakadu exception during Box management! ", e);
}
}
use of kdu_jni.Jp2_locator 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");
}
}
use of kdu_jni.Jp2_locator in project imageio-ext by geosolutions-it.
the class JP2KFileWalker method parse.
/**
* Parses this box, his brothers as well as his children recursively.
*
* @param inputBox
* the box to begin the parsing with.
* @param parent
* the parent box to which attach this box as well as its
* brothers.
* @param index
* the index at which this box should be attached in his
* father's children list.
* @throws KduException
* in case any problem with the low level machinery happens.
*/
private void parse(final Jp2_input_box inputBox, final JP2KBox parent, int index) throws KduException {
final Jp2_input_box childBox = new Jp2_input_box();
try {
// //
//
// get the info for this box
//
// //
final int boxtype = (int) (0xffffffff & inputBox.Get_box_type());
final String typeString = BoxUtilities.getTypeString(boxtype);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Found box " + typeString);
}
LazyJP2KBox currentBox = null;
// //
if (BoxUtilities.boxNames.containsKey(boxtype)) {
final Jp2_locator locator = inputBox.Get_locator();
// created a lazily loaded box
currentBox = new LazyJP2KBox(this.fileName, boxtype, locator);
parent.insert(currentBox, index++);
this.tree.nodesWereInserted(parent, new int[] { index - 1 });
} else {
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("Box of type " + typeString + " cannot be handled by this file type reader");
}
}
// reopen box
if (BoxUtilities.SUPERBOX_NAMES.contains(typeString)) {
if (childBox.Open(inputBox)) {
if (childBox.Exists()) {
parse(childBox, currentBox, 0);
}
// close box
childBox.Close();
}
}
// //
//
// check next
//
// //
// close box
inputBox.Close();
if (inputBox.Open_next()) {
if (inputBox.Exists()) {
parse(inputBox, parent, index);
}
}
} catch (KduException e) {
throw new RuntimeException("Error caused by a Kakadu exception during Box management! ", e);
} finally {
// clean up
try {
if (childBox != null)
childBox.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);
}
}
}
Aggregations