use of dontweave.gson.JsonPrimitive in project h2o-2 by h2oai.
the class TypeaheadFileRequest method serveFile.
protected JsonArray serveFile(String filter, int limit) {
File base = null;
String filterPrefix = "";
if (!filter.isEmpty()) {
File file = new File(filter);
if (file.isDirectory()) {
base = file;
} else {
base = file.getParentFile();
filterPrefix = file.getName().toLowerCase();
}
}
if (base == null)
base = new File(".");
JsonArray array = new JsonArray();
File[] files = base.listFiles();
if (files == null)
return array;
for (File file : files) {
if (file.isHidden())
continue;
if (file.getName().toLowerCase().startsWith(filterPrefix))
array.add(new JsonPrimitive(file.getPath()));
if (array.size() == limit)
break;
}
return array;
}
use of dontweave.gson.JsonPrimitive in project h2o-2 by h2oai.
the class TypeaheadHexKeyRequest method serve.
protected JsonArray serve(String filter, int limit, long timetolerance) {
JsonArray array = new JsonArray();
int len = 0;
// Gather some keys that pass all filters
for (H2O.KeyInfo kinfo : H2O.KeySnapshot.globalSnapshot(2000)._keyInfos) {
if (// Have a filter?
filter != null && kinfo._key.toString().indexOf(filter) == -1)
// Ignore this filtered-out key
continue;
// Wrong type?
if (!matchesType(kinfo))
continue;
// Generic override
if (!shouldIncludeKey(kinfo))
continue;
array.add(new JsonPrimitive(kinfo._key.toString()));
if (array.size() == limit)
break;
}
return array;
}
use of dontweave.gson.JsonPrimitive in project h2o-2 by h2oai.
the class TypeaheadS3BucketRequest method serve.
@Override
protected JsonArray serve(String filter, int limit) {
JsonArray array = new JsonArray();
try {
AmazonS3 s3 = PersistS3.getClient();
filter = Strings.nullToEmpty(filter);
for (Bucket b : s3.listBuckets()) {
if (b.getName().startsWith(filter))
array.add(new JsonPrimitive(b.getName()));
if (array.size() == limit)
break;
}
} catch (IllegalArgumentException xe) {
}
return array;
}
Aggregations