Package gov.lanl.adore.djatoka

Examples of gov.lanl.adore.djatoka.DjatokaException


        try {
            in = IOUtils.createTempTiff(bi);
            compressImage(in.getAbsolutePath(), output, params);
        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
            throw new DjatokaException(e.getMessage(), e);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            throw new DjatokaException(e.getMessage(), e);
        } finally {
            if (in != null) {
                if (!in.delete() && LOGGER.isWarnEnabled()) {
                    LOGGER.warn("File not deleted: {}", in);
                }
View Full Code Here


            out = File.createTempFile("tmp", ".jp2");
            compressImage(in.getAbsolutePath(), out.getAbsolutePath(), params);
            IOUtils.copyStream(new FileInputStream(out), output);
        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
            throw new DjatokaException(e.getMessage(), e);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            throw new DjatokaException(e.getMessage(), e);
        }

        if (in != null) {
            if (!in.delete() && LOGGER.isWarnEnabled()) {
                LOGGER.warn("File not deleted: {}", in);
View Full Code Here

                params.setLevels(ImageProcessingUtils.getLevelCount(dim.getWidth(), dim.getHeight()));
                dim = null;
            }
        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
            throw new DjatokaException(e.getMessage(), e);
        }

        compressImage(inputFile.getAbsolutePath(), output, params);

        if (inputFile != null) {
View Full Code Here

                params.setLevels(ImageProcessingUtils.getLevelCount(dim.getWidth(), dim.getHeight()));
                dim = null;
            }
        } catch (IOException e1) {
            LOGGER.error("Unexpected file format; expecting uncompressed TIFF", e1);
            throw new DjatokaException("Unexpected file format; expecting uncompressed TIFF");
        }

        String out = STDOUT;
        File winOut = null;
        if (isWindows) {
            try {
                winOut = File.createTempFile("pipe_", ".jp2");
            } catch (IOException e) {
                LOGGER.error(e.getMessage(), e);
                throw new DjatokaException(e.getMessage(), e);
            }
            out = winOut.getAbsolutePath();
        }

        String command = getKduCompressCommand(inputFile.getAbsolutePath(), out, params);
        String[] cmdParts = CommandLineTokenizer.tokenize(command);
        Runtime rt = Runtime.getRuntime();
        try {
            final Process process = rt.exec(cmdParts, envParams, new File(env));
            if (out.equals(STDOUT)) {
                IOUtils.copyStream(process.getInputStream(), output);
            } else if (isWindows) {
                FileInputStream fis = new FileInputStream(out);
                IOUtils.copyStream(fis, output);
                fis.close();
            }
            process.waitFor();
            if (process != null) {
                String errorCheck = null;
                try {
                    errorCheck = new String(IOUtils.getByteArray(process.getErrorStream()));
                } catch (Exception e1) {
                    LOGGER.error(e1.getMessage(), e1);
                }
                process.getInputStream().close();
                process.getOutputStream().close();
                process.getErrorStream().close();
                process.destroy();
                if (errorCheck != null) {
                    throw new DjatokaException(errorCheck);
                }
            }
        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
            throw new DjatokaException(e.getMessage(), e);
        } catch (InterruptedException e) {
            LOGGER.error(e.getMessage(), e);
            throw new DjatokaException(e.getMessage(), e);
        }

        if (inputFile != null) {
            if (!inputFile.delete() && LOGGER.isWarnEnabled()) {
                LOGGER.warn("File not deleted: {}", inputFile);
View Full Code Here

            try {
                inputFile = IOUtils.createTempTiff(input);
                tmp = true;
                input = inputFile.getAbsolutePath();
            } catch (Exception e) {
                throw new DjatokaException("Unrecognized file format: " + e.getMessage());
            }
        }

        if (params.getLevels() == 0) {
            ImageRecord dim = ImageRecordUtils.getImageDimensions(inputFile.getAbsolutePath());
            params.setLevels(ImageProcessingUtils.getLevelCount(dim.getWidth(), dim.getHeight()));
            dim = null;
        }

        File outFile = new File(output);
        String command = getKduCompressCommand(new File(input).getAbsolutePath(), outFile.getAbsolutePath(), params);
        String[] cmdParts = CommandLineTokenizer.tokenize(command);
        Runtime rt = Runtime.getRuntime();

        try {
            final Process process = rt.exec(cmdParts, envParams, new File(env));
            process.waitFor();
            if (process != null) {
                String errorCheck = null;

                try {
                    InputStream inStream = process.getErrorStream();
                    errorCheck = new String(IOUtils.getByteArray(inStream));
                } catch (Exception e1) {
                }

                process.getInputStream().close();
                process.getOutputStream().close();
                process.getErrorStream().close();
                process.destroy();

                if (errorCheck != null && !errorCheck.equals("")) {
                    throw new DjatokaException(errorCheck);
                }
            }
        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
            throw new DjatokaException(e.getMessage(), e);
        } catch (InterruptedException e) {
            LOGGER.error(e.getMessage(), e);
            throw new DjatokaException(e.getMessage(), e);
        } finally {
            if (tmp) {
                if (!inputFile.delete() && LOGGER.isWarnEnabled()) {
                    LOGGER.warn("File not deleted: {}", inputFile);
                }
            }
        }

        if (!outFile.getAbsolutePath().equals(STDOUT) && !outFile.exists()) {
            throw new DjatokaException("Unknown error occurred during processing.");
        }
    }
View Full Code Here

            FileOutputStream fos = new FileOutputStream(in);
            in.deleteOnExit();
            IOUtils.copyStream(input, fos);
        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
            throw new DjatokaException(e.getMessage(), e);
        }

        BufferedImage bi = process(in.getAbsolutePath(), params);

        if (in != null) {
View Full Code Here

                    closeStreams(process);
                }
            }
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            throw new DjatokaException(e.getMessage(), e);
        }

        return bi;
    }
View Full Code Here

            try {
                winOut = File.createTempFile("pipe_", ".ppm");
                winOut.deleteOnExit();
            } catch (IOException e) {
                LOGGER.error(e.getMessage(), e);
                throw new DjatokaException(e.getMessage(), e);
            }

            output = winOut.getAbsolutePath();
        }

        Runtime rt = Runtime.getRuntime();

        try {
            ArrayList<Double> dims = getRegionMetadata(input, params);
            String command = getKduExtractCommand(input, output, dims, params);
            String[] cmdParts = CommandLineTokenizer.tokenize(command);
            final Process process = rt.exec(cmdParts, 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.getMessage(), e);

                            if (winOut != null) {
                                if (!winOut.delete() && LOGGER.isWarnEnabled()) {
                                    LOGGER.warn("File not deleted: {}", winOut);
                                }
                            }

                            throw e;
                        }

                        if (winOut != null) {
                            winOut.delete();
                        }
                    }
                } catch (RuntimeException details) {
                    LOGGER.debug("Request out of bounds: {}", details.getMessage());

                    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.getMessage(), e);
                    }
                } finally {
                    if (process != null) {
                        closeStreams(process);
                    }
View Full Code Here

        if (input.getImageFile() != null) {
            return process(input, 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) {
            FileInputStream fis = null;

            // If < 4K bytes, image may be corrupt;
            // use safer pure Java Metadata gatherer.
            try {
                fis = new FileInputStream(f);
                return getMetadata(fis);
            } catch (Exception e) {
                throw new DjatokaException("Invalid file.");
            } finally {
                info.freelibrary.util.IOUtils.closeQuietly(fis);
            }
        }

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Checking: java.library.path = {}", System.getProperty("java.library.path"));
        }

        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.getMessage(), e);
            throw new DjatokaException(e.getMessage(), e);
        }

        return r;
    }
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.