Search in sources :

Example 11 with JSONObject

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

the class HttpFSFileSystem method truncate.

/**
   * Truncate a file.
   * 
   * @param f the file to be truncated.
   * @param newLength The size the file is to be truncated to.
   *
   * @throws IOException
   */
@Override
public boolean truncate(Path f, long newLength) throws IOException {
    Map<String, String> params = new HashMap<String, String>();
    params.put(OP_PARAM, Operation.TRUNCATE.toString());
    params.put(NEW_LENGTH_PARAM, Long.toString(newLength));
    HttpURLConnection conn = getConnection(Operation.TRUNCATE.getMethod(), params, f, true);
    JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
    return (Boolean) json.get(TRUNCATE_JSON);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap)

Example 12 with JSONObject

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

the class HttpFSFileSystem method getAclStatus.

/**
   * Get the ACL information for a given file
   * @param path Path to acquire ACL info for
   * @return the ACL information in JSON format
   * @throws IOException
   */
@Override
public AclStatus getAclStatus(Path path) throws IOException {
    Map<String, String> params = new HashMap<String, String>();
    params.put(OP_PARAM, Operation.GETACLSTATUS.toString());
    HttpURLConnection conn = getConnection(Operation.GETACLSTATUS.getMethod(), params, path, true);
    HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
    JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
    json = (JSONObject) json.get(ACL_STATUS_JSON);
    return createAclStatus(json);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap)

Example 13 with JSONObject

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

the class HttpFSFileSystem method listStatus.

/**
   * List the statuses of the files/directories in the given path if the path is
   * a directory.
   *
   * @param f given path
   *
   * @return the statuses of the files/directories in the given patch
   *
   * @throws IOException
   */
@Override
public FileStatus[] listStatus(Path f) throws IOException {
    Map<String, String> params = new HashMap<String, String>();
    params.put(OP_PARAM, Operation.LISTSTATUS.toString());
    HttpURLConnection conn = getConnection(Operation.LISTSTATUS.getMethod(), params, f, true);
    HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
    JSONObject json = (JSONObject) HttpFSUtils.jsonParse(conn);
    return toFileStatuses(json, f);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap)

Example 14 with JSONObject

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

the class HttpFSFileSystem method getContentSummary.

@Override
public ContentSummary getContentSummary(Path f) throws IOException {
    Map<String, String> params = new HashMap<String, String>();
    params.put(OP_PARAM, Operation.GETCONTENTSUMMARY.toString());
    HttpURLConnection conn = getConnection(Operation.GETCONTENTSUMMARY.getMethod(), params, f, true);
    HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
    JSONObject json = (JSONObject) ((JSONObject) HttpFSUtils.jsonParse(conn)).get(CONTENT_SUMMARY_JSON);
    return new ContentSummary.Builder().length((Long) json.get(CONTENT_SUMMARY_LENGTH_JSON)).fileCount((Long) json.get(CONTENT_SUMMARY_FILE_COUNT_JSON)).directoryCount((Long) json.get(CONTENT_SUMMARY_DIRECTORY_COUNT_JSON)).quota((Long) json.get(CONTENT_SUMMARY_QUOTA_JSON)).spaceConsumed((Long) json.get(CONTENT_SUMMARY_SPACE_CONSUMED_JSON)).spaceQuota((Long) json.get(CONTENT_SUMMARY_SPACE_QUOTA_JSON)).build();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) ContentSummary(org.apache.hadoop.fs.ContentSummary)

Example 15 with JSONObject

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

the class HttpFSFileSystem method getFileChecksum.

@Override
public FileChecksum getFileChecksum(Path f) throws IOException {
    Map<String, String> params = new HashMap<String, String>();
    params.put(OP_PARAM, Operation.GETFILECHECKSUM.toString());
    HttpURLConnection conn = getConnection(Operation.GETFILECHECKSUM.getMethod(), params, f, true);
    HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
    final JSONObject json = (JSONObject) ((JSONObject) HttpFSUtils.jsonParse(conn)).get(FILE_CHECKSUM_JSON);
    return new FileChecksum() {

        @Override
        public String getAlgorithmName() {
            return (String) json.get(CHECKSUM_ALGORITHM_JSON);
        }

        @Override
        public int getLength() {
            return ((Long) json.get(CHECKSUM_LENGTH_JSON)).intValue();
        }

        @Override
        public byte[] getBytes() {
            return StringUtils.hexStringToByte((String) json.get(CHECKSUM_BYTES_JSON));
        }

        @Override
        public void write(DataOutput out) throws IOException {
            throw new UnsupportedOperationException();
        }

        @Override
        public void readFields(DataInput in) throws IOException {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : DataInput(java.io.DataInput) DataOutput(java.io.DataOutput) HttpURLConnection(java.net.HttpURLConnection) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) FileChecksum(org.apache.hadoop.fs.FileChecksum)

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