KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > jwi > jgallery > FileImageAccessor


1 package de.jwi.jgallery;
2
3 /*
4  * jGallery - Java web application to display image galleries
5  *
6  * Copyright (C) 2004 Juergen Weber
7  *
8  * This file is part of jGallery.
9  *
10  * jGallery is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * jGallery is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with jGallery; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston
23  */

24
25 import java.io.File JavaDoc;
26 import java.io.FileInputStream JavaDoc;
27 import java.io.FileNotFoundException JavaDoc;
28 import java.io.InputStream JavaDoc;
29
30 /**
31  * @author Jürgen Weber
32  * Source file created on 07.03.2004
33  *
34  */

35 public class FileImageAccessor implements IImageAccessor
36 {
37
38     private String JavaDoc name;
39
40     private Folder folder;
41
42     private File JavaDoc image;
43     
44     InputStream JavaDoc imageInputStream;
45     InputStream JavaDoc thumbInputStream;
46     File JavaDoc directory;
47
48     FileImageAccessor(String JavaDoc name, Folder folder)
49     {
50         this.name = name;
51         this.folder = folder;
52     }
53
54     private File JavaDoc getFile()
55     {
56         if (image == null)
57         {
58             directory = folder.getDirectory();
59
60             image = new File JavaDoc(directory, name);
61         }
62         return image;
63     }
64     
65     public InputStream JavaDoc getImageInputStream()
66     throws FileNotFoundException JavaDoc
67     {
68         imageInputStream = new FileInputStream JavaDoc(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 JavaDoc getThumbInputStream()
83     throws FileNotFoundException JavaDoc
84     {
85         if (null==thumbInputStream)
86         {
87             getFile(); // to trigger directory
88

89             File JavaDoc thumb = new File JavaDoc(directory,
90                     folder.getThumbsdir() + "/" + name);
91             
92             thumbInputStream = new FileInputStream JavaDoc(thumb);
93         }
94         return thumbInputStream;
95     }
96 }
97
Popular Tags