Example usage for org.apache.hadoop.fs FileChecksum FileChecksum

List of usage examples for org.apache.hadoop.fs FileChecksum FileChecksum

Introduction

In this page you can find the example usage for org.apache.hadoop.fs FileChecksum FileChecksum.

Prototype

FileChecksum

Source Link

Usage

From source file:com.pigai.hadoop.HttpFSFileSystem.java

License:Apache License

@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);
    validateResponse(conn, HttpURLConnection.HTTP_OK);
    final JSONObject json = (JSONObject) ((JSONObject) jsonParse(conn)).get(FILE_CHECKSUM_JSON);
    return new FileChecksum() {
        @Override//from  ww  w. ja  v  a  2 s.c  o  m
        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));
        }

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

        public void readFields(DataInput in) throws IOException {
            throw new UnsupportedOperationException();
        }
    };
}

From source file:org.apache.falcon.hadoop.JailedFileSystem.java

License:Apache License

@Override
public FileChecksum getFileChecksum(Path f) throws IOException {
    final byte[] md5 = DigestUtils.md5(FileUtils.readFileToByteArray(new File(toLocalPath(f).toString())));
    return new FileChecksum() {

        @Override/*w  w  w.  j a  v  a 2 s.  c  om*/
        public String getAlgorithmName() {
            return "MD5";
        }

        @Override
        public int getLength() {
            return md5.length;
        }

        @Override
        public byte[] getBytes() {
            return md5;
        }

        @Override
        public void write(DataOutput out) throws IOException {
        }

        @Override
        public void readFields(DataInput in) throws IOException {
        }
    };
}