use of io.minio.messages.Bucket in project Universal-G-Code-Sender by winder.
the class S3FileSystemView method getFiles.
@Override
public File[] getFiles(final File dir, boolean useFileHiding) {
// If there is no bucket (i.e. just "s3:/"), add the buckets.
if (!hasBucket(dir.toString())) {
try {
final List<File> files = new ArrayList<>(1);
for (Bucket bucket : buckets) {
files.add(new S3VirtualFile("s3:/" + bucket.name() + "/", 0));
}
return files.toArray(new File[files.size()]);
} catch (Exception ex) {
ex.printStackTrace();
logger.log(Level.WARNING, "An error occurred listing buckets on S3.", ex);
}
return new S3VirtualFile[0];
}
ArrayList<S3VirtualFile> ret = new ArrayList<>();
Matcher m = parseURI(dir.toString());
try {
if (m.matches()) {
String bucket = m.group("bucket");
// Path should start with a slash unless it's empty
String path = m.group("path");
if (!"".equals(path)) {
path += "/";
}
Iterable<Result<Item>> objects = minioClient.listObjects(bucket, path, false);
String prefix = "s3:/" + bucket + "/";
String dirMatch = dir.toString() + "/";
for (Result<Item> res : objects) {
Item i = res.get();
String name = prefix + i.objectName();
// listObjects matches the current directory, filter it out.
if (name.equals(dirMatch)) {
continue;
}
S3VirtualFile f = new S3VirtualFile(name, i.objectSize());
if (!f.isDirectory()) {
try {
f.setLastModified(i.lastModified().getTime());
} catch (Exception e) {
// The mock server doesn't play well with the lastModified field.
}
}
ret.add(f);
}
}
} catch (Exception ex) {
logger.log(Level.WARNING, "An error occurred listing files on S3.", ex);
}
return ret.toArray(new S3VirtualFile[0]);
}
Aggregations