source: other-projects/rsyntax-textarea/src/java/org/fife/ui/rsyntaxtextarea/FileLocation.java@ 25584

Last change on this file since 25584 was 25584, checked in by davidb, 12 years ago

Initial cut an a text edit area for GLI that supports color syntax highlighting

File size: 3.3 KB
Line 
1/*
2 * 11/13/2008
3 *
4 * FileLocation.java - Holds the location of a local or remote file.
5 *
6 * This library is distributed under a modified BSD license. See the included
7 * RSyntaxTextArea.License.txt file for details.
8 */
9package org.fife.ui.rsyntaxtextarea;
10
11import java.io.File;
12import java.io.InputStream;
13import java.io.IOException;
14import java.io.OutputStream;
15import java.net.URL;
16
17
18/**
19 * Holds the location of a local or remote file. This provides a common way
20 * to read, write, and check properties of both local and remote files.
21 *
22 * @author Robert Futrell
23 * @version 1.0
24 */
25public abstract class FileLocation {
26
27
28 /**
29 * Creates a {@link FileLocation} instance for the specified local file.
30 *
31 * @param fileFullPath The full path to a local file.
32 * @return The file's location.
33 */
34 public static FileLocation create(String fileFullPath) {
35 return new FileFileLocation(new File(fileFullPath));
36 }
37
38
39 /**
40 * Creates a {@link FileLocation} instance for the specified local file.
41 *
42 * @param file A local file.
43 * @return The file's location.
44 */
45 public static FileLocation create(File file) {
46 return new FileFileLocation(file);
47 }
48
49
50 /**
51 * Creates a {@link FileLocation} instance for the specified file.
52 *
53 * @param url The URL of a file.
54 * @return The file's location.
55 */
56 public static FileLocation create(URL url) {
57 if ("file".equalsIgnoreCase(url.getProtocol())) {
58 return new FileFileLocation(new File(url.getPath()));
59 }
60 return new URLFileLocation(url);
61 }
62
63
64 /**
65 * Returns the last time this file was modified, or
66 * {@link TextEditorPane#LAST_MODIFIED_UNKNOWN} if this value cannot be
67 * computed (such as for a remote file).
68 *
69 * @return The last time this file was modified.
70 */
71 protected abstract long getActualLastModified();
72
73
74 /**
75 * Returns the full path to the file. This will be stripped of
76 * sensitive information such as passwords for remote files.
77 *
78 * @return The full path to the file.
79 * @see #getFileName()
80 */
81 public abstract String getFileFullPath();
82
83
84 /**
85 * Returns the name of the file.
86 *
87 * @return The name of the file.
88 * @see #getFileFullPath()
89 */
90 public abstract String getFileName();
91
92
93 /**
94 * Opens an input stream for reading from this file.
95 *
96 * @return The input stream.
97 * @throws IOException If the file does not exist, or some other IO error
98 * occurs.
99 */
100 protected abstract InputStream getInputStream() throws IOException;
101
102
103 /**
104 * Opens an output stream for writing this file.
105 *
106 * @return An output stream.
107 * @throws IOException If an IO error occurs.
108 */
109 protected abstract OutputStream getOutputStream() throws IOException;
110
111
112 /**
113 * Returns whether this file location is a local file.
114 *
115 * @return Whether this is a local file.
116 * @see #isLocalAndExists()
117 */
118 public abstract boolean isLocal();
119
120
121 /**
122 * Returns whether this file location is a local file that already
123 * exists.
124 *
125 * @return Whether this file is local and actually exists.
126 * @see #isLocal()
127 */
128 public abstract boolean isLocalAndExists();
129
130
131 /**
132 * Returns whether this file location is a remote location.
133 *
134 * @return Whether this is a remote file location.
135 */
136 public boolean isRemote() {
137 return !isLocal();
138 }
139
140
141}
Note: See TracBrowser for help on using the repository browser.