Ignore:
Timestamp:
2015-03-10T01:17:39+01:00 (9 years ago)
Author:
Don-vip
Message:

fix #11162 - update to metadata-extractor 2.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/drew/metadata/jpeg/JpegCommentReader.java

    r6127 r8132  
    11/*
    2  * Copyright 2002-2012 Drew Noakes
     2 * Copyright 2002-2015 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    1616 * More information about this project is available at:
    1717 *
    18  *    http://drewnoakes.com/code/exif/
    19  *    http://code.google.com/p/metadata-extractor/
     18 *    https://drewnoakes.com/code/exif/
     19 *    https://github.com/drewnoakes/metadata-extractor
    2020 */
    2121package com.drew.metadata.jpeg;
    2222
    23 import com.drew.lang.BufferBoundsException;
    24 import com.drew.lang.BufferReader;
     23import com.drew.imaging.jpeg.JpegSegmentMetadataReader;
     24import com.drew.imaging.jpeg.JpegSegmentType;
    2525import com.drew.lang.annotations.NotNull;
    2626import com.drew.metadata.Metadata;
    27 import com.drew.metadata.MetadataReader;
     27
     28import java.util.Arrays;
    2829
    2930/**
    30  * Decodes the comment stored within Jpeg files, populating a <code>Metadata</code> object with tag values in a
    31  * <code>JpegCommentDirectory</code>.
     31 * Decodes the comment stored within JPEG files, populating a {@link Metadata} object with tag values in a
     32 * {@link JpegCommentDirectory}.
    3233 *
    33  * @author Drew Noakes http://drewnoakes.com
     34 * @author Drew Noakes https://drewnoakes.com
    3435 */
    35 public class JpegCommentReader implements MetadataReader
     36public class JpegCommentReader implements JpegSegmentMetadataReader
    3637{
    37     /**
    38      * Performs the Jpeg data extraction, adding found values to the specified
    39      * instance of <code>Metadata</code>.
    40      */
    41     public void extract(@NotNull final BufferReader reader, @NotNull Metadata metadata)
     38    @NotNull
     39    public Iterable<JpegSegmentType> getSegmentTypes()
     40    {
     41        return Arrays.asList(JpegSegmentType.COM);
     42    }
     43
     44    public boolean canProcess(@NotNull byte[] segmentBytes, @NotNull JpegSegmentType segmentType)
     45    {
     46        // The entire contents of the byte[] is the comment. There's nothing here to discriminate upon.
     47        return true;
     48    }
     49
     50    public void extract(@NotNull byte[] segmentBytes, @NotNull Metadata metadata, @NotNull JpegSegmentType segmentType)
    4251    {
    4352        JpegCommentDirectory directory = metadata.getOrCreateDirectory(JpegCommentDirectory.class);
    4453
    45         try {
    46             directory.setString(JpegCommentDirectory.TAG_JPEG_COMMENT, reader.getString(0, (int)reader.getLength()));
    47         } catch (BufferBoundsException e) {
    48             directory.addError("Exception reading JPEG comment string");
    49         }
     54        // The entire contents of the directory are the comment
     55        directory.setString(JpegCommentDirectory.TAG_COMMENT, new String(segmentBytes));
    5056    }
    5157}
Note: See TracChangeset for help on using the changeset viewer.