org.apache.hadoop.hbase.util.Bytes.random()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(74)

本文整理了Java中org.apache.hadoop.hbase.util.Bytes.random()方法的一些代码示例,展示了Bytes.random()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.random()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.util.Bytes
类名称:Bytes
方法名:random

Bytes.random介绍

[英]Fill given array with random bytes.
[中]用随机字节填充给定数组。

代码示例

代码示例来源:origin: apache/hbase

private byte[] getRandomBlock(int size) {
 byte[] b = new byte[size];
 Bytes.random(b);
 return b;
}

代码示例来源:origin: apache/hbase

/**
 * Return a 128 bit key derived from the concatenation of the supplied
 * arguments using PBKDF2WithHmacSHA1 at 10,000 iterations.
 *
 */
public static byte[] pbkdf128(String... args) {
 byte[] salt = new byte[128];
 Bytes.random(salt);
 StringBuilder sb = new StringBuilder();
 for (String s: args) {
  sb.append(s);
 }
 PBEKeySpec spec = new PBEKeySpec(sb.toString().toCharArray(), salt, 10000, 128);
 try {
  return SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1")
   .generateSecret(spec).getEncoded();
 } catch (NoSuchAlgorithmException e) {
  throw new RuntimeException(e);
 } catch (InvalidKeySpecException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: apache/hbase

/**
 * Return a 128 bit key derived from the concatenation of the supplied
 * arguments using PBKDF2WithHmacSHA1 at 10,000 iterations.
 *
 */
public static byte[] pbkdf128(byte[]... args) {
 byte[] salt = new byte[128];
 Bytes.random(salt);
 StringBuilder sb = new StringBuilder();
 for (byte[] b: args) {
  sb.append(Arrays.toString(b));
 }
 PBEKeySpec spec = new PBEKeySpec(sb.toString().toCharArray(), salt, 10000, 128);
 try {
  return SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1")
   .generateSecret(spec).getEncoded();
 } catch (NoSuchAlgorithmException e) {
  throw new RuntimeException(e);
 } catch (InvalidKeySpecException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: apache/hbase

@Test
public void testSmallBlocks() throws Exception {
 byte[] key = new byte[16];
 Bytes.random(key);
 byte[] iv = new byte[16];
 Bytes.random(iv);
 for (int size: new int[] { 4, 8, 16, 32, 64, 128, 256, 512 } ) {
  checkTransformSymmetry(key, iv, getRandomBlock(size));
 }
}

代码示例来源:origin: apache/hbase

@Test
public void testOddSizedBlocks() throws Exception {
 byte[] key = new byte[16];
 Bytes.random(key);
 byte[] iv = new byte[16];
 Bytes.random(iv);
 for (int size: new int[] { 3, 7, 11, 23, 47, 79, 119, 175 } ) {
  checkTransformSymmetry(key, iv, getRandomBlock(size));
 }
}

代码示例来源:origin: apache/hbase

@Test
public void testTypicalHFileBlocks() throws Exception {
 byte[] key = new byte[16];
 Bytes.random(key);
 byte[] iv = new byte[16];
 Bytes.random(iv);
 for (int size: new int[] { 4 * 1024, 8 * 1024, 64 * 1024, 128 * 1024 } ) {
  checkTransformSymmetry(key, iv, getRandomBlock(size));
 }
}

代码示例来源:origin: apache/hbase

@Test
public void testLargeBlocks() throws Exception {
 byte[] key = new byte[16];
 Bytes.random(key);
 byte[] iv = new byte[16];
 Bytes.random(iv);
 for (int size: new int[] { 256 * 1024, 512 * 1024, 1024 * 1024 } ) {
  checkTransformSymmetry(key, iv, getRandomBlock(size));
 }
}

代码示例来源:origin: apache/hbase

if (context.getCipher().getIvLength() > 0) {
 iv = new byte[context.getCipher().getIvLength()];
 Bytes.random(iv);
Bytes.random(plaintext);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Encryption.encrypt(out, new ByteArrayInputStream(plaintext), context, iv);

代码示例来源:origin: apache/hbase

for (int j = 0; j < NUM_COLS; j++) {
 byte[] value = new byte[50];
 Bytes.random(value);
 p.addColumn(FAMILY, Bytes.toBytes(Integer.toString(j)), value);

代码示例来源:origin: apache/hbase

Put put = new Put(rowToCheck);
byte[] value = new byte[writeValueSize];
Bytes.random(value);
put.addColumn(column.getName(), HConstants.EMPTY_BYTE_ARRAY, value);

代码示例来源:origin: apache/phoenix

@Test(timeout=120000)
public void testCompactNonPhoenixTable() throws Exception {
  try (Connection conn = getConnection()) {
    // create a vanilla HBase table (non-Phoenix)
    String randomTable = generateUniqueName();
    TableName hbaseTN = TableName.valueOf(randomTable);
    byte[] famBytes = Bytes.toBytes("fam");
    Table hTable = getUtility().createTable(hbaseTN, famBytes);
    TestUtil.addCoprocessor(conn, randomTable, UngroupedAggregateRegionObserver.class);
    Put put = new Put(Bytes.toBytes("row"));
    byte[] value = new byte[1];
    Bytes.random(value);
    put.addColumn(famBytes, Bytes.toBytes("colQ"), value);
    hTable.put(put);
    // major compaction shouldn't cause a timeout or RS abort
    List<HRegion> regions = getUtility().getHBaseCluster().getRegions(hbaseTN);
    HRegion hRegion = regions.get(0);
    hRegion.flush(true);
    HStore store = hRegion.getStore(famBytes);
    store.triggerMajorCompaction();
    store.compactRecentForTestingAssumingDefaultPolicy(1);
    // we should be able to compact syscat itself as well
    regions = getUtility().getHBaseCluster().getRegions(TableName.valueOf(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME));
    hRegion = regions.get(0);
    hRegion.flush(true);
    store = hRegion.getStore(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES);
    store.triggerMajorCompaction();
    store.compactRecentForTestingAssumingDefaultPolicy(1);
  }
}

代码示例来源:origin: org.apache.hbase/hbase-common

private byte[] getRandomBlock(int size) {
 byte[] b = new byte[size];
 Bytes.random(b);
 return b;
}

代码示例来源:origin: org.apache.hbase/hbase-common

@Test
public void testSmallBlocks() throws Exception {
 byte[] key = new byte[16];
 Bytes.random(key);
 byte[] iv = new byte[16];
 Bytes.random(iv);
 for (int size: new int[] { 4, 8, 16, 32, 64, 128, 256, 512 } ) {
  checkTransformSymmetry(key, iv, getRandomBlock(size));
 }
}

代码示例来源:origin: com.aliyun.hbase/alihbase-common

@Test
public void testSmallBlocks() throws Exception {
 byte[] key = new byte[16];
 Bytes.random(key);
 byte[] iv = new byte[16];
 Bytes.random(iv);
 for (int size: new int[] { 4, 8, 16, 32, 64, 128, 256, 512 } ) {
  checkTransformSymmetry(key, iv, getRandomBlock(size));
 }
}

代码示例来源:origin: org.apache.hbase/hbase-common

@Test
public void testLargeBlocks() throws Exception {
 byte[] key = new byte[16];
 Bytes.random(key);
 byte[] iv = new byte[16];
 Bytes.random(iv);
 for (int size: new int[] { 256 * 1024, 512 * 1024, 1024 * 1024 } ) {
  checkTransformSymmetry(key, iv, getRandomBlock(size));
 }
}

代码示例来源:origin: org.apache.hbase/hbase-common

@Test
public void testOddSizedBlocks() throws Exception {
 byte[] key = new byte[16];
 Bytes.random(key);
 byte[] iv = new byte[16];
 Bytes.random(iv);
 for (int size: new int[] { 3, 7, 11, 23, 47, 79, 119, 175 } ) {
  checkTransformSymmetry(key, iv, getRandomBlock(size));
 }
}

代码示例来源:origin: org.apache.hbase/hbase-common

@Test
public void testTypicalHFileBlocks() throws Exception {
 byte[] key = new byte[16];
 Bytes.random(key);
 byte[] iv = new byte[16];
 Bytes.random(iv);
 for (int size: new int[] { 4 * 1024, 8 * 1024, 64 * 1024, 128 * 1024 } ) {
  checkTransformSymmetry(key, iv, getRandomBlock(size));
 }
}

代码示例来源:origin: com.aliyun.hbase/alihbase-common

@Test
public void testOddSizedBlocks() throws Exception {
 byte[] key = new byte[16];
 Bytes.random(key);
 byte[] iv = new byte[16];
 Bytes.random(iv);
 for (int size: new int[] { 3, 7, 11, 23, 47, 79, 119, 175 } ) {
  checkTransformSymmetry(key, iv, getRandomBlock(size));
 }
}

代码示例来源:origin: com.aliyun.hbase/alihbase-common

@Test
public void testTypicalHFileBlocks() throws Exception {
 byte[] key = new byte[16];
 Bytes.random(key);
 byte[] iv = new byte[16];
 Bytes.random(iv);
 for (int size: new int[] { 4 * 1024, 8 * 1024, 64 * 1024, 128 * 1024 } ) {
  checkTransformSymmetry(key, iv, getRandomBlock(size));
 }
}

代码示例来源:origin: com.aliyun.hbase/alihbase-common

@Test
public void testLargeBlocks() throws Exception {
 byte[] key = new byte[16];
 Bytes.random(key);
 byte[] iv = new byte[16];
 Bytes.random(iv);
 for (int size: new int[] { 256 * 1024, 512 * 1024, 1024 * 1024 } ) {
  checkTransformSymmetry(key, iv, getRandomBlock(size));
 }
}

相关文章

微信公众号

最新文章

更多