public static StaticBuffer fillBuffer(int len, byte value) { byte[] res = new byte[len]; for (int i = 0; i < len; i++) res[i]=value; return StaticArrayBuffer.of(res); }
private static StaticBuffer getPrefixed(int prefix) { assert prefix < (1 << PREFIX_BIT_LEN) && prefix >= 0; byte[] arr = new byte[1]; arr[0] = (byte) (prefix << (Byte.SIZE - PREFIX_BIT_LEN)); return new StaticArrayBuffer(arr); }
public byte[] getBytes(int length) { byte[] result = super.getBytes(position,length); position += length*BYTE_LEN; return result; }
public static StaticArrayBuffer of(ByteBuffer b) { if (b.hasArray()) { return new StaticArrayBuffer(b.array(),b.arrayOffset()+b.position(),b.arrayOffset()+b.limit()); } else { byte[] array = new byte[b.remaining()]; b.mark(); b.get(array); b.reset(); return StaticArrayBuffer.of(array); } }
row = previousRow; StaticArrayBuffer key = StaticArrayBuffer.of(row.getBytesUnsafe(KEY)); StaticBuffer column1 = StaticArrayBuffer.of(row.getBytesUnsafe(COLUMN_NAME)); StaticBuffer value = StaticArrayBuffer.of(row.getBytesUnsafe(VALUE)); Map<StaticBuffer, StaticBuffer> cvs = new HashMap<>(); cvs.put(column1, value); while (rowIterator.hasNext()) { Row nextRow = rowIterator.next(); StaticArrayBuffer nextKey = StaticArrayBuffer.of(nextRow.getBytesUnsafe(KEY)); if (! key.equals(nextKey)) { previousRow = nextRow; break; StaticBuffer nextColumn = StaticArrayBuffer.of(nextRow.getBytesUnsafe(COLUMN_NAME)); StaticBuffer nextValue = StaticArrayBuffer.of(nextRow.getBytesUnsafe(VALUE)); cvs.put(nextColumn, nextValue); totalRead++;
/** * Companion to {@link #getStartKey(int)}. See its javadoc for details. */ private byte[] getEndKey(int regionCount) { ByteBuffer regionWidth = ByteBuffer.allocate(4); regionWidth.putInt((int)(((1L << 32) - 1L) / regionCount * (regionCount - 1))).flip(); return StaticArrayBuffer.of(regionWidth).getBytes(0, 4); }
@Override public ByteBuffer asByteBuffer() { return as(StaticBuffer.BB_FACTORY); }
row = previousRow; StaticArrayBuffer key = StaticArrayBuffer.of(row.getBytesUnsafe(KEY)); StaticBuffer column1 = StaticArrayBuffer.of(row.getBytesUnsafe(COLUMN_NAME)); StaticBuffer value = StaticArrayBuffer.of(row.getBytesUnsafe(VALUE)); Map<StaticBuffer, StaticBuffer> cvs = new HashMap<>(); cvs.put(column1, value); while (rowIterator.hasNext()) { Row nextRow = rowIterator.next(); StaticArrayBuffer nextKey = StaticArrayBuffer.of(nextRow.getBytesUnsafe(KEY)); if (! key.equals(nextKey)) { previousRow = nextRow; break; StaticBuffer nextColumn = StaticArrayBuffer.of(nextRow.getBytesUnsafe(COLUMN_NAME)); StaticBuffer nextValue = StaticArrayBuffer.of(nextRow.getBytesUnsafe(VALUE)); cvs.put(nextColumn, nextValue); totalRead++;
/** * <p/> * From the {@code createTable} javadoc: * "The start key specified will become the end key of the first region of * the table, and the end key specified will become the start key of the * last region of the table (the first region has a null start key and * the last region has a null end key)" * <p/> * To summarize, the {@code createTable} argument called "startKey" is * actually the end key of the first region. */ private byte[] getStartKey(int regionCount) { ByteBuffer regionWidth = ByteBuffer.allocate(4); regionWidth.putInt((int)(((1L << 32) - 1L) / regionCount)).flip(); return StaticArrayBuffer.of(regionWidth).getBytes(0, 4); }
@Override public <T> T getColumnAs(Factory<T> factory) { return super.as(factory,0,valuePosition); }
public static StaticBuffer stringToByteBuffer(String s) { byte[] b; try { b = s.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } ByteBuffer bb = ByteBuffer.allocate(b.length); bb.put(b); bb.flip(); return StaticArrayBuffer.of(bb); }
row = previousRow; StaticArrayBuffer key = StaticArrayBuffer.of(row.getBytesUnsafe(KEY)); StaticBuffer column1 = StaticArrayBuffer.of(row.getBytesUnsafe(COLUMN_NAME)); StaticBuffer value = StaticArrayBuffer.of(row.getBytesUnsafe(VALUE)); Map<StaticBuffer, StaticBuffer> cvs = new HashMap<>(); cvs.put(column1, value); while (rowIterator.hasNext()) { Row nextRow = rowIterator.next(); StaticArrayBuffer nextKey = StaticArrayBuffer.of(nextRow.getBytesUnsafe(KEY)); if (!key.equals(nextKey)) { previousRow = nextRow; break; StaticBuffer nextColumn = StaticArrayBuffer.of(nextRow.getBytesUnsafe(COLUMN_NAME)); StaticBuffer nextValue = StaticArrayBuffer.of(nextRow.getBytesUnsafe(VALUE)); cvs.put(nextColumn, nextValue); totalRead++;
public static StaticArrayBuffer of(byte[] array) { return new StaticArrayBuffer(array); }
private StaticBuffer string2StaticBuffer(final String s) { ByteBuffer out = ByteBuffer.wrap(s.getBytes(Charset.forName("UTF-8"))); return StaticArrayBuffer.of(out); }
incompleteKV = null; } else { StaticArrayBuffer key = StaticArrayBuffer.of(reader.getCurrentKey()); SortedMap<ByteBuffer, Cell> valueSortedMap = reader.getCurrentValue(); List<Entry> entries = new ArrayList<>(valueSortedMap.size()); ByteBuffer col = ent.getKey(); ByteBuffer val = ent.getValue().value(); entries.add(StaticArrayEntry.of(StaticArrayBuffer.of(col), StaticArrayBuffer.of(val))); } else if (!incompleteKV.key.equals(key)) {
@Override public StaticBuffer subrange(int position, int length, boolean invert) { if (position<0 || length<0 || (offset + position + length)>limit) throw new ArrayIndexOutOfBoundsException("Position ["+position+"] and or length ["+length+"] out of bounds"); if (!invert) { return new StaticArrayBuffer(array, offset + position, offset + position + length); } else { byte[] inverted = new byte[length]; System.arraycopy(array,offset+position,inverted,0,length); for (int i = 0; i < inverted.length; i++) { inverted[i]=(byte)~inverted[i]; } return new StaticArrayBuffer(inverted); } }
public static StaticBuffer getLongBuffer(long id) { ByteBuffer buffer = ByteBuffer.allocate(longSize); buffer.putLong(id); byte[] arr = buffer.array(); Preconditions.checkArgument(arr.length == longSize); return StaticArrayBuffer.of(arr); }
incompleteKV = null; } else { StaticArrayBuffer key = StaticArrayBuffer.of(reader.getCurrentKey()); SortedMap<ByteBuffer, Cell> valueSortedMap = reader.getCurrentValue(); List<Entry> entries = new ArrayList<>(valueSortedMap.size()); ByteBuffer col = ent.getKey(); ByteBuffer val = ent.getValue().value(); entries.add(StaticArrayEntry.of(StaticArrayBuffer.of(col), StaticArrayBuffer.of(val))); } else if (!incompleteKV.key.equals(key)) {
public static StaticBuffer readBuffer(ScanBuffer in) { long length = VariableLong.readPositive(in); Preconditions.checkArgument(length>=0 && length<=Integer.MAX_VALUE); byte[] data = in.getBytes((int)length); assert data.length==length; return new StaticArrayBuffer(data); }