| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
package com.drew.metadata.file; |
| 22 |
|
| 23 |
import com.drew.lang.annotations.NotNull; |
| 24 |
import com.drew.metadata.Metadata; |
| 25 |
|
| 26 |
import java.io.*; |
| 27 |
import java.util.Date; |
| 28 |
|
| 29 |
public class FileSystemMetadataReader |
| 30 |
{ |
| 31 |
public void read(@NotNull File file, @NotNull Metadata metadata) throws IOException |
| 32 |
{ |
| 33 |
if (!file.isFile()) |
| 34 |
throw new IOException("File object must reference a file"); |
| 35 |
if (!file.exists()) |
| 36 |
throw new IOException("File does not exist"); |
| 37 |
if (!file.canRead()) |
| 38 |
throw new IOException("File is not readable"); |
| 39 |
|
| 40 |
FileSystemDirectory directory = metadata.getFirstDirectoryOfType(FileSystemDirectory.class); |
| 41 |
|
| 42 |
if (directory == null) { |
| 43 |
directory = new FileSystemDirectory(); |
| 44 |
metadata.addDirectory(directory); |
| 45 |
} |
| 46 |
|
| 47 |
directory.setString(FileSystemDirectory.TAG_FILE_NAME, file.getName()); |
| 48 |
directory.setLong(FileSystemDirectory.TAG_FILE_SIZE, file.length()); |
| 49 |
directory.setDate(FileSystemDirectory.TAG_FILE_MODIFIED_DATE, new Date(file.lastModified())); |
| 50 |
} |
| 51 |
} |