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 static StaticArrayBuffer of(byte[] array) { return new StaticArrayBuffer(array); }
@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 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); } }
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); }
public static StaticBuffer padBuffer(StaticBuffer b, int length) { if (b.length()>=length) return b; byte[] data = new byte[length]; //implicitly initialized to all 0s for (int i = 0; i < b.length(); i++) { data[i]=b.getByte(i); } return new StaticArrayBuffer(data); }
byte keyBuf[] = new byte[keyLength]; rand.nextBytes(keyBuf); key = new StaticArrayBuffer(keyBuf); col = new StaticArrayBuffer(colBuf);
public TimestampRid fromLockColumn(StaticBuffer lockKey, TimestampProvider provider) { ReadBuffer r = lockKey.asReadBuffer(); int len = r.length(); long tsNS = r.getLong(); len -= 8; byte[] curRid = new byte[len]; for (int i = 0; r.hasRemaining(); i++) { curRid[i] = r.getByte(); } StaticBuffer rid = new StaticArrayBuffer(curRid); Instant time = provider.getTime(tsNS); return new TimestampRid(time, rid); } }
public Builder fromConfig(Configuration config) { rid(new StaticArrayBuffer(config.get(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID) .getBytes(UTF8_CHARSET))); final String llmPrefix = config.get(GraphDatabaseConfiguration.LOCK_LOCAL_MEDIATOR_GROUP); times(config.get(GraphDatabaseConfiguration.TIMESTAMP_PROVIDER)); mediator(LocalLockMediators.INSTANCE.get(llmPrefix, times)); lockRetryCount(config.get(GraphDatabaseConfiguration.LOCK_RETRY)); lockWait(config.get(GraphDatabaseConfiguration.LOCK_WAIT)); lockExpire(config.get(GraphDatabaseConfiguration.LOCK_EXPIRE)); if (config.get(GraphDatabaseConfiguration.LOCK_CLEAN_EXPIRED)) { standardCleaner(); } return this; }
public static StaticBuffer decodeKey(final String name) { try { return new StaticArrayBuffer(Hex.decodeHex(name.toCharArray())); } catch (DecoderException e) { throw new RuntimeException(e); } } }
@Override public Entry next() { final Map.Entry<byte[], NavigableMap<Long, byte[]>> entry = iterator.next(); byte[] col = entry.getKey(); byte[] val = entry.getValue().lastEntry().getValue(); return StaticArrayEntry.of(new StaticArrayBuffer(col), new StaticArrayBuffer(val)); }
@Override public Entry next() { final Map.Entry<byte[], NavigableMap<Long, byte[]>> entry = iterator.next(); byte[] col = entry.getKey(); byte[] val = entry.getValue().lastEntry().getValue(); return StaticArrayEntry.of(new StaticArrayBuffer(col), new StaticArrayBuffer(val)); }