diff --git a/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java b/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java index dacfb011adf..10a379700e6 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,8 @@ import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; /** - * {@link Resource} implementation for class path resources. - * Uses either a given ClassLoader or a given Class for loading resources. + * {@link Resource} implementation for class path resources. Uses either a + * given {@link ClassLoader} or a given {@link Class} for loading resources. * *

Supports resolution as {@code java.io.File} if the class path * resource resides in the file system, but not for resources in a JAR. @@ -229,6 +229,7 @@ public class ClassPathResource extends AbstractFileResolvingResource { return builder.toString(); } + /** * This implementation compares the underlying class path locations. */ diff --git a/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java b/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java index 8f332385c67..294a3e3726b 100644 --- a/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -115,6 +115,26 @@ public class FileSystemResource extends AbstractResource implements WritableReso return new FileInputStream(this.file); } + /** + * This implementation checks whether the underlying file is marked as writable + * (and corresponds to an actual file with content, not to a directory). + * @see java.io.File#canWrite() + * @see java.io.File#isDirectory() + */ + @Override + public boolean isWritable() { + return (this.file.canWrite() && !this.file.isDirectory()); + } + + /** + * This implementation opens a FileOutputStream for the underlying file. + * @see java.io.FileOutputStream + */ + @Override + public OutputStream getOutputStream() throws IOException { + return new FileOutputStream(this.file); + } + /** * This implementation returns a URL for the underlying file. * @see java.io.File#toURI() @@ -180,29 +200,6 @@ public class FileSystemResource extends AbstractResource implements WritableReso } - // implementation of WritableResource - - /** - * This implementation checks whether the underlying file is marked as writable - * (and corresponds to an actual file with content, not to a directory). - * @see java.io.File#canWrite() - * @see java.io.File#isDirectory() - */ - @Override - public boolean isWritable() { - return (this.file.canWrite() && !this.file.isDirectory()); - } - - /** - * This implementation opens a FileOutputStream for the underlying file. - * @see java.io.FileOutputStream - */ - @Override - public OutputStream getOutputStream() throws IOException { - return new FileOutputStream(this.file); - } - - /** * This implementation compares the underlying File references. */ diff --git a/spring-core/src/main/java/org/springframework/core/io/PathResource.java b/spring-core/src/main/java/org/springframework/core/io/PathResource.java index 641d87635f8..f84ccfa9083 100644 --- a/spring-core/src/main/java/org/springframework/core/io/PathResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/PathResource.java @@ -33,10 +33,11 @@ import org.springframework.util.Assert; /** * {@link Resource} implementation for {@code java.nio.file.Path} handles. - *

Supports resolution as File, and also as URL. - *

Implements the extended {@link WritableResource} interface. + * Supports resolution as File, and also as URL. + * Implements the extended {@link WritableResource} interface. * * @author Philippe Marschall + * @author Juergen Hoeller * @since 4.0 * @see java.nio.file.Path */ @@ -130,6 +131,29 @@ public class PathResource extends AbstractResource implements WritableResource { return Files.newInputStream(this.path); } + /** + * This implementation checks whether the underlying file is marked as writable + * (and corresponds to an actual file with content, not to a directory). + * @see java.nio.file.Files#isWritable(Path) + * @see java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...) + */ + @Override + public boolean isWritable() { + return (Files.isWritable(this.path) && !Files.isDirectory(this.path)); + } + + /** + * This implementation opens a OutputStream for the underlying file. + * @see java.nio.file.spi.FileSystemProvider#newOutputStream(Path, OpenOption...) + */ + @Override + public OutputStream getOutputStream() throws IOException { + if (Files.isDirectory(this.path)) { + throw new FileNotFoundException(getPath() + " (is a directory)"); + } + return Files.newOutputStream(this.path); + } + /** * This implementation returns a URL for the underlying file. * @see java.nio.file.Path#toUri() @@ -178,8 +202,8 @@ public class PathResource extends AbstractResource implements WritableResource { */ @Override public long lastModified() throws IOException { - // we can not use the super class method since it uses conversion to a File and - // only Paths on the default file system can be converted to a File + // We can not use the superclass method since it uses conversion to a File and + // only a Path on the default file system can be converted to a File... return Files.getLastModifiedTime(path).toMillis(); } @@ -207,31 +231,6 @@ public class PathResource extends AbstractResource implements WritableResource { return "path [" + this.path.toAbsolutePath() + "]"; } - // implementation of WritableResource - - /** - * This implementation checks whether the underlying file is marked as writable - * (and corresponds to an actual file with content, not to a directory). - * @see java.nio.file.Files#isWritable(Path) - * @see java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...) - */ - @Override - public boolean isWritable() { - return Files.isWritable(this.path) && !Files.isDirectory(this.path); - } - - /** - * This implementation opens a OutputStream for the underlying file. - * @see java.nio.file.spi.FileSystemProvider#newOutputStream(Path, OpenOption...) - */ - @Override - public OutputStream getOutputStream() throws IOException { - if (Files.isDirectory(this.path)) { - throw new FileNotFoundException(getPath() + " (is a directory)"); - } - return Files.newOutputStream(this.path); - } - /** * This implementation compares the underlying Path references.