1 | /*
|
---|
2 | * 11/13/2008
|
---|
3 | *
|
---|
4 | * FileFileLocation.java - The location of a local file.
|
---|
5 | *
|
---|
6 | * This library is distributed under a modified BSD license. See the included
|
---|
7 | * RSyntaxTextArea.License.txt file for details.
|
---|
8 | */
|
---|
9 | package org.fife.ui.rsyntaxtextarea;
|
---|
10 |
|
---|
11 | import java.io.File;
|
---|
12 | import java.io.FileInputStream;
|
---|
13 | import java.io.FileOutputStream;
|
---|
14 | import java.io.InputStream;
|
---|
15 | import java.io.IOException;
|
---|
16 | import java.io.OutputStream;
|
---|
17 |
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * The location of a local file.
|
---|
21 | *
|
---|
22 | * @author Robert Futrell
|
---|
23 | * @version 1.0
|
---|
24 | */
|
---|
25 | class FileFileLocation extends FileLocation {
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * The file. This may or may not actually exist.
|
---|
29 | */
|
---|
30 | private File file;
|
---|
31 |
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Constructor.
|
---|
35 | *
|
---|
36 | * @param file The local file.
|
---|
37 | */
|
---|
38 | public FileFileLocation(File file) {
|
---|
39 | try {
|
---|
40 | // Useful on Windows and OS X.
|
---|
41 | this.file = file.getCanonicalFile();
|
---|
42 | } catch (IOException ioe) {
|
---|
43 | this.file = file;
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * {@inheritDoc}
|
---|
50 | */
|
---|
51 | protected long getActualLastModified() {
|
---|
52 | return file.lastModified();
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Returns the full path to the file.
|
---|
58 | *
|
---|
59 | * @return The full path to the file.
|
---|
60 | * @see #getFileName()
|
---|
61 | */
|
---|
62 | public String getFileFullPath() {
|
---|
63 | return file.getAbsolutePath();
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * {@inheritDoc}
|
---|
69 | */
|
---|
70 | public String getFileName() {
|
---|
71 | return file.getName();
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * {@inheritDoc}
|
---|
77 | */
|
---|
78 | protected InputStream getInputStream() throws IOException {
|
---|
79 | return new FileInputStream(file);
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * {@inheritDoc}
|
---|
85 | */
|
---|
86 | protected OutputStream getOutputStream() throws IOException {
|
---|
87 | return new FileOutputStream(file);
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * Always returns <code>true</code>.
|
---|
93 | *
|
---|
94 | * @return <code>true</code> always.
|
---|
95 | * @see #isLocalAndExists()
|
---|
96 | */
|
---|
97 | public boolean isLocal() {
|
---|
98 | return true;
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Since file locations of this type are guaranteed to be local, this
|
---|
104 | * method returns whether the file exists.
|
---|
105 | *
|
---|
106 | * @return Whether this local file actually exists.
|
---|
107 | * @see #isLocal()
|
---|
108 | */
|
---|
109 | public boolean isLocalAndExists() {
|
---|
110 | return file.exists();
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | } |
---|