Directory directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class); JpegDirectory jpegDirectory = metadata.getFirstDirectoryOfType(JpegDirectory.class);
@NotNull private Directory getCurrentOrErrorDirectory() { if (_currentDirectory != null) return _currentDirectory; ErrorDirectory error = _metadata.getFirstDirectoryOfType(ErrorDirectory.class); if (error != null) return error; pushDirectory(ErrorDirectory.class); return _currentDirectory; }
public void read(@NotNull File file, @NotNull Metadata metadata) throws IOException { if (!file.isFile()) throw new IOException("File object must reference a file"); if (!file.exists()) throw new IOException("File does not exist"); if (!file.canRead()) throw new IOException("File is not readable"); FileSystemDirectory directory = metadata.getFirstDirectoryOfType(FileSystemDirectory.class); if (directory == null) { directory = new FileSystemDirectory(); metadata.addDirectory(directory); } directory.setString(FileSystemDirectory.TAG_FILE_NAME, file.getName()); directory.setLong(FileSystemDirectory.TAG_FILE_SIZE, file.length()); directory.setDate(FileSystemDirectory.TAG_FILE_MODIFIED_DATE, new Date(file.lastModified())); } }
this.relativePath = relativePath; ExifIFD0Directory ifd0Dir = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class); ExifSubIFDDirectory subIfdDir = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class); ExifThumbnailDirectory thumbDir = metadata.getFirstDirectoryOfType(ExifThumbnailDirectory.class); if (ifd0Dir != null) { manufacturer = ifd0Dir.getDescription(ExifIFD0Directory.TAG_MAKE);
String fileName = file.getName(); String urlName = StringUtil.urlEncode(filePath); ExifIFD0Directory exifIFD0Directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class); String make = exifIFD0Directory == null ? "" : exifIFD0Directory.getString(ExifIFD0Directory.TAG_MAKE); String model = exifIFD0Directory == null ? "" : exifIFD0Directory.getString(ExifIFD0Directory.TAG_MODEL);
protected void addError(@NotNull String errorMessage, final @NotNull Metadata metadata) { ErrorDirectory directory = metadata.getFirstDirectoryOfType(ErrorDirectory.class); if (directory == null) { metadata.addDirectory(new ErrorDirectory(errorMessage)); } else { directory.addError(errorMessage); } } }
/** * Serializes the XmpDirectory component of <code>Metadata</code> into an <code>OutputStream</code> * @param os Destination for the xmp data * @param data populated metadata * @return serialize success */ public static boolean write(OutputStream os, Metadata data) { XmpDirectory dir = data.getFirstDirectoryOfType(XmpDirectory.class); if (dir == null) return false; XMPMeta meta = dir.getXMPMeta(); try { SerializeOptions so = new SerializeOptions().setOmitPacketWrapper(true); XMPMetaFactory.serialize(meta, os, so); } catch (XMPException e) { e.printStackTrace(); return false; } return true; } }
public void extract(byte[] segmentBytes, Metadata metadata, JpegSegmentType segmentType) { JpegDirectory directory = metadata.getFirstDirectoryOfType(JpegDirectory.class); if (directory == null) { ErrorDirectory errorDirectory = new ErrorDirectory(); metadata.addDirectory(errorDirectory); errorDirectory.addError("DNL segment found without SOFx - illegal JPEG format"); return; } SequentialReader reader = new SequentialByteArrayReader(segmentBytes); try { // Only set height from DNL if it's not already defined Integer i = directory.getInteger(JpegDirectory.TAG_IMAGE_HEIGHT); if (i == null || i == 0) { directory.setInt(JpegDirectory.TAG_IMAGE_HEIGHT, reader.getUInt16()); } } catch (IOException ex) { directory.addError(ex.getMessage()); } } }
Directory directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class); if (directory != null) { for (Tag tag : directory.getTags()) {
/** * Performs the DHT tables extraction, adding found tables to the specified * instance of {@link Metadata}. */ public void extract(@NotNull final SequentialReader reader, @NotNull final Metadata metadata) { HuffmanTablesDirectory directory = metadata.getFirstDirectoryOfType(HuffmanTablesDirectory.class); if (directory == null) { directory = new HuffmanTablesDirectory(); metadata.addDirectory(directory); } try { while (reader.available() > 0) { byte header = reader.getByte(); HuffmanTableClass tableClass = HuffmanTableClass.typeOf((header & 0xF0) >> 4); int tableDestinationId = header & 0xF; byte[] lBytes = getBytes(reader, 16); int vCount = 0; for (byte b : lBytes) { vCount += (b & 0xFF); } byte[] vBytes = getBytes(reader, vCount); directory.getTables().add(new HuffmanTable(tableClass, tableDestinationId, lBytes, vBytes)); } } catch (IOException me) { directory.addError(me.getMessage()); } directory.setInt(HuffmanTablesDirectory.TAG_NUMBER_OF_TABLES, directory.getTables().size()); }
Directory ifd0Directory = _metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
private static int readExifOrientation(Metadata metadata) throws MetadataException { Directory directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class); return directory.getInt(ExifIFD0Directory.TAG_ORIENTATION); }
private static int readExifOrientation(Metadata metadata) throws MetadataException { Directory directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class); return directory.getInt(ExifIFD0Directory.TAG_ORIENTATION); }
@NotNull private Directory getCurrentOrErrorDirectory() { if (_currentDirectory != null) return _currentDirectory; ErrorDirectory error = _metadata.getFirstDirectoryOfType(ErrorDirectory.class); if (error != null) return error; pushDirectory(ErrorDirectory.class); return _currentDirectory; }
public void read(@NotNull File file, @NotNull Metadata metadata) throws IOException { if (!file.isFile()) throw new IOException("File object must reference a file"); if (!file.exists()) throw new IOException("File does not exist"); if (!file.canRead()) throw new IOException("File is not readable"); FileSystemDirectory directory = metadata.getFirstDirectoryOfType(FileSystemDirectory.class); if (directory == null) { directory = new FileSystemDirectory(); metadata.addDirectory(directory); } directory.setString(FileSystemDirectory.TAG_FILE_NAME, file.getName()); directory.setLong(FileSystemDirectory.TAG_FILE_SIZE, file.length()); directory.setDate(FileSystemDirectory.TAG_FILE_MODIFIED_DATE, new Date(file.lastModified())); } }
private static ImageTransform getImageTransformFromMetadata(Metadata metadata) { //new ImageTransform(false, 0) is the original image orientation, with no flip needed, and no rotation needed. ImageTransform imageTransform = getNoFlipNoRotationImageTransform(); if (metadata != null) { ExifIFD0Directory directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class); if (directory != null) { Integer orientationInteger = directory.getInteger(ExifIFD0Directory.TAG_ORIENTATION); if (orientationInteger != null) { imageTransform = convertOrientationToTransform(orientationInteger); } } } return imageTransform; }
protected void addError(@NotNull String errorMessage, final @NotNull Metadata metadata) { ErrorDirectory directory = metadata.getFirstDirectoryOfType(ErrorDirectory.class); if (directory == null) { metadata.addDirectory(new ErrorDirectory(errorMessage)); } else { directory.addError(errorMessage); } } }
/** * Serializes the XmpDirectory component of <code>Metadata</code> into an <code>OutputStream</code> * @param os Destination for the xmp data * @param data populated metadata * @return serialize success */ public static boolean write(OutputStream os, Metadata data) { XmpDirectory dir = data.getFirstDirectoryOfType(XmpDirectory.class); if (dir == null) return false; XMPMeta meta = dir.getXMPMeta(); try { SerializeOptions so = new SerializeOptions().setOmitPacketWrapper(true); XMPMetaFactory.serialize(meta, os, so); } catch (XMPException e) { e.printStackTrace(); return false; } return true; } }
public void extract(byte[] segmentBytes, Metadata metadata, JpegSegmentType segmentType) { JpegDirectory directory = metadata.getFirstDirectoryOfType(JpegDirectory.class); if (directory == null) { ErrorDirectory errorDirectory = new ErrorDirectory(); metadata.addDirectory(errorDirectory); errorDirectory.addError("DNL segment found without SOFx - illegal JPEG format"); return; } SequentialReader reader = new SequentialByteArrayReader(segmentBytes); try { // Only set height from DNL if it's not already defined Integer i = directory.getInteger(JpegDirectory.TAG_IMAGE_HEIGHT); if (i == null || i == 0) { directory.setInt(JpegDirectory.TAG_IMAGE_HEIGHT, reader.getUInt16()); } } catch (IOException ex) { directory.addError(ex.getMessage()); } } }
/** * Performs the DHT tables extraction, adding found tables to the specified * instance of {@link Metadata}. */ public void extract(@NotNull final SequentialReader reader, @NotNull final Metadata metadata) { HuffmanTablesDirectory directory = metadata.getFirstDirectoryOfType(HuffmanTablesDirectory.class); if (directory == null) { directory = new HuffmanTablesDirectory(); metadata.addDirectory(directory); } try { while (reader.available() > 0) { byte header = reader.getByte(); HuffmanTableClass tableClass = HuffmanTableClass.typeOf((header & 0xF0) >> 4); int tableDestinationId = header & 0xF; byte[] lBytes = getBytes(reader, 16); int vCount = 0; for (byte b : lBytes) { vCount += (b & 0xFF); } byte[] vBytes = getBytes(reader, vCount); directory.getTables().add(new HuffmanTable(tableClass, tableDestinationId, lBytes, vBytes)); } } catch (IOException me) { directory.addError(me.getMessage()); } directory.setInt(HuffmanTablesDirectory.TAG_NUMBER_OF_TABLES, directory.getTables().size()); }