1 package de.jwi.jgallery; 2 3 24 25 import java.io.File ; 26 import java.io.FileNotFoundException ; 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 import java.net.URL ; 30 import java.net.URLConnection ; 31 32 37 public class WebImageAccessor implements IImageAccessor 38 { 39 40 private String name; 41 42 private WebFolder folder; 43 44 InputStream imageInputStream; 45 InputStream thumbInputStream; 46 File directory; 47 48 private long lastModified; 49 private long length; 50 51 private String baseURL; 52 private String folderPath; 53 54 WebImageAccessor(String name, WebFolder folder) 55 { 56 this.name = name; 57 this.folder = folder; 58 baseURL = folder.getBaseURL(); 59 folderPath = folder.getFolderPath(); 60 } 61 62 63 public InputStream getImageInputStream() 64 throws FileNotFoundException 65 { 66 67 URL url; 68 URLConnection connection; 69 70 try 71 { 72 url = new URL (folderPath + "/" + name); 73 connection = url.openConnection(); 74 connection.connect(); 75 } 76 catch (Exception e) 77 { 78 throw new FileNotFoundException (e.getMessage()); 79 } 80 81 try 82 { 83 imageInputStream = connection.getInputStream(); 84 } 85 catch (IOException e) 86 { 87 throw new FileNotFoundException (e.getMessage()); 88 } 89 90 lastModified = connection.getLastModified(); 91 length = connection.getContentLength(); 92 93 return imageInputStream; 94 } 95 96 public long getLastModified() 97 { 98 return lastModified; 99 } 100 101 public long getLength() 102 { 103 return length; 104 } 105 106 107 public InputStream getThumbInputStream() 108 throws FileNotFoundException 109 { 110 111 URL url; 112 URLConnection connection; 113 114 try 115 { 116 url = new URL (folderPath + folder.getThumbsdir() + "/" + name); 117 connection = url.openConnection(); 118 connection.connect(); 119 } 120 catch (Exception e) 121 { 122 throw new FileNotFoundException (e.getMessage()); 123 } 124 125 try 126 { 127 imageInputStream = connection.getInputStream(); 128 } 129 catch (IOException e) 130 { 131 throw new FileNotFoundException (e.getMessage()); 132 } 133 134 lastModified = connection.getLastModified(); 135 length = connection.getContentLength(); 136 137 return imageInputStream; 138 } 139 140 141 } 142 | Popular Tags |