Search in sources :

Example 6 with JsonObject

use of org.json.simple.JsonObject in project hadoop by apache.

the class HttpFSFileSystem method mkdirs.

/**
   * Make the given file and all non-existent parents into
   * directories. Has the semantics of Unix 'mkdir -p'.
   * Existence of the directory hierarchy is not an error.
   */
@Override
public boolean mkdirs(Path f, FsPermission permission) throws IOException {
    Map<String, String> params = new HashMap<String, String>();
    params.put(OP_PARAM, Operation.MKDIRS.toString());
    params.put(PERMISSION_PARAM, permissionToString(permission));
    HttpURLConnection conn = getConnection(Operation.MKDIRS.getMethod(), params, f, true);
    HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
    JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
    return (Boolean) json.get(MKDIRS_JSON);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap)

Example 7 with JsonObject

use of org.json.simple.JsonObject in project hadoop by apache.

the class HttpFSFileSystem method listStatusBatch.

@Override
public DirectoryEntries listStatusBatch(Path f, byte[] token) throws FileNotFoundException, IOException {
    Map<String, String> params = new HashMap<String, String>();
    params.put(OP_PARAM, Operation.LISTSTATUS_BATCH.toString());
    if (token != null) {
        params.put(START_AFTER_PARAM, new String(token, Charsets.UTF_8));
    }
    HttpURLConnection conn = getConnection(Operation.LISTSTATUS_BATCH.getMethod(), params, f, true);
    HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
    // Parse the FileStatus array
    JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
    JSONObject listing = (JSONObject) json.get(DIRECTORY_LISTING_JSON);
    FileStatus[] statuses = toFileStatuses((JSONObject) listing.get(PARTIAL_LISTING_JSON), f);
    // New token is the last FileStatus entry
    byte[] newToken = null;
    if (statuses.length > 0) {
        newToken = statuses[statuses.length - 1].getPath().getName().toString().getBytes(Charsets.UTF_8);
    }
    // Parse the remainingEntries boolean into hasMore
    final long remainingEntries = (Long) listing.get(REMAINING_ENTRIES_JSON);
    final boolean hasMore = remainingEntries > 0 ? true : false;
    return new DirectoryEntries(statuses, newToken, hasMore);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) FileStatus(org.apache.hadoop.fs.FileStatus) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap)

Example 8 with JsonObject

use of org.json.simple.JsonObject in project hadoop by apache.

the class HttpFSFileSystem method getXAttrs.

@Override
public Map<String, byte[]> getXAttrs(Path f, List<String> names) throws IOException {
    Preconditions.checkArgument(names != null && !names.isEmpty(), "XAttr names cannot be null or empty.");
    Map<String, String> params = new HashMap<String, String>();
    params.put(OP_PARAM, Operation.GETXATTRS.toString());
    Map<String, List<String>> multiValuedParams = Maps.newHashMap();
    multiValuedParams.put(XATTR_NAME_PARAM, names);
    HttpURLConnection conn = getConnection(Operation.GETXATTRS.getMethod(), params, multiValuedParams, f, true);
    HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
    JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
    return createXAttrMap((JSONArray) json.get(XATTRS_JSON));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList)

Example 9 with JsonObject

use of org.json.simple.JsonObject in project hadoop by apache.

the class HttpFSFileSystem method delete.

/**
   * Delete a file.
   *
   * @param f the path to delete.
   * @param recursive if path is a directory and set to
   * true, the directory is deleted else throws an exception. In
   * case of a file the recursive can be set to either true or false.
   *
   * @return true if delete is successful else false.
   *
   * @throws IOException
   */
@Override
public boolean delete(Path f, boolean recursive) throws IOException {
    Map<String, String> params = new HashMap<String, String>();
    params.put(OP_PARAM, Operation.DELETE.toString());
    params.put(RECURSIVE_PARAM, Boolean.toString(recursive));
    HttpURLConnection conn = getConnection(Operation.DELETE.getMethod(), params, f, true);
    HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
    JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
    return (Boolean) json.get(DELETE_JSON);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap)

Example 10 with JsonObject

use of org.json.simple.JsonObject in project hadoop by apache.

the class HttpFSFileSystem method getXAttrs.

@Override
public Map<String, byte[]> getXAttrs(Path f) throws IOException {
    Map<String, String> params = new HashMap<String, String>();
    params.put(OP_PARAM, Operation.GETXATTRS.toString());
    HttpURLConnection conn = getConnection(Operation.GETXATTRS.getMethod(), params, f, true);
    HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
    JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
    return createXAttrMap((JSONArray) json.get(XATTRS_JSON));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap)

Aggregations

JSONObject (org.json.simple.JSONObject)2110 JSONArray (org.json.simple.JSONArray)601 JSONParser (org.json.simple.parser.JSONParser)389 Test (org.junit.Test)341 Test (org.junit.jupiter.api.Test)247 HashMap (java.util.HashMap)214 IOException (java.io.IOException)199 ArrayList (java.util.ArrayList)190 ParseException (org.json.simple.parser.ParseException)171 Map (java.util.Map)140 Date (java.util.Date)74 InputStreamReader (java.io.InputStreamReader)62 List (java.util.List)61 File (java.io.File)60 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)60 URL (java.net.URL)45 HashSet (java.util.HashSet)42 HttpURLConnection (java.net.HttpURLConnection)41 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)41 HttpClient (org.apache.commons.httpclient.HttpClient)41