Example usage for org.apache.commons.imaging.formats.jpeg JpegImageParser getExifRawData

List of usage examples for org.apache.commons.imaging.formats.jpeg JpegImageParser getExifRawData

Introduction

In this page you can find the example usage for org.apache.commons.imaging.formats.jpeg JpegImageParser getExifRawData.

Prototype

public byte[] getExifRawData(final ByteSource byteSource) throws ImageReadException, IOException 

Source Link

Usage

From source file:com.att.aro.core.bestpractice.impl.ImageMetaDataImpl.java

private void runTestForFiles(List<String> imageList, List<ImageMdataEntry> entrylist, Session session,
        HttpRequestResponseInfo req, String imagePath, String imgFile, String extractedImageName, int pos,
        File[] listOfFiles) {/*from w w  w  .  j  av  a 2s . co m*/
    String imgFullName = "";
    String imgExtn = "";

    // check folder exists
    for (int i = 0; i < listOfFiles.length; i++) {
        if (listOfFiles[i].isFile()) {
            imgFullName = listOfFiles[i].getName();
            if (extractedImageName.equalsIgnoreCase(imgFullName)) {
                imgExtn = imgFullName.substring(pos, imgFullName.length());
                imgFile = imagePath + imgFullName;
                if (Util.isJPG(new File(imgFile), imgExtn)) {
                    extractMetadata(imgFile);
                }
                // isMetaDataPresent = true;
            } // clear
        }

        if (isMetaDataPresent) {
            File getImage = new File(imgFile);
            JpegImageParser imgP = new JpegImageParser();
            byte[] mdata = null;
            long mSize = 0;

            try {
                mdata = imgP.getExifRawData(new ByteSourceFile(getImage));
                mSize = mdata.length;
            } catch (ImageReadException | IOException e) {

            }
            imageList.add(imgFile);

            long iSize = getImage.length();

            double savings = (mSize * 100) / iSize;

            if (savings >= 15.00) {
                entrylist.add(new ImageMdataEntry(req, session.getDomainName(), imgFile,
                        Util.doubleFileSize(iSize), Util.doubleFileSize(mSize),
                        String.valueOf(new DecimalFormat("##.##").format(savings)) + "%"));
            }
            isMetaDataPresent = false;
        }
    }
}