2009-02-12 17:04:17 -05:00
|
|
|
|
|
|
|
package net.sourceforge.tuned;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
2009-04-26 09:34:22 -04:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2009-02-12 17:04:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
public class FastFile extends File {
|
|
|
|
|
|
|
|
private Long length;
|
|
|
|
private Boolean isDirectory;
|
|
|
|
private Boolean isFile;
|
|
|
|
|
|
|
|
|
|
|
|
public FastFile(String path) {
|
|
|
|
super(path);
|
|
|
|
}
|
|
|
|
|
2012-02-10 11:43:09 -05:00
|
|
|
|
2009-02-12 17:04:17 -05:00
|
|
|
public FastFile(File parent, String child) {
|
|
|
|
super(parent, child);
|
|
|
|
}
|
|
|
|
|
2012-02-10 11:43:09 -05:00
|
|
|
|
2009-02-12 17:04:17 -05:00
|
|
|
@Override
|
|
|
|
public long length() {
|
|
|
|
return length != null ? length : (length = super.length());
|
|
|
|
}
|
|
|
|
|
2009-05-03 13:38:22 -04:00
|
|
|
|
2009-02-12 17:04:17 -05:00
|
|
|
@Override
|
|
|
|
public boolean isDirectory() {
|
|
|
|
return isDirectory != null ? isDirectory : (isDirectory = super.isDirectory());
|
|
|
|
}
|
|
|
|
|
2012-02-10 11:43:09 -05:00
|
|
|
|
2009-02-12 17:04:17 -05:00
|
|
|
@Override
|
|
|
|
public boolean isFile() {
|
|
|
|
return isFile != null ? isFile : (isFile = super.isFile());
|
|
|
|
}
|
|
|
|
|
2012-02-10 11:43:09 -05:00
|
|
|
|
2009-02-12 17:04:17 -05:00
|
|
|
@Override
|
|
|
|
public File[] listFiles() {
|
|
|
|
String[] names = list();
|
2012-12-06 12:47:39 -05:00
|
|
|
if (names == null)
|
|
|
|
return null;
|
2009-02-12 17:04:17 -05:00
|
|
|
|
2012-12-06 12:47:39 -05:00
|
|
|
File[] files = new File[names.length];
|
2009-02-12 17:04:17 -05:00
|
|
|
for (int i = 0; i < names.length; i++) {
|
|
|
|
files[i] = new FastFile(this, names[i]);
|
|
|
|
}
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
2012-02-10 11:43:09 -05:00
|
|
|
|
2009-04-26 09:34:22 -04:00
|
|
|
public static List<FastFile> foreach(File... files) {
|
|
|
|
return foreach(Arrays.asList(files));
|
|
|
|
}
|
|
|
|
|
2012-02-10 11:43:09 -05:00
|
|
|
|
2009-04-26 09:34:22 -04:00
|
|
|
public static List<FastFile> foreach(final List<File> files) {
|
|
|
|
List<FastFile> result = new ArrayList<FastFile>(files.size());
|
|
|
|
|
|
|
|
for (File file : files) {
|
|
|
|
result.add(new FastFile(file.getPath()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2009-02-12 17:04:17 -05:00
|
|
|
}
|