|
|
|
|
@ -2,7 +2,9 @@ package cokr.xit.base.file;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.net.URLConnection;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
import cokr.xit.foundation.AbstractComponent;
|
|
|
|
|
@ -18,7 +20,7 @@ public class FileInspector extends AbstractComponent {
|
|
|
|
|
.set("parent", file.getParent())
|
|
|
|
|
.set("length", file.length())
|
|
|
|
|
.set("type", type)
|
|
|
|
|
.set("mimeType", URLConnection.guessContentTypeFromName(name));
|
|
|
|
|
.set("mimeType", "file".equals(type) ? URLConnection.guessContentTypeFromName(name) : null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private File getDir(String path) {
|
|
|
|
|
@ -34,11 +36,11 @@ public class FileInspector extends AbstractComponent {
|
|
|
|
|
public List<DataObject> getDirList(String path) {
|
|
|
|
|
File dir = getDir(path);
|
|
|
|
|
File[] subs = dir.listFiles(File::isDirectory);
|
|
|
|
|
return Stream.of(subs).map(this::getInfo).toList();
|
|
|
|
|
return Stream.of(subs).map(this::getInfo).collect(Collectors.toCollection(ArrayList::new));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<DataObject> getFileList(String dir) {
|
|
|
|
|
File[] files = getDir(dir).listFiles(File::isFile);
|
|
|
|
|
return Stream.of(files).map(this::getInfo).toList();
|
|
|
|
|
return Stream.of(files).map(this::getInfo).collect(Collectors.toCollection(ArrayList::new));
|
|
|
|
|
}
|
|
|
|
|
}
|