1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.hbql.client;
22
23 import java.util.Collection;
24
25 public class Util {
26
27 public static String getZeroPaddedNonNegativeNumber(final long val, final int width) throws HBqlException {
28
29 if (val < 0)
30 throw new HBqlException("Value " + val + " must be non-negative");
31
32 final String strval = "" + val;
33 final int padsize = width - strval.length();
34 if (padsize < 0)
35 throw new HBqlException("Value " + val + " exceeds width " + width);
36
37 final StringBuilder sbuf = new StringBuilder();
38 for (int i = 0; i < padsize; i++)
39 sbuf.append("0");
40
41 sbuf.append(strval);
42 return sbuf.toString();
43 }
44
45 public static byte[][] getStringsAsBytes(final Collection<String> vals) {
46
47 final byte[][] retval;
48
49 if (vals == null) {
50 retval = null;
51 }
52 else {
53 retval = new byte[vals.size()][];
54 int cnt = 0;
55 for (final String val : vals)
56 retval[cnt++] = val.getBytes();
57 }
58
59 return retval;
60 }
61
62 public static byte[] getFixedWidthString(final char c, final int len) {
63 final StringBuilder sbuf = new StringBuilder(len);
64 for (int i = 0; i < len; i++)
65 sbuf.append(c);
66 return sbuf.toString().getBytes();
67 }
68 }