Skip to content

Commit 6993a7d

Browse files
committed
Polishing
1 parent 9cf2895 commit 6993a7d

File tree

3 files changed

+53
-56
lines changed

3 files changed

+53
-56
lines changed

spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,8 +27,8 @@
2727
import org.springframework.util.StringUtils;
2828

2929
/**
30-
* {@link Resource} implementation for class path resources.
31-
* Uses either a given ClassLoader or a given Class for loading resources.
30+
* {@link Resource} implementation for class path resources. Uses either a
31+
* given {@link ClassLoader} or a given {@link Class} for loading resources.
3232
*
3333
* <p>Supports resolution as {@code java.io.File} if the class path
3434
* resource resides in the file system, but not for resources in a JAR.
@@ -229,6 +229,7 @@ public String getDescription() {
229229
return builder.toString();
230230
}
231231

232+
232233
/**
233234
* This implementation compares the underlying class path locations.
234235
*/

spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -115,6 +115,26 @@ public InputStream getInputStream() throws IOException {
115115
return new FileInputStream(this.file);
116116
}
117117

118+
/**
119+
* This implementation checks whether the underlying file is marked as writable
120+
* (and corresponds to an actual file with content, not to a directory).
121+
* @see java.io.File#canWrite()
122+
* @see java.io.File#isDirectory()
123+
*/
124+
@Override
125+
public boolean isWritable() {
126+
return (this.file.canWrite() && !this.file.isDirectory());
127+
}
128+
129+
/**
130+
* This implementation opens a FileOutputStream for the underlying file.
131+
* @see java.io.FileOutputStream
132+
*/
133+
@Override
134+
public OutputStream getOutputStream() throws IOException {
135+
return new FileOutputStream(this.file);
136+
}
137+
118138
/**
119139
* This implementation returns a URL for the underlying file.
120140
* @see java.io.File#toURI()
@@ -180,29 +200,6 @@ public String getDescription() {
180200
}
181201

182202

183-
// implementation of WritableResource
184-
185-
/**
186-
* This implementation checks whether the underlying file is marked as writable
187-
* (and corresponds to an actual file with content, not to a directory).
188-
* @see java.io.File#canWrite()
189-
* @see java.io.File#isDirectory()
190-
*/
191-
@Override
192-
public boolean isWritable() {
193-
return (this.file.canWrite() && !this.file.isDirectory());
194-
}
195-
196-
/**
197-
* This implementation opens a FileOutputStream for the underlying file.
198-
* @see java.io.FileOutputStream
199-
*/
200-
@Override
201-
public OutputStream getOutputStream() throws IOException {
202-
return new FileOutputStream(this.file);
203-
}
204-
205-
206203
/**
207204
* This implementation compares the underlying File references.
208205
*/

spring-core/src/main/java/org/springframework/core/io/PathResource.java

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@
3333

3434
/**
3535
* {@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.
3838
*
3939
* @author Philippe Marschall
40+
* @author Juergen Hoeller
4041
* @since 4.0
4142
* @see java.nio.file.Path
4243
*/
@@ -130,6 +131,29 @@ public InputStream getInputStream() throws IOException {
130131
return Files.newInputStream(this.path);
131132
}
132133

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+
133157
/**
134158
* This implementation returns a URL for the underlying file.
135159
* @see java.nio.file.Path#toUri()
@@ -178,8 +202,8 @@ public long contentLength() throws IOException {
178202
*/
179203
@Override
180204
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...
183207
return Files.getLastModifiedTime(path).toMillis();
184208
}
185209

@@ -207,31 +231,6 @@ public String getDescription() {
207231
return "path [" + this.path.toAbsolutePath() + "]";
208232
}
209233

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-
235234

236235
/**
237236
* This implementation compares the underlying Path references.

0 commit comments

Comments
 (0)