@ -33,10 +33,11 @@ import org.springframework.util.Assert;
@@ -33,10 +33,11 @@ import org.springframework.util.Assert;
/ * *
* { @link Resource } implementation for { @code java . nio . file . Path } handles .
* < p > Supports resolution as File , and also as URL .
* < p > 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 {
@@ -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 {
@@ -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 super class 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 {
@@ -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 .