public static int getOrientation(final Metadata metadata) {
        return safeProcess("orientation", metadata, ExifInterface.ORIENTATION_NORMAL, () -> {

            final Collection<ExifDirectoryBase> exifDirs = metadata.getDirectoriesOfType(ExifDirectoryBase.class);
            for (ExifDirectoryBase exifDir : exifDirs) {
                if (exifDir.containsTag(TAG_ORIENTATION)) {
                    return exifDir.getInt(TAG_ORIENTATION);
                }
            }

            return ExifInterface.ORIENTATION_NORMAL;
        });
    }
Tries to read metadata from given stream, assuming it is an image data stream

@param description describes the stream. Used for logging in case of errors
@param imageStream image data stream
@param closeAfter  if true, stream is closed after read
@return Metadata read, or null if metadata could not be read
main/src/main/java/cgeo/geocaching/utils/MetadataUtils.java