List of usage examples for java.io Bits getShort
static short getShort(byte[] b, int off)
From source file:voldemort.store.cachestore.BlockUtil.java
public static Key toKey(byte[] data) { KeyType t = getType(data[0]);//from w ww. j a va 2 s .c o m int len; switch (t) { case INT: len = getLen(data[0]); return Key.createKey(readInt(data, len)); case LONG: len = getLen(data[0]); return Key.createKey(readLong(data, len)); case STRING: len = Bits.getShort(data, 1); String s; try { s = new String(data, 3, len, "UTF-8"); } catch (UnsupportedEncodingException ex) { throw new StoreException(ex.getMessage(), ex); } return Key.createKey(s); case BARRAY: byte[] b = new byte[data.length - 1]; System.arraycopy(data, 1, b, 0, b.length); return Key.createKey(new ByteArray(b)); case BYTEARY: byte[] bs = new byte[data.length - 1]; System.arraycopy(data, 1, bs, 0, bs.length); return Key.createKey(bs); default: return Key.createKey(toJObject(data, 1, data.length - 1)); } }