Changeset 8132 in josm for trunk/src/com/drew/metadata/jpeg/JpegCommentReader.java
- Timestamp:
- 2015-03-10T01:17:39+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/drew/metadata/jpeg/JpegCommentReader.java
r6127 r8132 1 1 /* 2 * Copyright 2002-201 2Drew Noakes2 * Copyright 2002-2015 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 16 16 * More information about this project is available at: 17 17 * 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 20 20 */ 21 21 package com.drew.metadata.jpeg; 22 22 23 import com.drew. lang.BufferBoundsException;24 import com.drew. lang.BufferReader;23 import com.drew.imaging.jpeg.JpegSegmentMetadataReader; 24 import com.drew.imaging.jpeg.JpegSegmentType; 25 25 import com.drew.lang.annotations.NotNull; 26 26 import com.drew.metadata.Metadata; 27 import com.drew.metadata.MetadataReader; 27 28 import java.util.Arrays; 28 29 29 30 /** 30 * Decodes the comment stored within J peg files, populating a <code>Metadata</code>object with tag values in a31 * <code>JpegCommentDirectory</code>.31 * Decodes the comment stored within JPEG files, populating a {@link Metadata} object with tag values in a 32 * {@link JpegCommentDirectory}. 32 33 * 33 * @author Drew Noakes http ://drewnoakes.com34 * @author Drew Noakes https://drewnoakes.com 34 35 */ 35 public class JpegCommentReader implements MetadataReader36 public class JpegCommentReader implements JpegSegmentMetadataReader 36 37 { 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) 42 51 { 43 52 JpegCommentDirectory directory = metadata.getOrCreateDirectory(JpegCommentDirectory.class); 44 53 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)); 50 56 } 51 57 }
Note:
See TracChangeset
for help on using the changeset viewer.