GroupDocsGists
10/24/2017 - 1:56 PM

Examples-GroupDocs.Metadata-for-Java

Examples-GroupDocs.Metadata-for-Java

public class PhotoParser
{
    /**
     * <p>
     * Absolute path to the photos directory.
     * </p>
     */
    public final String getPhotosDirectory(){ return auto_PhotosDirectory; }

    public final void setPhotosDirectory(String value){ auto_PhotosDirectory = value; }
    private String auto_PhotosDirectory;

    public PhotoParser(String photosDirectory) throws FileNotFoundException
    {

        Path path = Paths.get(Common.getStoragePath(photosDirectory));

        this.setPhotosDirectory(Common.getStoragePath(photosDirectory));
    }

    public final String[] filterByCameraManufacturer(String manufacturer)
    {
        File dir = new File(getPhotosDirectory());

        File [] files = dir.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".jpg");
            }
        });

        java.util.List<String> result = new ArrayList<String>();

        for(File f: files)
        {
            String filePath = f.getAbsolutePath();

            // recognize file
            FormatBase format = FormatFactory.recognizeFormat(filePath);

            if(format.getType() == DocumentType.Jpeg)
            {
                JpegFormat jpeg = (JpegFormat)format;

                // get exif data
                JpegExifInfo exif = (JpegExifInfo)jpeg.getExifInfo();

                if (exif != null)
                {

                    if (exif.getMake() == manufacturer)
                    {
                        result.add(filePath);
                    }
                }
            }
        }

        return result.toArray(new String[0]);
    }
}