1 package de.jwi.jgallery; 2 3 24 25 import java.io.File ; 26 import java.io.FileInputStream ; 27 import java.io.FileNotFoundException ; 28 import java.io.InputStream ; 29 30 35 public class FileImageAccessor implements IImageAccessor 36 { 37 38 private String name; 39 40 private Folder folder; 41 42 private File image; 43 44 InputStream imageInputStream; 45 InputStream thumbInputStream; 46 File directory; 47 48 FileImageAccessor(String name, Folder folder) 49 { 50 this.name = name; 51 this.folder = folder; 52 } 53 54 private File getFile() 55 { 56 if (image == null) 57 { 58 directory = folder.getDirectory(); 59 60 image = new File (directory, name); 61 } 62 return image; 63 } 64 65 public InputStream getImageInputStream() 66 throws FileNotFoundException 67 { 68 imageInputStream = new FileInputStream (getFile()); 69 return imageInputStream; 70 } 71 72 public long getLastModified() 73 { 74 return getFile().lastModified(); 75 } 76 77 public long getLength() 78 { 79 return getFile().length(); 80 } 81 82 public InputStream getThumbInputStream() 83 throws FileNotFoundException 84 { 85 if (null==thumbInputStream) 86 { 87 getFile(); 89 File thumb = new File (directory, 90 folder.getThumbsdir() + "/" + name); 91 92 thumbInputStream = new FileInputStream (thumb); 93 } 94 return thumbInputStream; 95 } 96 } 97 | Popular Tags |