/** * Given a byte array, returns in MD5 hash as a hex string. * @param key * @return SHA1 hash as a 32 character hex string. */ public static String getMD5AsHex(byte[] key) { return getMD5AsHex(key, 0, key.length); }
/** * @param startKey * The start key. * @param date * The string of the latest timestamp of cells in this file, the format is yyyymmdd. * @param uuid * The uuid */ private MobFileName(byte[] startKey, String date, String uuid) { this.startKey = MD5Hash.getMD5AsHex(startKey, 0, startKey.length); this.uuid = uuid; this.date = date; this.fileName = this.startKey + this.date + this.uuid; }
/** * Converts the given key to string, and prefixes it with the MD5 hash of * the index's string representation. */ public static String md5PrefixedKey(long key) { String stringKey = Long.toString(key); String md5hash = MD5Hash.getMD5AsHex(Bytes.toBytes(stringKey)); // flip the key to randomize return md5hash + "-" + stringKey; }
public Context setKey(Key key) { Preconditions.checkNotNull(cipher, "Context does not have a cipher"); // validate the key length byte[] encoded = key.getEncoded(); if (encoded.length != cipher.getKeyLength()) { throw new RuntimeException("Illegal key length, have=" + encoded.length + ", want=" + cipher.getKeyLength()); } this.key = key; this.keyHash = MD5Hash.getMD5AsHex(encoded); return this; } }
String md5Hash = MD5Hash.getMD5AsHex(b, 0, offset); byte [] md5HashBytes = Bytes.toBytes(md5Hash);
private Path createTableFiles(final Path rootDir, final String tableName, final Set<String> tableRegions, final Set<String> tableFamilies, final Set<String> tableHFiles) throws IOException { Path tableDir = new Path(rootDir, tableName); for (int r = 0; r < 10; ++r) { String regionName = MD5Hash.getMD5AsHex(Bytes.toBytes(r)); tableRegions.add(regionName); Path regionDir = new Path(tableDir, regionName); for (int f = 0; f < 3; ++f) { String familyName = "f" + f; tableFamilies.add(familyName); Path familyDir = new Path(regionDir, familyName); fs.mkdirs(familyDir); for (int h = 0; h < 5; ++h) { String hfileName = TEST_UTIL.getRandomUUID().toString().replaceAll("-", ""); tableHFiles.add(hfileName); fs.createNewFile(new Path(familyDir, hfileName)); } } } return tableDir; } }
@Test public void testCreateRegionInfoName() throws Exception { final String tableName = name.getMethodName(); final TableName tn = TableName.valueOf(tableName); String startKey = "startkey"; final byte[] sk = Bytes.toBytes(startKey); String id = "id"; // old format region name byte [] name = RegionInfo.createRegionName(tn, sk, id, false); String nameStr = Bytes.toString(name); assertEquals(tableName + "," + startKey + "," + id, nameStr); // new format region name. String md5HashInHex = MD5Hash.getMD5AsHex(name); assertEquals(RegionInfo.MD5_HEX_LENGTH, md5HashInHex.length()); name = RegionInfo.createRegionName(tn, sk, id, true); nameStr = Bytes.toString(name); assertEquals(tableName + "," + startKey + "," + id + "." + md5HashInHex + ".", nameStr); }
public static void loadData(final Connection connection, final TableName tableName, int rows, final byte[][] splitKeys, final String... sfamilies) throws IOException { byte[][] families = new byte[sfamilies.length][]; for (int i = 0; i < families.length; ++i) { families[i] = Bytes.toBytes(sfamilies[i]); } BufferedMutator mutator = connection.getBufferedMutator(tableName); // Ensure one row per region assertTrue(rows >= splitKeys.length); for (byte[] k: splitKeys) { byte[] value = Bytes.add(Bytes.toBytes(System.currentTimeMillis()), k); byte[] key = Bytes.add(k, Bytes.toBytes(MD5Hash.getMD5AsHex(value))); mutator.mutate(createPut(families, key, value)); rows--; } // Add other extra rows. more rows, more files while (rows-- > 0) { byte[] value = Bytes.add(Bytes.toBytes(System.currentTimeMillis()), Bytes.toBytes(rows)); byte[] key = Bytes.toBytes(MD5Hash.getMD5AsHex(value)); mutator.mutate(createPut(families, key, value)); } mutator.flush(); }
@Test public void testCreateHRegionInfoName() throws Exception { final String tableName = name.getMethodName(); final TableName tn = TableName.valueOf(tableName); String startKey = "startkey"; final byte[] sk = Bytes.toBytes(startKey); String id = "id"; // old format region name byte [] name = HRegionInfo.createRegionName(tn, sk, id, false); String nameStr = Bytes.toString(name); assertEquals(tableName + "," + startKey + "," + id, nameStr); // new format region name. String md5HashInHex = MD5Hash.getMD5AsHex(name); assertEquals(HRegionInfo.MD5_HEX_LENGTH, md5HashInHex.length()); name = HRegionInfo.createRegionName(tn, sk, id, true); nameStr = Bytes.toString(name); assertEquals(tableName + "," + startKey + "," + id + "." + md5HashInHex + ".", nameStr); }
public static void loadData(final HBaseTestingUtility util, final BufferedMutator mutator, int rows, byte[]... families) throws IOException, InterruptedException { // Ensure one row per region assertTrue(rows >= KEYS.length); for (byte k0: KEYS) { byte[] k = new byte[] { k0 }; byte[] value = Bytes.add(Bytes.toBytes(System.currentTimeMillis()), k); byte[] key = Bytes.add(k, Bytes.toBytes(MD5Hash.getMD5AsHex(value))); final byte[][] families1 = families; final byte[] key1 = key; final byte[] value1 = value; mutator.mutate(createPut(families1, key1, value1)); rows--; } // Add other extra rows. more rows, more files while (rows-- > 0) { byte[] value = Bytes.add(Bytes.toBytes(System.currentTimeMillis()), Bytes.toBytes(rows)); byte[] key = Bytes.toBytes(MD5Hash.getMD5AsHex(value)); final byte[][] families1 = families; final byte[] key1 = key; final byte[] value1 = value; mutator.mutate(createPut(families1, key1, value1)); } mutator.flush(); waitForTableToBeOnline(util, mutator.getName()); }
@Test public void testGet() { MobFileName mobFileName = MobFileName.create(startKey, dateStr, uuid); assertEquals(MD5Hash.getMD5AsHex(startKey, 0, startKey.length), mobFileName.getStartKey()); assertEquals(dateStr, mobFileName.getDate()); assertEquals(mobFileName.getFileName(), MD5Hash.getMD5AsHex(startKey, 0, startKey.length) + dateStr + uuid); }
@Test public void testRemoveAllLastPushedSeqIdsForPeer() throws Exception { String peerId = "1"; String peerIdToDelete = "2"; for (int i = 0; i < 100; i++) { String encodedRegionName = MD5Hash.getMD5AsHex(Bytes.toBytes(i)); STORAGE.setLastSequenceIds(peerId, ImmutableMap.of(encodedRegionName, (long) i)); STORAGE.setLastSequenceIds(peerIdToDelete, ImmutableMap.of(encodedRegionName, (long) i)); } for (int i = 0; i < 100; i++) { String encodedRegionName = MD5Hash.getMD5AsHex(Bytes.toBytes(i)); assertEquals(i, STORAGE.getLastSequenceId(encodedRegionName, peerId)); assertEquals(i, STORAGE.getLastSequenceId(encodedRegionName, peerIdToDelete)); } STORAGE.removeLastSequenceIds(peerIdToDelete); for (int i = 0; i < 100; i++) { String encodedRegionName = MD5Hash.getMD5AsHex(Bytes.toBytes(i)); assertEquals(i, STORAGE.getLastSequenceId(encodedRegionName, peerId)); assertEquals(HConstants.NO_SEQNUM, STORAGE.getLastSequenceId(encodedRegionName, peerIdToDelete)); } } }
String md5Hash = MD5Hash.getMD5AsHex(b, 0, offset); byte [] md5HashBytes = Bytes.toBytes(md5Hash);
/** * Given a byte array, returns in MD5 hash as a hex string. * @param key * @return SHA1 hash as a 32 character hex string. */ public static String getMD5AsHex(byte[] key) { return getMD5AsHex(key, 0, key.length); }
/** * Given a byte array, returns in MD5 hash as a hex string. * @param key * @return SHA1 hash as a 32 character hex string. */ public static String getMD5AsHex(byte[] key) { return getMD5AsHex(key, 0, key.length); }
/** * Given a byte array, returns in MD5 hash as a hex string. * @param key * @return SHA1 hash as a 32 character hex string. */ public static String getMD5AsHex(byte[] key) { return getMD5AsHex(key, 0, key.length); }
/** * Given a byte array, returns in MD5 hash as a hex string. * @param key * @return SHA1 hash as a 32 character hex string. */ public static String getMD5AsHex(byte[] key) { return getMD5AsHex(key, 0, key.length); }
/** * Converts the given key to string, and prefixes it with the MD5 hash of * the index's string representation. */ public static String md5PrefixedKey(long key) { String stringKey = Long.toString(key); String md5hash = MD5Hash.getMD5AsHex(Bytes.toBytes(stringKey)); // flip the key to randomize return md5hash + "-" + stringKey; }
public static byte[] getMd5Row(String rowkey) { int rowInt = Integer.valueOf(rowkey); byte[] rowBytes = Bytes.toBytes(rowInt); return Bytes.toBytes(MD5Hash.getMD5AsHex(rowBytes)); } }
String md5Hash = MD5Hash.getMD5AsHex(b, 0, offset); byte [] md5HashBytes = Bytes.toBytes(md5Hash);