Package com.drew.metadata.eps
Class EpsReader
- java.lang.Object
-
- com.drew.metadata.eps.EpsReader
-
public class EpsReader extends java.lang.ObjectReads file passed in through SequentialReader and parses encountered data:- Basic EPS Comments
- EXIF
- Photoshop
- IPTC
- ICC Profile
- XMP
- Max line length is 255 characters
- Lines end with a CR(0xD) or LF(0xA) character (or both, in practice)
- ':' separates keywords (considered part of the keyword)
- Whitespace is either a space(0x20) or tab(0x9)
- If there is more than one header, the 1st is truth
-
-
Field Summary
Fields Modifier and Type Field Description private int_previousTag
-
Constructor Summary
Constructors Constructor Description EpsReader()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddToDirectory(EpsDirectory directory, java.lang.String name, java.lang.String value)Default case that adds comment with keyword to directoryprivate static byte[]decodeHexCommentBlock(SequentialReader reader)EPS files can contain hexadecimal-encoded ASCII blocks, each prefixed with"% " .private voidextract(EpsDirectory directory, Metadata metadata, SequentialReader reader)Main method that parses all comments and then distributes data extraction among other methods that parse the rest of file and store encountered data in metadata (if there exists an entry in EpsDirectory for the found data).voidextract(java.io.InputStream inputStream, Metadata metadata)Filter method that determines if file will contain an EPS Header.private static voidextractIccData(Metadata metadata, SequentialReader reader)Decodes a commented hex section, and usesIccReaderto decode the resulting data.private static voidextractImageData(EpsDirectory directory, java.lang.String imageData)Parses%ImageDatacomment which holds several values including width in px, height in px and color type.private static voidextractPhotoshopData(Metadata metadata, SequentialReader reader)Decodes a commented hex section, and usesPhotoshopReaderto decode the resulting data.private static voidextractXmpData(Metadata metadata, SequentialReader reader)Extracts an XMP xpacket, and usesXmpReaderto decode the resulting data.private static byte[]readUntil(SequentialReader reader, byte[] sentinel)Reads all bytes until the given sentinel is observed.private static inttryHexToInt(byte b)Treats a byte as an ASCII character, and returns it's numerical value in hexadecimal.
-
-
-
Method Detail
-
extract
public void extract(java.io.InputStream inputStream, Metadata metadata) throws java.io.IOExceptionFilter method that determines if file will contain an EPS Header. If it does, it will read the necessary data and then set the position to the beginning of the PostScript data. If it does not, the position will not be changed. After both scenarios, the main extract method is called.- Parameters:
inputStream- InputStream containing filemetadata- Metadata to add directory to and extracted data- Throws:
java.io.IOException
-
extract
private void extract(EpsDirectory directory, Metadata metadata, SequentialReader reader) throws java.io.IOException
Main method that parses all comments and then distributes data extraction among other methods that parse the rest of file and store encountered data in metadata (if there exists an entry in EpsDirectory for the found data). Reads until a begin data/binary comment is found or _reader's estimated available data has run out (or AI09 End Private Data). Will extract data from normal EPS comments, Photoshop, ICC, and XMP.- Parameters:
metadata- Metadata to add directory to and extracted data- Throws:
java.io.IOException
-
addToDirectory
private void addToDirectory(EpsDirectory directory, java.lang.String name, java.lang.String value) throws java.io.IOException
Default case that adds comment with keyword to directory- Parameters:
directory- EpsDirectory to add extracted data toname- String that holds name of current commentvalue- String that holds value of current comment- Throws:
java.io.IOException
-
extractImageData
private static void extractImageData(EpsDirectory directory, java.lang.String imageData) throws java.io.IOException
Parses%ImageDatacomment which holds several values including width in px, height in px and color type.- Throws:
java.io.IOException
-
extractPhotoshopData
private static void extractPhotoshopData(Metadata metadata, SequentialReader reader) throws java.io.IOException
Decodes a commented hex section, and usesPhotoshopReaderto decode the resulting data.- Throws:
java.io.IOException
-
extractIccData
private static void extractIccData(Metadata metadata, SequentialReader reader) throws java.io.IOException
Decodes a commented hex section, and usesIccReaderto decode the resulting data.- Throws:
java.io.IOException
-
extractXmpData
private static void extractXmpData(Metadata metadata, SequentialReader reader) throws java.io.IOException
Extracts an XMP xpacket, and usesXmpReaderto decode the resulting data.- Throws:
java.io.IOException
-
readUntil
private static byte[] readUntil(SequentialReader reader, byte[] sentinel) throws java.io.IOException
Reads all bytes until the given sentinel is observed. The sentinel will be included in the returned bytes.- Throws:
java.io.IOException
-
decodeHexCommentBlock
private static byte[] decodeHexCommentBlock(SequentialReader reader) throws java.io.IOException
EPS files can contain hexadecimal-encoded ASCII blocks, each prefixed with"% " . This method reads such a block and returns a byte[] of the decoded contents. Reading stops at the first invalid line, which is discarded (it's a terminator anyway). For example:
When calling this method, the reader must be positioned at the start of the first line containing hex data, not at the introductory line.%BeginPhotoshop: 9564 % 3842494D040400000000005D1C015A00031B25471C0200000200041C02780004 % 6E756C6C1C027A00046E756C6C1C025000046E756C6C1C023700083230313630 % 3331311C023C000B3131343335362B303030301C023E00083230313630333131 % 48000000010000003842494D03FD0000000000080101000000000000 %EndPhotoshop- Returns:
- The decoded bytes, or
nullif decoding failed. - Throws:
java.io.IOException
-
tryHexToInt
private static int tryHexToInt(byte b)
Treats a byte as an ASCII character, and returns it's numerical value in hexadecimal. If conversion is not possible, returns -1.
-
-