| Line | |
|---|
| 1 | package com.drew.metadata.file;
|
|---|
| 2 |
|
|---|
| 3 | import com.drew.lang.annotations.NotNull;
|
|---|
| 4 | import com.drew.metadata.Metadata;
|
|---|
| 5 |
|
|---|
| 6 | import java.io.File;
|
|---|
| 7 | import java.io.IOException;
|
|---|
| 8 | import java.util.Date;
|
|---|
| 9 |
|
|---|
| 10 | public class FileMetadataReader
|
|---|
| 11 | {
|
|---|
| 12 | public void read(@NotNull File file, @NotNull Metadata metadata) throws IOException
|
|---|
| 13 | {
|
|---|
| 14 | if (!file.isFile())
|
|---|
| 15 | throw new IOException("File object must reference a file");
|
|---|
| 16 | if (!file.exists())
|
|---|
| 17 | throw new IOException("File does not exist");
|
|---|
| 18 | if (!file.canRead())
|
|---|
| 19 | throw new IOException("File is not readable");
|
|---|
| 20 |
|
|---|
| 21 | FileMetadataDirectory directory = new FileMetadataDirectory();
|
|---|
| 22 |
|
|---|
| 23 | directory.setString(FileMetadataDirectory.TAG_FILE_NAME, file.getName());
|
|---|
| 24 | directory.setLong(FileMetadataDirectory.TAG_FILE_SIZE, file.length());
|
|---|
| 25 | directory.setDate(FileMetadataDirectory.TAG_FILE_MODIFIED_DATE, new Date(file.lastModified()));
|
|---|
| 26 |
|
|---|
| 27 | metadata.addDirectory(directory);
|
|---|
| 28 | }
|
|---|
| 29 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.