Package gov.lanl.adore.djatoka

Examples of gov.lanl.adore.djatoka.DjatokaException


                    closeStreams(process);
                }
            }
        } catch (Exception e) {
            logger.error(e, e);
            throw new DjatokaException(e);
        }
        return bi;
    }
View Full Code Here


            try {
                winOut = File.createTempFile("pipe_", ".ppm");
                winOut.deleteOnExit();
            } catch (IOException e) {
                logger.error(e, e);
                throw new DjatokaException(e);
            }
            output = winOut.getAbsolutePath();
        }
        Runtime rt = Runtime.getRuntime();
        try {
            ArrayList<Double> dims = getRegionMetadata(input, params);
            String command = getKduExtractCommand(input, output, dims, params);
            final Process process = rt.exec(command, envParams, new File(env));

            if (output != null) {
                try {
                    if (output.equals(STDOUT)) {
                        bi = new PNMReader().open(new BufferedInputStream(process.getInputStream()));
                    } else if (isWindows) {
                        process.waitFor();
                        try {
                            bi = new PNMReader().open(new BufferedInputStream(new FileInputStream(new File(output))));
                        } catch (Exception e) {
                            logger.error(e, e);
                if (winOut != null)
                                winOut.delete();
                            throw e;
                        }
            if (winOut != null)
                            winOut.delete();
                    }
                } catch (RuntimeException e) {
                    logger.debug("Request out of bounds");
                    bi = OOB;
                } catch (Exception e) {
                    String error = null;
                    try {
                        error = new String(IOUtils.getByteArray(process.getErrorStream()));
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                    logger.error(error, e);
            if (error != null)
                        throw new DjatokaException(error);
            else
                        throw new DjatokaException(e);
                } finally {
                    if (process != null) {
                        closeStreams(process);
                    }
                }
View Full Code Here

        if (input.getImageFile() != null) {
            return process(input.getImageFile(), params);
        } else if (input.getObject() != null) {
            return process(getStreamFromObject(input.getObject()), params);
        } else {
            throw new DjatokaException(
                    "File not defined and Input Object Type "
                    + input.getObject().getClass().getName()
                    + " is not supported");
        }
    }
View Full Code Here

     * @return a populated JPEG 2000 ImageRecord instance
     * @throws DjatokaException
     */
    public final ImageRecord getMetadata(ImageRecord r) throws DjatokaException {
    if (r == null)
            throw new DjatokaException("ImageRecord is null");
        if (r.getImageFile() == null && r.getObject() != null) {
            ImageRecord ir = getMetadata(getStreamFromObject(r.getObject()));
            ir.setObject(r.getObject());
            return ir;
        }
        File f = new File(r.getImageFile());
    if (!f.exists())
            throw new DjatokaException("Image Does Not Exist");
    if (!ImageProcessingUtils.checkIfJp2(r.getImageFile()))
            throw new DjatokaException("Not a JP2 image.");
        if (f.length() <= 4096) {
            // If < 4K bytes, image may be corrupt, use safer pure Java Metadata gatherer.
            try {
                return getMetadata(new FileInputStream(f));
            } catch (Exception e) {
                throw new DjatokaException("Invalid file.");
            }
        }

        Jpx_source inputSource = new Jpx_source();
        Jp2_family_src jp2_family_in = new Jp2_family_src();

        int ref_component = 0;
        try {
            jp2_family_in.Open(r.getImageFile(), true);
            inputSource.Open(jp2_family_in, true);
            Kdu_codestream codestream = new Kdu_codestream();
            codestream.Create(inputSource.Access_codestream(ref_component).Open_stream());

            int minLevels = codestream.Get_min_dwt_levels();
            int depth = codestream.Get_bit_depth(ref_component);
            int colors = codestream.Get_num_components();
            int[] frames = new int[1];
            inputSource.Count_compositing_layers(frames);
            Kdu_dims image_dims = new Kdu_dims();
            codestream.Get_dims(ref_component, image_dims);
            Kdu_coords imageSize = image_dims.Access_size();

            r.setWidth(imageSize.Get_x());
            r.setHeight(imageSize.Get_y());
            r.setDWTLevels(minLevels);
            int djatokaLevels = ImageProcessingUtils.getLevelCount(r.getWidth(), r.getHeight());
            r.setLevels((djatokaLevels > minLevels) ? minLevels : djatokaLevels);
            r.setBitDepth(depth);
            r.setNumChannels(colors);
            r.setCompositingLayerCount(frames[0]);

            int[] v = new int[1];
            Kdu_params p = codestream.Access_siz().Access_cluster("COD");
            if (p != null) {
                p.Get(Kdu_global.Clayers, 0, 0, v, true, true, true);
          if (v[0] > 0)
                    r.setQualityLayers(v[0]);
            }

      if (codestream.Exists())
                codestream.Destroy();
            inputSource.Native_destroy();
            jp2_family_in.Native_destroy();
        } catch (KduException e) {
            logger.error(e, e);
            throw new DjatokaException(e);
        }

        return r;
    }
View Full Code Here

        JP2ImageInfo info;
        try {
            info = new JP2ImageInfo(is);
        } catch (IOException e) {
            logger.error(e, e);
            throw new DjatokaException(e);
        }
        return info.getImageRecord();
    }
View Full Code Here

      if ((token = st.nextToken()).contains("."))
                dims.add(Double.parseDouble(token));
      else {
                int t = Integer.parseInt(token);
        if (r.getHeight() < t)
                    throw new DjatokaException("Region inset out of bounds: " + t + ">" + r.getHeight());
                dims.add(Double.parseDouble(token) / r.getHeight());
            }
            // left
            if ((token = st.nextToken()).contains(".")) {
                dims.add(Double.parseDouble(token));
            } else {
                int t = Integer.parseInt(token);
        if (r.getWidth() < t)
                    throw new DjatokaException("Region inset out of bounds: " + t + ">" + r.getWidth());
                dims.add(Double.parseDouble(token) / r.getWidth());
            }
            // height
            if ((token = st.nextToken()).contains(".")) {
                dims.add(Double.parseDouble(token));
View Full Code Here

      src.close();
      dest.close();
     
      return urlLocal;
    } catch (Exception e) {
      throw new DjatokaException(e);
    } finally {
      if (processing.contains(uri.toString()))
        processing.remove(uri.toString());
    }
  }
View Full Code Here

      } else {
        try {
          IExtract ex = new KduExtractExe();
          ex.getMetadata(new ImageRecord(uri.toString(), img.getAbsolutePath()));
        } catch (DjatokaException e) {
          throw new DjatokaException("Unknown JP2/JPX file format");
        }
      }
    } catch (Exception e) {
      throw new DjatokaException(e);
    }
    return img;
  }
View Full Code Here

                destination.close();
            }

            return file;
        } catch (final Exception details) {
            throw new DjatokaException(details.getMessage(), details);
        } finally {
            if (processing.contains(aReferent)) {
                processing.remove(aReferent);
            }
        }
View Full Code Here

            } else {
                try {
                    final IExtract ex = new KduExtractExe();
                    ex.getMetadata(new ImageRecord(uri.toString(), img.getAbsolutePath()));
                } catch (final DjatokaException e) {
                    throw new DjatokaException("Unknown JP2/JPX file format");
                }
            }
        } catch (final Exception e) {
            throw new DjatokaException(e.getMessage(), e);
        }
        return img;
    }
View Full Code Here

TOP

Related Classes of gov.lanl.adore.djatoka.DjatokaException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.