Package com.drew.metadata.eps
Class EpsReader
java.lang.Object
com.drew.metadata.eps.EpsReader
Reads 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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddToDirectory(EpsDirectory directory, String name, String value) Default case that adds comment with keyword to directoryprivate static byte[]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(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, 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.
-
Field Details
-
_previousTag
private int _previousTag
-
-
Constructor Details
-
EpsReader
public EpsReader()
-
-
Method Details
-
extract
Filter 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:
IOException
-
extract
private void extract(EpsDirectory directory, Metadata metadata, SequentialReader reader) throws 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:
IOException
-
addToDirectory
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:
IOException
-
extractImageData
Parses%ImageDatacomment which holds several values including width in px, height in px and color type.- Throws:
IOException
-
extractPhotoshopData
private static void extractPhotoshopData(Metadata metadata, SequentialReader reader) throws IOException Decodes a commented hex section, and usesPhotoshopReaderto decode the resulting data.- Throws:
IOException
-
extractIccData
Decodes a commented hex section, and usesIccReaderto decode the resulting data.- Throws:
IOException
-
extractXmpData
Extracts an XMP xpacket, and usesXmpReaderto decode the resulting data.- Throws:
IOException
-
readUntil
Reads all bytes until the given sentinel is observed. The sentinel will be included in the returned bytes.- Throws:
IOException
-
decodeHexCommentBlock
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:
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.
-