return lastModifiedTime;
}
- private boolean isDirectory;
+ private final boolean isDirectory;
- private boolean isSymbolicLink;
+ private final boolean isSymbolicLink;
- private boolean isRegularFile;
+ private final boolean isRegularFile;
- private long creationTime;
+ private final long creationTime;
- private long lastModifiedTime;
+ private final long lastModifiedTime;
- private boolean isExecutable;
+ private final boolean isExecutable;
- private File file;
+ private final File file;
- private boolean exists;
+ private final boolean exists;
/**
* file length
*/
protected long length = -1;
- FS fs;
+ final FS fs;
Attributes(FS fs, File file, boolean exists, boolean isDirectory,
boolean isExecutable, boolean isSymbolicLink,
}
/**
- * Constructor when there are issues with reading
+ * Constructor when there are issues with reading. All attributes except
+ * given will be set to the default values.
*
* @param fs
* @param path
*/
public Attributes(File path, FS fs) {
- this.file = path;
- this.fs = fs;
+ this(fs, path, false, false, false, false, false, 0L, 0L, 0L);
}
/**
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
-import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.BasicFileAttributes;
*/
public class FileUtil {
- static class Java7BasicAttributes extends Attributes {
-
- Java7BasicAttributes(FS fs, File fPath, boolean exists,
- boolean isDirectory, boolean isExecutable,
- boolean isSymbolicLink, boolean isRegularFile,
- long creationTime, long lastModifiedTime, long length) {
- super(fs, fPath, exists, isDirectory, isExecutable, isSymbolicLink,
- isRegularFile, creationTime, lastModifiedTime, length);
- }
- }
-
/**
* @param path
* @return target path of the symlink
.getFileAttributeView(nioPath,
BasicFileAttributeView.class,
LinkOption.NOFOLLOW_LINKS).readAttributes();
- Attributes attributes = new FileUtil.Java7BasicAttributes(fs, path,
+ Attributes attributes = new Attributes(fs, path,
true,
readAttributes.isDirectory(),
fs.supportsExecute() ? path.canExecute() : false,
.encode(FileUtils.readSymLink(path)).length
: readAttributes.size());
return attributes;
- } catch (NoSuchFileException e) {
- return new FileUtil.Java7BasicAttributes(fs, path, false, false,
- false, false, false, 0L, 0L, 0L);
} catch (IOException e) {
return new Attributes(path, fs);
}
.getFileAttributeView(nioPath,
PosixFileAttributeView.class,
LinkOption.NOFOLLOW_LINKS).readAttributes();
- Attributes attributes = new FileUtil.Java7BasicAttributes(
+ Attributes attributes = new Attributes(
fs,
path,
true, //
readAttributes.lastModifiedTime().toMillis(),
readAttributes.size());
return attributes;
- } catch (NoSuchFileException e) {
- return new FileUtil.Java7BasicAttributes(fs, path, false, false,
- false, false, false, 0L, 0L, 0L);
} catch (IOException e) {
return new Attributes(path, fs);
}