Example usage for org.apache.hadoop.io MD5Hash digest

List of usage examples for org.apache.hadoop.io MD5Hash digest

Introduction

In this page you can find the example usage for org.apache.hadoop.io MD5Hash digest.

Prototype

null digest

To view the source code for org.apache.hadoop.io MD5Hash digest.

Click Source Link

Usage

From source file:bytes.ByteValues.java

License:Open Source License

public static byte[] getFullValue(String id) throws NotSupportedDatatypeException {
    byte[] ret = new byte[totalBytes];

    byte t = (byte) 1;//default String
    byte[] val = null;
    if (id.contains("\"^^")) {//type
        StringTokenizer tokenizer = new StringTokenizer(id);
        String value = tokenizer.nextToken("^^");
        String type = tokenizer.nextToken();
        type = type.substring(type.lastIndexOf("#") + 1, type.length() - 1);
        //System.out.println(type +" value: "+value);
        if (type.contains("string")) {
            t = TYPE_STRING;/*ww  w  .j av a2  s .c  o m*/
            //System.out.println(t +" value: "+value);
            MD5Hash md5h = MD5Hash.digest(value);
            long hashVal = md5h.halfDigest();
            val = Bytes.toBytes(hashVal);
        } else if (type.contains("boolean")) {
            t = TYPE_BOOLEAN;
            val = new byte[valueBytes];
            if (value.contains("true") || value.contains("1")) {
                val[valueBytes - 1] = (byte) 1;
            } else if (value.contains("false") || value.contains("0")) {
                val[valueBytes - 1] = (byte) 0;
            }
        } else if (type.contains("int")) {
            t = TYPE_INT;
            val = Bytes
                    .toBytes(SortedInt.toSortedInt(Integer.parseInt(value.substring(1, value.length() - 1))));
        } else if (type.contains("long")) {
            t = TYPE_LONG;
            val = Bytes
                    .toBytes(SortedLong.toSortedLong(Long.parseLong(value.substring(1, value.length() - 1))));
        } else if (type.contains("demical")) {
            t = TYPE_DEMICAL;
            throw new NotSupportedDatatypeException(type);
        } else if (type.contains("float")) {
            t = TYPE_FLOAT;
            val = Bytes.toBytes(Float.parseFloat(value.substring(1, value.length() - 1)));
        } else if (type.contains("double")) {
            t = TYPE_DOUBLE;
            val = Bytes.toBytes(Double.parseDouble(value.substring(1, value.length() - 1)));
        } else if (type.contains("duration")) {
            t = TYPE_DURATION;
            throw new NotSupportedDatatypeException(type);
        } else if (type.contains("datetime")) {
            t = TYPE_DATETIME;
            throw new NotSupportedDatatypeException(type);
        } else if (type.contains("time")) {
            t = TYPE_TIME;
            throw new NotSupportedDatatypeException(type);
        } else if (type.contains("date")) {
            t = TYPE_DATE;
            System.out.println(type + " value: " + value);
            String date = value.substring(1, value.length() - 1);
            StringTokenizer t2 = new StringTokenizer(date);
            int day = Integer.parseInt(t2.nextToken("/"));
            int month = Integer.parseInt(t2.nextToken("/"));
            int year = Integer.parseInt(t2.nextToken("/"));
            System.out.println(day + " " + month + " " + year);

            Calendar c = Calendar.getInstance();
            c.set(year, month, day);
            val = Bytes.toBytes(c.getTimeInMillis());
        } else {
            System.out.println(type + " value: " + value);
            throw new NotSupportedDatatypeException(type);
        }

    } else {//string
        t = TYPE_STRING;
        //System.out.println(t +" value: "+value);
        MD5Hash md5h = MD5Hash.digest(id);
        long hashVal = md5h.halfDigest();
        val = Bytes.toBytes(hashVal);
    }

    ret[0] = t;
    for (int i = 0; i < valueBytes; i++) {
        ret[i + 1] = val[i];
    }

    if (ret.length != totalBytes) {
        System.exit(5);
    }

    return ret;

}

From source file:bytes.ByteValues.java

License:Open Source License

public static byte[] getFullValue(String value, String type) throws NotSupportedDatatypeException {
    byte[] ret = new byte[totalBytes];
    value = "\"" + value + "\"";
    //System.out.println(value);
    byte t = (byte) 1;//default String
    byte[] val = null;
    if (type.contains("string")) {
        t = TYPE_STRING;/*from ww w  . ja v  a2  s  .  c o m*/
        //System.out.println(t +" value: "+value);
        MD5Hash md5h = MD5Hash.digest(value);
        long hashVal = md5h.halfDigest();
        val = Bytes.toBytes(hashVal);
    } else if (type.contains("boolean")) {
        t = TYPE_BOOLEAN;
        val = new byte[valueBytes];
        if (value.contains("true") || value.contains("1")) {
            val[valueBytes - 1] = (byte) 1;
        } else if (value.contains("false") || value.contains("0")) {
            val[valueBytes - 1] = (byte) 0;
        }
    } else if (type.contains("int")) {
        t = TYPE_INT;
        val = Bytes.toBytes(SortedInt.toSortedInt(Integer.parseInt(value.substring(1, value.length() - 1))));
    } else if (type.contains("long")) {
        t = TYPE_LONG;
        val = Bytes.toBytes(SortedLong.toSortedLong(Long.parseLong(value.substring(1, value.length() - 1))));
    } else if (type.contains("demical")) {
        t = TYPE_DEMICAL;
        throw new NotSupportedDatatypeException(type);
    } else if (type.contains("float")) {
        t = TYPE_FLOAT;
        val = Bytes.toBytes(Float.parseFloat(value.substring(1, value.length() - 1)));
    } else if (type.contains("double")) {
        t = TYPE_DOUBLE;
        val = Bytes.toBytes(Double.parseDouble(value.substring(1, value.length() - 1)));
    } else if (type.contains("duration")) {
        t = TYPE_DURATION;
        throw new NotSupportedDatatypeException(type);
    } else if (type.contains("datetime")) {
        t = TYPE_DATETIME;
        throw new NotSupportedDatatypeException(type);
    } else if (type.contains("time")) {
        t = TYPE_TIME;
        throw new NotSupportedDatatypeException(type);
    } else if (type.contains("date")) {
        t = TYPE_DATE;
        System.out.println(type + " value: " + value);
        String date = value.substring(1, value.length() - 1);
        StringTokenizer t2 = new StringTokenizer(date);
        int day = Integer.parseInt(t2.nextToken("/"));
        int month = Integer.parseInt(t2.nextToken("/"));
        int year = Integer.parseInt(t2.nextToken("/"));
        System.out.println(day + " " + month + " " + year);

        Calendar c = Calendar.getInstance();
        c.set(year, month, day);
        val = Bytes.toBytes(c.getTimeInMillis());
    } else {
        System.out.println(type + " value: " + value);
        throw new NotSupportedDatatypeException(type);
    }

    ret[0] = t;
    for (int i = 0; i < valueBytes; i++) {
        ret[i + 1] = val[i];
    }

    if (ret.length != totalBytes) {
        System.exit(5);
    }

    return ret;
}

From source file:co.cask.cdap.logging.serialize.LogSchema.java

License:Apache License

public LogSchema() throws IOException {
    this.schema = new Schema.Parser().parse(getClass().getResourceAsStream(SCHEMA_LOCATION));
    this.schemaHash = new SchemaHash(MD5Hash.digest(getClass().getResourceAsStream(SCHEMA_LOCATION)));
}

From source file:co.nubetech.hiho.dedup.HashUtility.java

License:Apache License

public static MD5Hash getMD5Hash(Object object) throws IOException {
    return MD5Hash.digest(object.toString());
}

From source file:co.nubetech.hiho.dedup.HashUtility.java

License:Apache License

public static MD5Hash getMD5Hash(Text key) throws IOException {
    return MD5Hash.digest(key.getBytes());
}

From source file:co.nubetech.hiho.dedup.HashUtility.java

License:Apache License

public static MD5Hash getMD5Hash(String key) throws IOException {
    return MD5Hash.digest(key.getBytes());
}

From source file:co.nubetech.hiho.dedup.HashUtility.java

License:Apache License

public static MD5Hash getMD5Hash(LongWritable key) throws IOException {
    return MD5Hash.digest(key.toString());
}

From source file:co.nubetech.hiho.dedup.HashUtility.java

License:Apache License

public static MD5Hash getMD5Hash(BytesWritable key) throws IOException {
    return MD5Hash.digest(key.getBytes());
}

From source file:co.nubetech.hiho.dedup.HashUtility.java

License:Apache License

public static MD5Hash getMD5Hash(IntWritable key) throws IOException {
    return MD5Hash.digest(key.toString());
}

From source file:co.nubetech.hiho.dedup.HashUtility.java

License:Apache License

public static MD5Hash getMD5Hash(ArrayWritable key) throws IOException {
    return MD5Hash.digest(key.toString());
}