Example usage for java.lang Character MAX_RADIX

List of usage examples for java.lang Character MAX_RADIX

Introduction

In this page you can find the example usage for java.lang Character MAX_RADIX.

Prototype

int MAX_RADIX

To view the source code for java.lang Character MAX_RADIX.

Click Source Link

Document

The maximum radix available for conversion to and from strings.

Usage

From source file:org.apache.accumulo.server.master.tableOps.Utils.java

static String getNextTableId(String tableName, Instance instance) throws ThriftTableOperationException {

    String tableId = null;/*from   w  w  w.  ja v a 2s.  c  o m*/
    try {
        IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
        final String ntp = ZooUtil.getRoot(instance) + Constants.ZTABLES;
        byte[] nid = zoo.mutate(ntp, "0".getBytes(), ZooUtil.PUBLIC, new Mutator() {
            @Override
            public byte[] mutate(byte[] currentValue) throws Exception {
                BigInteger nextId = new BigInteger(new String(currentValue), Character.MAX_RADIX);
                nextId = nextId.add(BigInteger.ONE);
                return nextId.toString(Character.MAX_RADIX).getBytes();
            }
        });
        return new String(nid);
    } catch (Exception e1) {
        Logger.getLogger(CreateTable.class).error("Failed to assign tableId to " + tableName, e1);
        throw new ThriftTableOperationException(tableId, tableName, TableOperation.CREATE,
                TableOperationExceptionType.OTHER, e1.getMessage());
    }
}

From source file:org.apache.accumulo.master.tableOps.Utils.java

static String getNextTableId(String tableName, Instance instance) throws ThriftTableOperationException {

    String tableId = null;/*from   w w w.j  a va2  s.c o m*/
    try {
        IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
        final String ntp = ZooUtil.getRoot(instance) + Constants.ZTABLES;
        byte[] nid = zoo.mutate(ntp, ZERO_BYTE, ZooUtil.PUBLIC, new Mutator() {
            @Override
            public byte[] mutate(byte[] currentValue) throws Exception {
                BigInteger nextId = new BigInteger(new String(currentValue, Constants.UTF8),
                        Character.MAX_RADIX);
                nextId = nextId.add(BigInteger.ONE);
                return nextId.toString(Character.MAX_RADIX).getBytes(Constants.UTF8);
            }
        });
        return new String(nid, Constants.UTF8);
    } catch (Exception e1) {
        Logger.getLogger(CreateTable.class).error("Failed to assign tableId to " + tableName, e1);
        throw new ThriftTableOperationException(tableId, tableName, TableOperation.CREATE,
                TableOperationExceptionType.OTHER, e1.getMessage());
    }
}

From source file:db.PGKeys.java

public static synchronized String randomKey() {
    if (currentKey >= nextPack) {
        currentPack = DBContext.Redis().incrBy(INC, PACK_SIZE);
        nextPack = currentPack + PACK_SIZE;
        currentKey = currentPack;/*w w w  .  j  av a  2  s  .com*/
    }
    return DB_VER_PREFIX + Long.toString(currentKey++, Character.MAX_RADIX);
}

From source file:mitm.common.util.MiscArrayUtils.java

/**
 * Encodes the byte array to a String consisting of all readable characters.
 *///from  w w  w  . ja  v a 2s  .  co  m
public static String toMaxRadix(byte[] bytes) {
    Check.notNull(bytes, "bytes");

    /*
     * We need to make sure that the BigInteger will be positive and that any starting zero (0) bytes
     * are not removed.
     */
    byte[] pos = ArrayUtils.addAll(new byte[] { 1 }, bytes);

    BigInteger bigInt = new BigInteger(pos);

    return bigInt.toString(Character.MAX_RADIX);
}

From source file:de.knowwe.core.kdom.rendering.RenderResult.java

private static String createMaskKey(HttpServletRequest request) {
    Object storedMaskKey = request.getAttribute(storeKey);
    if (storedMaskKey != null)
        return (String) storedMaskKey;

    int rnd = Math.abs(new Random().nextInt());
    String maskKey = Integer.toString(rnd, Character.MAX_RADIX);
    request.setAttribute(storeKey, maskKey);
    return maskKey;
}

From source file:com.github.rnewson.couchdb.lucene.couchdb.View.java

public String getDigest() {
    try {//w  w  w .j a v  a 2 s.c o  m
        final MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(toBytes(json.optString("analyzer")));
        md.update(toBytes(json.optString("defaults")));
        md.update(toBytes(json.optString("index")));
        return new BigInteger(1, md.digest()).toString(Character.MAX_RADIX);
    } catch (final NoSuchAlgorithmException e) {
        throw new Error("MD5 support missing.");
    }
}

From source file:mitm.common.util.MiscArrayUtils.java

/**
 * Converts the input string which is encoded in MAX_RADIX to a byte array (this function 
 * is the complement of ArrayUtils#toMaxRadix) 
 *///from   w  w  w  . java2  s .  c  o  m
public static byte[] fromMaxRadix(String inputMaxRadix) {
    Check.notNull(inputMaxRadix, "inputMaxRadix");

    BigInteger bigInt = new BigInteger(inputMaxRadix, Character.MAX_RADIX);

    byte[] bytes = bigInt.toByteArray();

    /*
     * We need to remove the first byte added by toMaxRadix.
     */
    return ArrayUtils.subarray(bytes, 1, bytes.length);
}

From source file:org.apache.hadoop.hive.ql.udf.UDFConv.java

public Text evaluate(Text n, IntWritable fromBase, IntWritable toBase) {
    if (n == null || n.toString().equalsIgnoreCase("") || fromBase == null || toBase == null) {
        return null;
    }/*from  w w  w  .j  a  v a 2s.  c o m*/

    int fromBs = fromBase.get();
    int toBs = toBase.get();
    if (fromBs < Character.MIN_RADIX || fromBs > Character.MAX_RADIX || Math.abs(toBs) < Character.MIN_RADIX
            || Math.abs(toBs) > Character.MAX_RADIX) {
        return null;
    }

    byte[] num = n.getBytes();
    boolean negative = (num[0] == '-');
    int first = 0;
    if (negative) {
        first = 1;
    }
    Arrays.fill(value, (byte) 0);

    for (int i = 1; i <= n.getLength() - first; i++) {
        value[value.length - i] = num[n.getLength() - i];
    }
    char2byte(fromBs, value.length - n.getLength() + first);

    long val = encode(fromBs);
    if (negative && toBs > 0) {
        if (val < 0) {
            val = -1;
        } else {
            val = -val;
        }
    }
    if (toBs < 0 && val < 0) {
        val = -val;
        negative = true;
    }
    decode(val, Math.abs(toBs));

    for (first = 0; first < value.length - 1 && value[first] == 0; first++)
        ;

    byte2char(Math.abs(toBs), first);

    if (negative && toBs < 0) {
        value[--first] = '-';
    }

    result.set(value, first, value.length - first);
    return result;
}

From source file:$.DeviceTypeServiceImpl.java

private static String shortUUID() {
        UUID uuid = UUID.randomUUID();
        long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong();
        return Long.toString(l, Character.MAX_RADIX);
    }//from w  w w .java2s . c om

From source file:org.apache.lucene.index.LuceneSegmentsMerger.java

private final synchronized String newSegmentName() {
    return "_" + Integer.toString(segmentInfos.counter++, Character.MAX_RADIX);
}