1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jasperreports.jsf.resource;
20
21 import java.io.File;
22 import java.io.FileInputStream;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.net.URL;
26
27
28
29
30
31
32 public final class FileResource implements Resource {
33
34 private final File file;
35
36 protected FileResource(File file) {
37 if (file == null) {
38 throw new IllegalArgumentException("'file' can't be null");
39 }
40 this.file = file;
41 }
42
43 public String getName() {
44 return file.getAbsolutePath();
45 }
46
47 public String getSimpleName() {
48 return file.getName();
49 }
50
51 public InputStream getInputStream() throws IOException {
52 if (file.isDirectory()) {
53 throw new ResourceException("Can't get a stream from a directory.");
54 }
55 return new FileInputStream(file);
56 }
57
58 public URL getLocation() throws IOException {
59 return new URL("file://" + file.getAbsolutePath());
60 }
61
62 public String getPath() {
63 if (file.isFile()) {
64 return file.getParentFile().getAbsolutePath();
65 } else {
66 return file.getAbsolutePath();
67 }
68 }
69
70 public String toString() {
71 return file.getAbsolutePath();
72 }
73
74 }