2 * Copyright 2005 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.photos.model.filesystem;
19 import java.io.FileInputStream;
20 import java.io.FileNotFoundException;
21 import java.io.IOException;
22 import java.io.InputStream;
24 import org.wamblee.photos.model.Photo;
25 import org.wamblee.photos.model.PhotoEntry;
28 * Represents a photo stored on the file system.
30 public class FileSystemPhoto implements Photo {
32 private File _thumbnail;
36 public FileSystemPhoto(File aThumbnail, File aPhoto, String aPath) {
37 _thumbnail = aThumbnail;
45 * @see org.wamblee.photos.database.PhotoEntry#getPath()
47 public String getPath() {
54 * @see org.wamblee.photos.database.Photo#getThumbNail()
56 public InputStream getThumbNail() throws IOException {
57 return openFile(_thumbnail);
63 * @see org.wamblee.photos.database.Photo#getFile()
65 public InputStream getPhoto() throws IOException {
66 return openFile(_photo);
69 private InputStream openFile(File aFile) throws FileNotFoundException {
70 return new FileInputStream(aFile);
76 * @see org.wamblee.photos.database.PhotoEntry#getId()
78 public String getId() {
82 public static String getId(String aPath) {
83 int index = aPath.lastIndexOf("/");
87 return aPath.substring(index + 1);
90 public String toString() {
94 String print(String aIndent) {
95 return aIndent + "IMG: " + _photo.getName();
99 * @see java.lang.Object#equals(java.lang.Object)
102 public boolean equals(Object obj) {
103 if ( !(obj instanceof Photo) ) {
106 return getPath().equals( ((Photo)obj).getPath());
110 * @see java.lang.Object#hashCode()
113 public int hashCode() {
114 return getPath().hashCode();
118 * @see java.lang.Comparable#compareTo(java.lang.Object)
120 public int compareTo(PhotoEntry aEntry) {
121 return getId().compareTo(((PhotoEntry)aEntry).getId());