@Override public void onExtractionSuccess(@NotNull File file, @NotNull Metadata metadata, @NotNull String relativePath, @NotNull PrintStream log) { super.onExtractionSuccess(file, metadata, relativePath, log); for (Directory directory : metadata.getDirectories()) { for (Tag tag : directory.getTags()) { // Only interested in unknown tags (those without names) if (tag.hasTagName()) continue; HashMap<Integer, Integer> occurrenceCountByTag = _occurrenceCountByTagByDirectory.get(directory.getName()); if (occurrenceCountByTag == null) { occurrenceCountByTag = new HashMap<Integer, Integer>(); _occurrenceCountByTagByDirectory.put(directory.getName(), occurrenceCountByTag); } Integer count = occurrenceCountByTag.get(tag.getTagType()); if (count == null) { count = 0; occurrenceCountByTag.put(tag.getTagType(), 0); } occurrenceCountByTag.put(tag.getTagType(), count + 1); } } }
System.out.printf("%s|0x%s|%s|%s%n", directoryName, Integer.toHexString(tag.getTagType()), tagName, description);
/** * A basic representation of the tag's type and value. EG: <code>[Exif IFD0] FNumber - f/2.8</code>. * * @return the tag's type and value */ @Override @NotNull public String toString() { String description = getDescription(); if (description == null) description = _directory.getString(getTagType()) + " (unable to formulate description)"; return "[" + _directory.getName() + "] " + getTagName() + " - " + description; } }
description = ""; if (directory instanceof FileSystemDirectory && tag.getTagType() == FileSystemDirectory.TAG_FILE_MODIFIED_DATE) description = "<omitted for regression testing as checkout dependent>"; writer.format("[%s - %s] %s = %s%s", directoryName, tag.getTagTypeHex(), tagName, description, NEW_LINE);
if (directory != null) { for (Tag tag : directory.getTags()) { if (tag.getTagType() == ExifDirectoryBase.TAG_DATETIME) { dateTime = tag.getDescription();
@Override public void extractMetadata(File f, TypeDefinition td, Session session) throws MapperException { reset(); // see http://code.google.com/p/metadata-extractor/wiki/GettingStarted try { com.drew.metadata.Metadata metadata = ImageMetadataReader.readMetadata(f); Iterator<?> it = metadata.getDirectoryIterator(); while (it.hasNext()) { Directory directory = (com.drew.metadata.Directory) it.next(); Iterator<?> tagIt = directory.getTagIterator(); while (tagIt.hasNext()) { Tag tag = (Tag) tagIt.next(); Object o = directory.getObject(tag.getTagType()); LOG.debug("Tag: " + tag + ", value: " + o + ", class: " + o.getClass() + ", tag type: " + tag.getTagType() + ", hex-value: " + tag.getTagTypeHex()); if (null != cmisProperties) { ((PropertyMapperExif)mapper).mapTagAndConvert(directory, tag, td); } } } Map<String, Object> props = ((PropertyMapperExif)mapper).getMappedProperties(); cmisProperties.putAll(props); } catch (ImageProcessingException e) { LOG.error(e.toString(), e); } }
File pic = new File("C:/myPicture.jpg"); Metadata metadata = ImageMetadataReader.readMetadata(pic); for (Directory directory : metadata.getDirectories()) { for (Tag tag : directory.getTags()) { System.out.println(tag + " - " +tag.getTagType()); } }
System.out.printf("%s|0x%s|%s|%s%n", directoryName, Integer.toHexString(tag.getTagType()), tagName, description);
private void populateMetadata(Metadata metadata) { for (Iterator<?> di = metadata.getDirectories().iterator(); di.hasNext();) { Directory directory = (Directory) di.next(); Map<String, String> tags = new HashMap<String, String>(); put(directory.getName(), tags); for (Iterator<?> ti = directory.getTags().iterator(); ti.hasNext();) { Tag tag = (Tag) ti.next(); try { tags.put(tag.getTagName(), directory.getDescription(tag.getTagType())); } catch (Exception error) { errors.add(error); } } } }
description = ""; if (directory instanceof FileSystemDirectory && tag.getTagType() == FileSystemDirectory.TAG_FILE_MODIFIED_DATE) description = "<omitted for regression testing as checkout dependent>"; writer.format("[%s - %s] %s = %s%s", directoryName, tag.getTagTypeHex(), tagName, description, NEW_LINE);
/*************************************************************************** * * **************************************************************************/ @SuppressWarnings("unchecked") @Override public int[] getTags() { final int[] result = new int[directory.getTagCount()]; int j = 0; for (final Tag tag: directory.getTags()) { result[j++] = tag.getTagType(); } return result; }
@Override public void extractMetadata(byte[] bytes, Map<String, String> md) { BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(bytes)); try { Metadata metadata = ImageMetadataReader.readMetadata(bis, false); for (Directory directory : metadata.getDirectories()) { for (Tag tag : directory.getTags()) { String key = tag.getTagName(); if (md.containsKey(key)) { key = String.format("%s (%s)", tag.getTagName(), tag.getDirectoryName()); } String value = directory.getDescription(tag.getTagType()); if (StringUtils.isNotEmpty(value) && value.startsWith("[") && value.endsWith("bytes]")) { byte[] tagBytes = directory.getByteArray(tag.getTagType()); value = Base64.encodeBase64String(tagBytes); } md.put(key, value); } } } catch (Exception ex) { ex.printStackTrace(); } } }
@Override public void onExtractionSuccess(@NotNull File file, @NotNull Metadata metadata, @NotNull String relativePath, @NotNull PrintStream log) { super.onExtractionSuccess(file, metadata, relativePath, log); for (Directory directory : metadata.getDirectories()) { for (Tag tag : directory.getTags()) { // Only interested in unknown tags (those without names) if (tag.hasTagName()) continue; HashMap<Integer, Integer> occurrenceCountByTag = _occurrenceCountByTagByDirectory.get(directory.getName()); if (occurrenceCountByTag == null) { occurrenceCountByTag = new HashMap<Integer, Integer>(); _occurrenceCountByTagByDirectory.put(directory.getName(), occurrenceCountByTag); } Integer count = occurrenceCountByTag.get(tag.getTagType()); if (count == null) { count = 0; occurrenceCountByTag.put(tag.getTagType(), 0); } occurrenceCountByTag.put(tag.getTagType(), count + 1); } } }
String hexStr = getHexString(tag.getTagType()); } else { propMap.put(propId, dir.getObject(tag.getTagType()));
private static Object convertGps(Tag tag, Directory dir, boolean mustInvert) { Double res = null; Object src = dir.getObject(tag.getTagType()); Class<?> stringArrayClass = src.getClass(); Class<?> stringArrayComponentType = stringArrayClass.getComponentType(); if (!stringArrayClass.isArray() || null == stringArrayComponentType || Array.getLength(src) != 3) { throw new MapperException("GPS coordinate \"" + tag + "\" has unknown type."); } if (!stringArrayComponentType.equals(Rational.class)) { throw new MapperException("GPS coordinate \"" + tag + "\" has unknown component type (expected Rational, found: " + stringArrayComponentType.getName() + ")"); } // do conversion Rational[] components; components = (Rational[]) src; int deg = components[0].intValue(); double min = components[1].doubleValue(); double sec = components[2].doubleValue(); Double d = (deg + min / SECS_PER_MINUTE + sec / SECS_PER_HOUR); if (d > 0.0 && mustInvert) { d = -d; } res = d; return res; } }
public Object convertValue(Directory dir, Tag tag, PropertyType propType) { String hexStr = getHexString(tag.getTagType()); if (GpsDirectory.TAG_GPS_LONGITUDE == tag.getTagType()) { Object ref = dir.getObject(GpsDirectory.TAG_GPS_LONGITUDE_REF); boolean mustInv = (ref instanceof String) && ((String) ref).equals("W"); return convertGps(tag, dir, mustInv); } else if (GpsDirectory.TAG_GPS_LATITUDE == tag.getTagType()) { Object ref = dir.getObject(GpsDirectory.TAG_GPS_LONGITUDE_REF); boolean mustInv = (ref instanceof String) && ((String) ref).equals("S"); Object src = dir.getObject(tag.getTagType()); if (src instanceof Rational) { Object src = dir.getObject(tag.getTagType()); Class<?> clazz = src.getClass(); if (tag.getTagType() == ExifDirectory.TAG_SHUTTER_SPEED) { } else if (tag.getTagType() == (ExifDirectory.TAG_APERTURE)) { double aperture = ((Rational) src).doubleValue(); double fStop = PhotographicConversions.apertureToFStop(aperture); Object src = dir.getObject(tag.getTagType()); Class<?> clazz = src.getClass();
/** * A basic representation of the tag's type and value. EG: <code>[Exif IFD0] FNumber - f/2.8</code>. * * @return the tag's type and value */ @Override @NotNull public String toString() { String description = getDescription(); if (description == null) description = _directory.getString(getTagType()) + " (unable to formulate description)"; return "[" + _directory.getName() + "] " + getTagName() + " - " + description; } }
private void processGenericMetadataDirectory(final MapWriter writer, final GenericMetadataDirectory directory) { for (Tag tag : directory.getTags()) { try { final int tagType = tag.getTagType(); if (tagType != GenericMetadataDirectory.TAG_FILE_SIZE && tagType != GenericMetadataDirectory.TAG_FILE_DATE_TIME || fileSystemMetadata) { writeValue(writer, formatName(tag.getTagName()), descriptive ? directory.getDescription(tagType) : directory.getObject(tagType)); } } catch (Exception e) { // simply skip this tag } } }
private ExifMetadata getMetadataFromTag(Directory directory, Tag tag) throws MetadataException { ExifMetadata metadata = new ExifMetadata(); metadata.setDirectory(tag.getDirectoryName()); metadata.setKey(tag.getTagName()); metadata.setValue(tag.getDescription()); String values[]; Object value = directory.getObject(tag.getTagType()); if (value instanceof byte[]) { return null; } else if (value instanceof String) { values = new String[] {(String)value}; } else if (value instanceof String[]) { values = (String[])value; } else { values = new String[] {directory.getString(tag.getTagType())}; } values = decodeValues(values); metadata.setValues(values); return metadata; }
private void processDirectory(final MapWriter writer, final Directory directory, final Metadata metadata) { for (Tag tag : directory.getTags()) { try { final int tagType = tag.getTagType(); Object value; if (descriptive || isDescriptionTag(directory, tagType)) {