Search in sources :

Example 6 with JsonPrimitive

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;
}
Also used : JsonArray(dontweave.gson.JsonArray) JsonPrimitive(dontweave.gson.JsonPrimitive) File(java.io.File)

Example 7 with JsonPrimitive

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;
}
Also used : JsonArray(dontweave.gson.JsonArray) JsonPrimitive(dontweave.gson.JsonPrimitive)

Example 8 with JsonPrimitive

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;
}
Also used : JsonArray(dontweave.gson.JsonArray) AmazonS3(com.amazonaws.services.s3.AmazonS3) Bucket(com.amazonaws.services.s3.model.Bucket) JsonPrimitive(dontweave.gson.JsonPrimitive)

Aggregations

JsonArray (dontweave.gson.JsonArray)8 JsonPrimitive (dontweave.gson.JsonPrimitive)8 AmazonS3 (com.amazonaws.services.s3.AmazonS3)2 Bucket (com.amazonaws.services.s3.model.Bucket)2 Configuration (org.apache.hadoop.conf.Configuration)2 JsonElement (dontweave.gson.JsonElement)1 JsonObject (dontweave.gson.JsonObject)1 File (java.io.File)1