|
33 | 33 |
|
34 | 34 | /**
|
35 | 35 | * {@link Resource} implementation for {@code java.nio.file.Path} handles.
|
36 |
| - * <p>Supports resolution as File, and also as URL. |
37 |
| - * <p>Implements the extended {@link WritableResource} interface. |
| 36 | + * Supports resolution as File, and also as URL. |
| 37 | + * Implements the extended {@link WritableResource} interface. |
38 | 38 | *
|
39 | 39 | * @author Philippe Marschall
|
| 40 | + * @author Juergen Hoeller |
40 | 41 | * @since 4.0
|
41 | 42 | * @see java.nio.file.Path
|
42 | 43 | */
|
@@ -130,6 +131,29 @@ public InputStream getInputStream() throws IOException {
|
130 | 131 | return Files.newInputStream(this.path);
|
131 | 132 | }
|
132 | 133 |
|
| 134 | + /** |
| 135 | + * This implementation checks whether the underlying file is marked as writable |
| 136 | + * (and corresponds to an actual file with content, not to a directory). |
| 137 | + * @see java.nio.file.Files#isWritable(Path) |
| 138 | + * @see java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...) |
| 139 | + */ |
| 140 | + @Override |
| 141 | + public boolean isWritable() { |
| 142 | + return (Files.isWritable(this.path) && !Files.isDirectory(this.path)); |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * This implementation opens a OutputStream for the underlying file. |
| 147 | + * @see java.nio.file.spi.FileSystemProvider#newOutputStream(Path, OpenOption...) |
| 148 | + */ |
| 149 | + @Override |
| 150 | + public OutputStream getOutputStream() throws IOException { |
| 151 | + if (Files.isDirectory(this.path)) { |
| 152 | + throw new FileNotFoundException(getPath() + " (is a directory)"); |
| 153 | + } |
| 154 | + return Files.newOutputStream(this.path); |
| 155 | + } |
| 156 | + |
133 | 157 | /**
|
134 | 158 | * This implementation returns a URL for the underlying file.
|
135 | 159 | * @see java.nio.file.Path#toUri()
|
@@ -178,8 +202,8 @@ public long contentLength() throws IOException {
|
178 | 202 | */
|
179 | 203 | @Override
|
180 | 204 | public long lastModified() throws IOException {
|
181 |
| - // we can not use the super class method since it uses conversion to a File and |
182 |
| - // only Paths on the default file system can be converted to a File |
| 205 | + // We can not use the superclass method since it uses conversion to a File and |
| 206 | + // only a Path on the default file system can be converted to a File... |
183 | 207 | return Files.getLastModifiedTime(path).toMillis();
|
184 | 208 | }
|
185 | 209 |
|
@@ -207,31 +231,6 @@ public String getDescription() {
|
207 | 231 | return "path [" + this.path.toAbsolutePath() + "]";
|
208 | 232 | }
|
209 | 233 |
|
210 |
| - // implementation of WritableResource |
211 |
| - |
212 |
| - /** |
213 |
| - * This implementation checks whether the underlying file is marked as writable |
214 |
| - * (and corresponds to an actual file with content, not to a directory). |
215 |
| - * @see java.nio.file.Files#isWritable(Path) |
216 |
| - * @see java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...) |
217 |
| - */ |
218 |
| - @Override |
219 |
| - public boolean isWritable() { |
220 |
| - return Files.isWritable(this.path) && !Files.isDirectory(this.path); |
221 |
| - } |
222 |
| - |
223 |
| - /** |
224 |
| - * This implementation opens a OutputStream for the underlying file. |
225 |
| - * @see java.nio.file.spi.FileSystemProvider#newOutputStream(Path, OpenOption...) |
226 |
| - */ |
227 |
| - @Override |
228 |
| - public OutputStream getOutputStream() throws IOException { |
229 |
| - if (Files.isDirectory(this.path)) { |
230 |
| - throw new FileNotFoundException(getPath() + " (is a directory)"); |
231 |
| - } |
232 |
| - return Files.newOutputStream(this.path); |
233 |
| - } |
234 |
| - |
235 | 234 |
|
236 | 235 | /**
|
237 | 236 | * This implementation compares the underlying Path references.
|
|
0 commit comments