List of usage examples for org.apache.hadoop.io MD5Hash halfDigest
public long halfDigest()
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;//from w w 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); } } 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;/* w w w. j a v a 2s .c om*/ //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; }