/** * @param t operands * @return Array of binary byte arrays made from passed array of binary strings */ public static byte[][] toBinaryByteArrays(final String[] t) { byte[][] result = new byte[t.length][]; for (int i = 0; i < t.length; i++) { result[i] = Bytes.toBytesBinary(t[i]); } return result; }
@Override public void setFirstRow(String userInput) { firstRowBytes = Bytes.toBytesBinary(userInput); }
@Override public void setLastRow(String userInput) { lastRowBytes = Bytes.toBytesBinary(userInput); }
@Override public byte[] strToRow(String input) { return Bytes.toBytesBinary(input); }
@Override public byte[] toBytesBinary(String s) { return Bytes.toBytesBinary(s); }
@Override public byte[] toBytesBinary(String s) { return Bytes.toBytesBinary(s); }
private static byte[] getKeyFromConf(Configuration conf, String base64Key, String deprecatedKey) { String encoded = conf.get(base64Key); if (encoded != null) { return Base64.getDecoder().decode(encoded); } String oldStyleVal = conf.get(deprecatedKey); if (oldStyleVal == null) { return null; } LOG.warn("Using deprecated configuration " + deprecatedKey + " - please use static accessor methods instead."); return Bytes.toBytesBinary(oldStyleVal); }
private static List<MultiRowRangeFilter.RowRange> parseRowRangeParameter( String arg, String rangeSwitch) { final String[] ranges = arg.substring(rangeSwitch.length()).split(";"); final List<MultiRowRangeFilter.RowRange> rangeList = new ArrayList<>(); for (String range : ranges) { String[] startEnd = range.split(",", 2); if (startEnd.length != 2 || startEnd[1].contains(",")) { printUsage("Please specify range in such format as \"--range=a,b\" " + "or, with only one boundary, \"--range=,b\" or \"--range=a,\""); throw new IllegalArgumentException("Wrong range specification: " + range); } String startKey = startEnd[0]; String endKey = startEnd[1]; rangeList.add(new MultiRowRangeFilter.RowRange( Bytes.toBytesBinary(startKey), true, Bytes.toBytesBinary(endKey), false)); } return rangeList; }
/** * Create a key by concatenating multiple column values. * Override this function in order to produce different types of keys. * * @param vals * @return key generated by concatenating multiple column values */ protected ImmutableBytesWritable createGroupKey(byte[][] vals) { if(vals == null) { return null; } StringBuilder sb = new StringBuilder(); for(int i = 0; i < vals.length; i++) { if(i > 0) { sb.append(" "); } sb.append(Bytes.toString(vals[i])); } return new ImmutableBytesWritable(Bytes.toBytesBinary(sb.toString())); } }
/** * Create a key by concatenating multiple column values. * <p> * Override this function in order to produce different types of keys. * * @param vals The current key/values. * @return A key generated by concatenating multiple column values. */ protected ImmutableBytesWritable createGroupKey(byte[][] vals) { if(vals == null) { return null; } StringBuilder sb = new StringBuilder(); for(int i = 0; i < vals.length; i++) { if(i > 0) { sb.append(" "); } sb.append(Bytes.toString(vals[i])); } return new ImmutableBytesWritable(Bytes.toBytesBinary(sb.toString())); }
public static String format(final String value, final Unit unit) { StringBuilder human = new StringBuilder(); switch (unit) { case TIME_INTERVAL: human.append(humanReadableTTL(Long.parseLong(value))); break; case LONG: byte[] longBytes = Bytes.toBytesBinary(value); human.append(String.valueOf(Bytes.toLong(longBytes))); break; case BOOLEAN: byte[] booleanBytes = Bytes.toBytesBinary(value); human.append(String.valueOf(Bytes.toBoolean(booleanBytes))); break; default: human.append(value); } return human.toString(); }
private static Filter getExportFilter(String[] args) { Filter exportFilter; String filterCriteria = (args.length > 5) ? args[5]: null; if (filterCriteria == null) return null; if (filterCriteria.startsWith("^")) { String regexPattern = filterCriteria.substring(1, filterCriteria.length()); exportFilter = new RowFilter(CompareOperator.EQUAL, new RegexStringComparator(regexPattern)); } else { exportFilter = new PrefixFilter(Bytes.toBytesBinary(filterCriteria)); } return exportFilter; }
private static Filter getRowFilter(String[] args) { Filter rowFilter = null; String filterCriteria = (args.length > 3) ? args[3]: null; if (filterCriteria == null) return null; if (filterCriteria.startsWith("^")) { String regexPattern = filterCriteria.substring(1, filterCriteria.length()); rowFilter = new RowFilter(CompareOperator.EQUAL, new RegexStringComparator(regexPattern)); } else { rowFilter = new PrefixFilter(Bytes.toBytesBinary(filterCriteria)); } return rowFilter; }
private static SortedSet<byte[]> readFileToSearch(final Configuration conf, final FileSystem fs, final FileStatus keyFileStatus, SortedSet<byte []> result) throws IOException, InterruptedException { // verify uses file output format and writes <Text, Text>. We can read it as a text file try (InputStream in = fs.open(keyFileStatus.getPath()); BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { // extract out the key and return that missing as a missing key String line; while ((line = reader.readLine()) != null) { if (line.isEmpty()) continue; String[] parts = line.split("\\s+"); if (parts.length >= 1) { String key = parts[0]; result.add(Bytes.toBytesBinary(key)); } else { LOG.info("Cannot parse key from: " + line); } } } return result; }
public void testToBytesBinaryTrailingBackslashes() throws Exception { try { Bytes.toBytesBinary("abc\\x00\\x01\\"); } catch (StringIndexOutOfBoundsException ex) { fail("Illegal string access: " + ex.getMessage()); } }
private void verifyReversibleForBytes(byte[] originalBytes) { String convertedString = Bytes.toStringBinary(originalBytes); byte[] convertedBytes = Bytes.toBytesBinary(convertedString); if (Bytes.compareTo(originalBytes, convertedBytes) != 0) { fail("Not reversible for\nbyte[]: " + Arrays.toString(originalBytes) + ",\nStringBinary: " + convertedString); } }
public void testToStringBinary_toBytesBinary_Reversable() throws Exception { String bytes = Bytes.toStringBinary(Bytes.toBytes(2.17)); assertEquals(2.17, Bytes.toDouble(Bytes.toBytesBinary(bytes)), 0); }
for (; i < totalRows - rowsWithOneCol; i++) { byte[] row = Bytes.toBytesBinary("\\x00row" + i); Put put = new Put(row); put.addColumn(family, col1, value);
@Override public int run(String[] args) throws Exception { if (args.length != 1) { System.out.println("Usage : " + Delete.class.getSimpleName() + " <node to delete>"); return 0; } byte[] val = Bytes.toBytesBinary(args[0]); org.apache.hadoop.hbase.client.Delete delete = new org.apache.hadoop.hbase.client.Delete(val); try (Connection connection = ConnectionFactory.createConnection(getConf()); Table table = connection.getTable(getTableName(getConf()))) { table.delete(delete); } System.out.println("Delete successful"); return 0; } }
Put p = new Put(Bytes.toBytesBinary(rows[i])); p.addColumn(cf.getBytes(), cq.getBytes(), "value".getBytes()); ht.put(p); byte[] fuzzyKey = Bytes.toBytesBinary("\\x9B\\x00\\x044e"); byte[] mask = new byte[] { 0, 0, 0, 0, 0 };