com.drew.metadata.Tag Java Examples

The following examples show how to use com.drew.metadata.Tag. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtractImageMetadata.java    From nifi with Apache License 2.0 6 votes vote down vote up
private Map<String, String> getTags(Integer max, Metadata metadata) {
    Map<String, String> results = new HashMap<>();
    int i =0;

    for (Directory directory : metadata.getDirectories()) {
        for (Tag tag : directory.getTags()) {
            results.put(directory.getName() + "." + tag.getTagName(), tag.getDescription());

            if(max!=null) {
                i++;
                if (i >= max) {
                    return results;
                }
            }
        }
    }

    return results;
}
 
Example #2
Source File: MetaDataTreeTableModel.java    From Pixelitor with GNU General Public License v3.0 6 votes vote down vote up
DirNode(Directory dir) {
    this.dir = dir;
    Collection<Tag> tags = dir.getTags();
    int tagIndex = 0;
    for (Tag tag : tags) {
        String tagName = tag.getTagName();
        if (tagName.startsWith("Unknown")) {
            continue;
        }
        String description = tag.getDescription();
        if (description != null && description.startsWith("Unknown")) {
            continue;
        }
        nodes.add(new TagNode(tagName, description, tagIndex));
        tagIndex++;
    }
}
 
Example #3
Source File: ImageResource.java    From entando-components with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Map<String, String> getImgMetadata(File file, List<String> ignoreKeysList) {
    logger.debug("Get image Metadata in Resource Action");
    Map<String, String> meta = new HashMap<>();
    try {
        Metadata metadata = ImageMetadataReader.readMetadata(file);

        for (Directory directory : metadata.getDirectories()) {
            for (Tag tag : directory.getTags()) {
                if (!ignoreKeysList.contains(tag.getTagName())) {
                    logger.debug("Add Metadata with key: {}", tag.getTagName());
                    meta.put(tag.getTagName(), tag.getDescription());
                } else {
                    logger.debug("Skip Metadata key {}", tag.getTagName());
                }
            }
        }
    } catch (ImageProcessingException|IOException ex) {
        logger.error("Error reading image metadata for file {}", file.getName(), ex);
    }
    return meta;
}
 
Example #4
Source File: IptcReaderTest.java    From metadata-extractor with Apache License 2.0 6 votes vote down vote up
@Test
public void testIptcEncodingUnknown() throws Exception
{
    IptcDirectory directory = processBytes("Tests/Data/iptc-encoding-unknown.bytes");

    assertFalse(directory.getErrors().toString(), directory.hasErrors());

    Tag[] tags = directory.getTags().toArray(new Tag[directory.getTagCount()]);
    assertEquals(3, tags.length);

    assertEquals(IptcDirectory.TAG_APPLICATION_RECORD_VERSION, tags[0].getTagType());
    assertEquals(2, directory.getObject(tags[0].getTagType()));

    assertEquals(IptcDirectory.TAG_CAPTION, tags[1].getTagType());
    assertEquals("Das Encoding dieser Metadaten ist nicht deklariert und lässt sich nur schwer erkennen.", directory.getStringValue(tags[1].getTagType()).toString());

    assertEquals(IptcDirectory.TAG_KEYWORDS, tags[2].getTagType());
    assertArrayEquals(new String[]{"häufig", "üblich", "Lösung", "Spaß"}, directory.getStringArray(tags[2].getTagType()));
}
 
Example #5
Source File: IptcReaderTest.java    From metadata-extractor with Apache License 2.0 6 votes vote down vote up
@Test
public void testIptcEncodingUndefinedIso() throws Exception
{
    IptcDirectory directory = processBytes("Tests/Data/iptc-encoding-undefined-iso.bytes");

    assertFalse(directory.getErrors().toString(), directory.hasErrors());

    Tag[] tags = directory.getTags().toArray(new Tag[directory.getTagCount()]);
    assertEquals(3, tags.length);

    assertEquals(IptcDirectory.TAG_ENVELOPE_RECORD_VERSION, tags[0].getTagType());
    assertEquals(2, directory.getObject(tags[0].getTagType()));

    assertEquals(IptcDirectory.TAG_APPLICATION_RECORD_VERSION, tags[1].getTagType());
    assertEquals(2, directory.getObject(tags[1].getTagType()));

    assertEquals(IptcDirectory.TAG_CAPTION, tags[2].getTagType());
    assertEquals("In diesem Text sind Umlaute enthalten, nämlich öfter als üblich: ÄÖÜäöüß\r", directory.getStringValue(tags[2].getTagType()).toString());
}
 
Example #6
Source File: IptcReaderTest.java    From metadata-extractor with Apache License 2.0 6 votes vote down vote up
@Test
public void testIptcEncodingUtf8() throws Exception
{
    IptcDirectory directory = processBytes("Tests/Data/iptc-encoding-defined-utf8.bytes");

    assertFalse(directory.getErrors().toString(), directory.hasErrors());

    Tag[] tags = directory.getTags().toArray(new Tag[directory.getTagCount()]);
    assertEquals(4, tags.length);

    assertEquals(IptcDirectory.TAG_ENVELOPE_RECORD_VERSION, tags[0].getTagType());
    assertEquals(2, directory.getObject(tags[0].getTagType()));

    assertEquals(IptcDirectory.TAG_CODED_CHARACTER_SET, tags[1].getTagType());
    assertEquals("UTF-8", directory.getObject(tags[1].getTagType()));

    assertEquals(IptcDirectory.TAG_APPLICATION_RECORD_VERSION, tags[2].getTagType());
    assertEquals(2, directory.getObject(tags[2].getTagType()));

    assertEquals(IptcDirectory.TAG_CAPTION, tags[3].getTagType());
    assertEquals("In diesem Text sind Umlaute enthalten, nämlich öfter als üblich: ÄÖÜäöüß\r", directory.getStringValue(tags[3].getTagType()).toString());
}
 
Example #7
Source File: MetadataProcessor.java    From FakeImageDetection with GNU General Public License v3.0 6 votes vote down vote up
public MetadataProcessor(File imageFile) {
    this.imageFile = imageFile;
    try {
        data = ImageMetadataReader.readMetadata(imageFile);
    } catch (Exception ex) {
        Logger.getLogger(MetadataProcessor.class.getName()).log(Level.SEVERE, null, ex);
    }
    
    for (Directory directory : data.getDirectories()) {
        extracted_data += String.format("----------------------------------------------%15s---------------------------------\n", directory.getName());
        for (Tag tag : directory.getTags()) {
            extracted_data += tag + "\n";
        }
        if (directory.hasErrors()) {
            for (String error : directory.getErrors()) {
                System.err.println("ERROR: " + error);
            }
        }
    }
}
 
Example #8
Source File: ExtractImageMetadata.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private Map<String, String> getTags(Integer max, Metadata metadata) {
    Map<String, String> results = new HashMap<>();
    int i =0;

    for (Directory directory : metadata.getDirectories()) {
        for (Tag tag : directory.getTags()) {
            results.put(directory.getName() + "." + tag.getTagName(), tag.getDescription());

            if(max!=null) {
                i++;
                if (i >= max) {
                    return results;
                }
            }
        }
    }

    return results;
}
 
Example #9
Source File: SampleProcessor.java    From tutorials with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void process(Record record, SingleLaneBatchMaker batchMaker) throws StageException {
  LOG.info("Input record: {}", record);

  FileRef fileRef = record.get("/fileRef").getValueAsFileRef();
  Metadata metadata;
  try {
    metadata = ImageMetadataReader.readMetadata(fileRef.createInputStream(getContext(), InputStream.class));
  } catch (ImageProcessingException | IOException e) {
    String filename = record.get("/fileInfo/filename").getValueAsString();
    LOG.info("Exception getting metadata from {}", filename, e);
    throw new OnRecordErrorException(record, Errors.SAMPLE_02, e);
  }

  for (Directory directory : metadata.getDirectories()) {
    LinkedHashMap<String, Field> listMap = new LinkedHashMap<>();

    for (Tag tag : directory.getTags()) {
      listMap.put(tag.getTagName(), Field.create(tag.getDescription()));
    }

    if (directory.hasErrors()) {
      for (String error : directory.getErrors()) {
        LOG.info("ERROR: {}", error);
      }
    }

    record.set("/" + directory.getName(), Field.createListMap(listMap));
  }

  LOG.info("Output record: {}", record);

  batchMaker.addRecord(record);
}
 
Example #10
Source File: ProcessAllImagesInFolderUtility.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example #11
Source File: ProcessAllImagesInFolderUtility.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@Override
public void onExtractionSuccess(@NotNull File file, @NotNull Metadata metadata, @NotNull String relativePath, @NotNull PrintStream log)
{
    super.onExtractionSuccess(file, metadata, relativePath, log);

    // Iterate through all values, calling toString to flush out any formatting exceptions
    for (Directory directory : metadata.getDirectories()) {
        directory.getName();
        for (Tag tag : directory.getTags()) {
            tag.getTagName();
            tag.getDescription();
        }
    }
}
 
Example #12
Source File: ImageRecordReader.java    From Bats with Apache License 2.0 5 votes vote down vote up
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
    }
  }
}
 
Example #13
Source File: ResourceAction.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected Map getImgMetadata(File file) {
    logger.debug("Get image Metadata in Resource Action");
    Map<String, String> meta = new HashMap<>();
    ResourceInterface resourcePrototype = this.getResourceManager().createResourceType(this.getResourceType());
    try {
        Metadata metadata = ImageMetadataReader.readMetadata(file);
        String ignoreKeysConf = resourcePrototype.getMetadataIgnoreKeys();
        String[] ignoreKeys = null;
        if (null != ignoreKeysConf) {
            ignoreKeys = ignoreKeysConf.split(",");
            logger.debug("Metadata ignoreKeys: {}", ignoreKeys);
        } else {
            logger.debug("Metadata ignoreKeys not configured");
        }
        List<String> ignoreKeysList = new ArrayList<String>();
        if (null != ignoreKeys) {
            ignoreKeysList = Arrays.asList(ignoreKeys);
        }
        for (Directory directory : metadata.getDirectories()) {
            for (Tag tag : directory.getTags()) {
                if (!ignoreKeysList.contains(tag.getTagName())) {
                    logger.debug("Add Metadata with key: {}", tag.getTagName());
                    meta.put(tag.getTagName(), tag.getDescription());
                } else {
                    logger.debug("Skip Metadata key {}", tag.getTagName());
                }
            }
        }
    } catch (ImageProcessingException ex) {
        logger.error("Error reading metadata from file " + this.getFileName() + " - message " + ex.getMessage());
    } catch (IOException ioex) {
        logger.error("Error reading file", ioex);
    }
    return meta;
}
 
Example #14
Source File: MutableImage.java    From react-native-camera-face-detector with MIT License 5 votes vote down vote up
public void writeDataToFile(File file, ReadableMap options, int jpegQualityPercent) throws IOException {
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(toJpeg(currentRepresentation, jpegQualityPercent));
    fos.close();

    try {
        ExifInterface exif = new ExifInterface(file.getAbsolutePath());

        // copy original exif data to the output exif...
        // unfortunately, this Android ExifInterface class doesn't understand all the tags so we lose some
        for (Directory directory : originalImageMetaData().getDirectories()) {
            for (Tag tag : directory.getTags()) {
                int tagType = tag.getTagType();
                Object object = directory.getObject(tagType);
                exif.setAttribute(tag.getTagName(), object.toString());
            }
        }

        writeLocationExifData(options, exif);

        if(hasBeenReoriented)
            rewriteOrientation(exif);

        exif.saveAttributes();
    } catch (ImageProcessingException  | IOException e) {
        Log.e(TAG, "failed to save exif data", e);
    }
}
 
Example #15
Source File: ImageDataReader.java    From java-11-examples with Apache License 2.0 5 votes vote down vote up
public static ImageInfo getImageInfo(InputStream imageStream) throws ImageProcessingException, IOException {
    Metadata metadata = ImageMetadataReader.readMetadata(imageStream);
    ImageInfo.Builder builder = new ImageInfo.Builder();
    for (Directory directory: metadata.getDirectories()) {
        for (Tag tag: directory.getTags()) {
            if (ParsingUtils.IMAGE_HEIGHT.equals(tag.getTagName())) {
                builder.setPixelsY(ParsingUtils.getIntegerFromData(tag.getDescription()));
            } else if (ParsingUtils.IMAGE_WIDTH.equals(tag.getTagName())) {
                builder.setPixelsX(ParsingUtils.getIntegerFromData(tag.getDescription()));
            }
        }
    }
    return builder.build();
}
 
Example #16
Source File: IptcReaderTest.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@Test
public void testIptcEncodingUnknown2() throws Exception
{
    // This metadata has an encoding of three characters [ \ESC '%' '5' ]
    // It's not clear what to do with this, so it should be ignored.
    // Version 2.7.0 tripped up on this and threw an exception.
    IptcDirectory directory = processBytes("Tests/Data/iptc-encoding-unknown-2.bytes");

    assertFalse(directory.getErrors().toString(), directory.hasErrors());

    Tag[] tags = directory.getTags().toArray(new Tag[directory.getTagCount()]);
    assertEquals(37, tags.length);

    assertEquals("MEDWAS,MEDLON,MEDTOR,RONL,ASIA,AONL,APC,USA,CAN,SAM,BIZ", directory.getString(IptcDirectory.TAG_DESTINATION));
}
 
Example #17
Source File: MetadataHelper.java    From leafpicrevived with GNU General Public License v3.0 5 votes vote down vote up
public MediaDetailsMap<String, String> getAllDetails(Context context, Media media) {
    MediaDetailsMap<String, String> data = new MediaDetailsMap<String, String>();
    try {
        Metadata metadata = ImageMetadataReader.readMetadata(context.getContentResolver().openInputStream(media.getUri()));
        for (Directory directory : metadata.getDirectories()) {

            for (Tag tag : directory.getTags()) {
                data.put(tag.getTagName(), directory.getObject(tag.getTagType()) + "");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return data;
}
 
Example #18
Source File: IptcReaderTest.java    From metadata-extractor with Apache License 2.0 4 votes vote down vote up
@Test
public void testIptc1BytesFromFile() throws Exception
{
    IptcDirectory directory = processBytes("Tests/Data/iptc1.jpg.appd");

    assertFalse(directory.getErrors().toString(), directory.hasErrors());

    Tag[] tags = directory.getTags().toArray(new Tag[directory.getTagCount()]);
    assertEquals(16, tags.length);

    assertEquals(IptcDirectory.TAG_CATEGORY, tags[0].getTagType());
    assertArrayEquals(new String[] { "Supl. Category2", "Supl. Category1", "Cat" }, directory.getStringArray(tags[0].getTagType()));

    assertEquals(IptcDirectory.TAG_COPYRIGHT_NOTICE, tags[1].getTagType());
    assertEquals("Copyright", directory.getString(tags[1].getTagType()));

    assertEquals(IptcDirectory.TAG_SPECIAL_INSTRUCTIONS, tags[2].getTagType());
    assertEquals("Special Instr.", directory.getString(tags[2].getTagType()));

    assertEquals(IptcDirectory.TAG_HEADLINE, tags[3].getTagType());
    assertEquals("Headline", directory.getString(tags[3].getTagType()));

    assertEquals(IptcDirectory.TAG_CAPTION_WRITER, tags[4].getTagType());
    assertEquals("CaptionWriter", directory.getString(tags[4].getTagType()));

    assertEquals(IptcDirectory.TAG_CAPTION, tags[5].getTagType());
    assertEquals("Caption", directory.getString(tags[5].getTagType()));

    assertEquals(IptcDirectory.TAG_ORIGINAL_TRANSMISSION_REFERENCE, tags[6].getTagType());
    assertEquals("Transmission", directory.getString(tags[6].getTagType()));

    assertEquals(IptcDirectory.TAG_COUNTRY_OR_PRIMARY_LOCATION_NAME, tags[7].getTagType());
    assertEquals("Country", directory.getString(tags[7].getTagType()));

    assertEquals(IptcDirectory.TAG_PROVINCE_OR_STATE, tags[8].getTagType());
    assertEquals("State", directory.getString(tags[8].getTagType()));

    assertEquals(IptcDirectory.TAG_CITY, tags[9].getTagType());
    assertEquals("City", directory.getString(tags[9].getTagType()));

    assertEquals(IptcDirectory.TAG_DATE_CREATED, tags[10].getTagType());
    assertEquals("20000101", directory.getString(tags[10].getTagType()));

    assertEquals(IptcDirectory.TAG_OBJECT_NAME, tags[11].getTagType());
    assertEquals("ObjectName", directory.getString(tags[11].getTagType()));

    assertEquals(IptcDirectory.TAG_SOURCE, tags[12].getTagType());
    assertEquals("Source", directory.getString(tags[12].getTagType()));

    assertEquals(IptcDirectory.TAG_CREDIT, tags[13].getTagType());
    assertEquals("Credits", directory.getString(tags[13].getTagType()));

    assertEquals(IptcDirectory.TAG_BY_LINE_TITLE, tags[14].getTagType());
    assertEquals("BylineTitle", directory.getString(tags[14].getTagType()));

    assertEquals(IptcDirectory.TAG_BY_LINE, tags[15].getTagType());
    assertEquals("Byline", directory.getString(tags[15].getTagType()));
}
 
Example #19
Source File: JfifReaderTest.java    From metadata-extractor with Apache License 2.0 4 votes vote down vote up
@Test public void testRead() throws Exception
{
    final byte[] jfifData = new byte[] {
        74,70,73,70,0,
        1,2,
        1,
        0,108,
        0,108,
        0,0
    };

    final Metadata metadata = new Metadata();
    final JfifReader reader = new JfifReader();
    reader.extract(new ByteArrayReader(jfifData), metadata);

    assertEquals(1, metadata.getDirectoryCount());
    JfifDirectory directory = metadata.getFirstDirectoryOfType(JfifDirectory.class);
    assertNotNull(directory);
    assertFalse(directory.getErrors().toString(), directory.hasErrors());

    Tag[] tags = directory.getTags().toArray(new Tag[directory.getTagCount()]);
    assertEquals(6, tags.length);

    assertEquals(JfifDirectory.TAG_VERSION, tags[0].getTagType());
    assertEquals(0x0102, directory.getInt(tags[0].getTagType()));

    assertEquals(JfifDirectory.TAG_UNITS, tags[1].getTagType());
    assertEquals(1, directory.getInt(tags[1].getTagType()));

    assertEquals(JfifDirectory.TAG_RESX, tags[2].getTagType());
    assertEquals(108, directory.getInt(tags[2].getTagType()));

    assertEquals(JfifDirectory.TAG_RESY, tags[3].getTagType());
    assertEquals(108, directory.getInt(tags[3].getTagType()));

    assertEquals(JfifDirectory.TAG_THUMB_WIDTH, tags[4].getTagType());
    assertEquals(0, directory.getInt(tags[4].getTagType()));

    assertEquals(JfifDirectory.TAG_THUMB_HEIGHT, tags[5].getTagType());
    assertEquals(0, directory.getInt(tags[5].getTagType()));
}
 
Example #20
Source File: IptcReaderTest.java    From metadata-extractor with Apache License 2.0 4 votes vote down vote up
@Test
public void testIptc2Photoshop6BytesFromFile() throws Exception
{
    IptcDirectory directory = processBytes("Tests/Data/iptc2-photoshop6.jpg.appd");

    assertFalse(directory.getErrors().toString(), directory.hasErrors());

    Tag[] tags = directory.getTags().toArray(new Tag[directory.getTagCount()]);
    assertEquals(17, tags.length);

    assertEquals(IptcDirectory.TAG_APPLICATION_RECORD_VERSION, tags[0].getTagType());
    assertEquals(2, directory.getObject(tags[0].getTagType()));

    assertEquals(IptcDirectory.TAG_CAPTION, tags[1].getTagType());
    assertEquals("Caption PS6", directory.getString(tags[1].getTagType()));

    assertEquals(IptcDirectory.TAG_CAPTION_WRITER, tags[2].getTagType());
    assertEquals("CaptionWriter", directory.getString(tags[2].getTagType()));

    assertEquals(IptcDirectory.TAG_HEADLINE, tags[3].getTagType());
    assertEquals("Headline", directory.getString(tags[3].getTagType()));

    assertEquals(IptcDirectory.TAG_SPECIAL_INSTRUCTIONS, tags[4].getTagType());
    assertEquals("Special Instr.", directory.getString(tags[4].getTagType()));

    assertEquals(IptcDirectory.TAG_BY_LINE, tags[5].getTagType());
    assertEquals("Byline", directory.getString(tags[5].getTagType()));

    assertEquals(IptcDirectory.TAG_BY_LINE_TITLE, tags[6].getTagType());
    assertEquals("BylineTitle", directory.getString(tags[6].getTagType()));

    assertEquals(IptcDirectory.TAG_CREDIT, tags[7].getTagType());
    assertEquals("Credits", directory.getString(tags[7].getTagType()));

    assertEquals(IptcDirectory.TAG_SOURCE, tags[8].getTagType());
    assertEquals("Source", directory.getString(tags[8].getTagType()));

    assertEquals(IptcDirectory.TAG_OBJECT_NAME, tags[9].getTagType());
    assertEquals("ObjectName", directory.getString(tags[9].getTagType()));

    assertEquals(IptcDirectory.TAG_CITY, tags[10].getTagType());
    assertEquals("City", directory.getString(tags[10].getTagType()));

    assertEquals(IptcDirectory.TAG_PROVINCE_OR_STATE, tags[11].getTagType());
    assertEquals("State", directory.getString(tags[11].getTagType()));

    assertEquals(IptcDirectory.TAG_COUNTRY_OR_PRIMARY_LOCATION_NAME, tags[12].getTagType());
    assertEquals("Country", directory.getString(tags[12].getTagType()));

    assertEquals(IptcDirectory.TAG_ORIGINAL_TRANSMISSION_REFERENCE, tags[13].getTagType());
    assertEquals("Transmission", directory.getString(tags[13].getTagType()));

    assertEquals(IptcDirectory.TAG_CATEGORY, tags[14].getTagType());
    assertEquals("Cat", directory.getString(tags[14].getTagType()));

    assertEquals(IptcDirectory.TAG_SUPPLEMENTAL_CATEGORIES, tags[15].getTagType());
    assertArrayEquals(new String[] { "Supl. Category1", "Supl. Category2" }, directory.getStringArray(tags[15].getTagType()));

    assertEquals(IptcDirectory.TAG_COPYRIGHT_NOTICE, tags[16].getTagType());
    assertEquals("Copyright", directory.getString(tags[16].getTagType()));
}
 
Example #21
Source File: ImageRecordReader.java    From Bats with Apache License 2.0 4 votes vote down vote up
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)) {
        value = directory.getDescription(tagType);
        if (directory instanceof PngDirectory) {
          if (((PngDirectory) directory).getPngChunkType().areMultipleAllowed()) {
            value = new String[] { (String) value };
          }
        }
      } else {
        value = directory.getObject(tagType);
        if (directory instanceof ExifIFD0Directory && tagType == ExifIFD0Directory.TAG_DATETIME) {
          ExifSubIFDDirectory exifSubIFDDir = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
          String subsecond = null;
          if (exifSubIFDDir != null) {
            subsecond = exifSubIFDDir.getString(ExifSubIFDDirectory.TAG_SUBSECOND_TIME);
          }
          value = directory.getDate(tagType, subsecond, timeZone);
        } else if (directory instanceof ExifSubIFDDirectory) {
          if (tagType == ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL) {
            value = ((ExifSubIFDDirectory) directory).getDateOriginal(timeZone);
          } else if (tagType == ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED) {
            value = ((ExifSubIFDDirectory) directory).getDateDigitized(timeZone);
          }
        } else if (directory instanceof GpsDirectory) {
          if (tagType == GpsDirectory.TAG_LATITUDE) {
            value = ((GpsDirectory) directory).getGeoLocation().getLatitude();
          } else if (tagType == GpsDirectory.TAG_LONGITUDE) {
            value = ((GpsDirectory) directory).getGeoLocation().getLongitude();
          }
        }
        if (isVersionTag(directory, tagType)) {
          value = directory.getString(tagType, "US-ASCII");
        } else if (isDateTag(directory, tagType)) {
          value = directory.getDate(tagType, timeZone);
        }
      }
      writeValue(writer, formatName(tag.getTagName()), value);
    } catch (Exception e) {
      // simply skip this tag
    }
  }
}