/** * Thread safe equals method for StaticBuffer - ByteBuffer equality comparison * * @param b1 * @param b2 * @return */ public static boolean equals(StaticBuffer b1, ByteBuffer b2) { if (b1.length()!=b2.remaining()) return false; int p2 = b2.position(); for (int i=0;i<b1.length();i++) { if (b1.getByte(i)!=b2.get(p2+i)) return false; } return true; }
public static WriteBuffer put(WriteBuffer out, StaticBuffer in) { for (int i=0;i<in.length();i++) out.putByte(in.getByte(i)); return out; }
public Future<Message> add(StaticBuffer content, StaticBuffer key, ExternalPersistor persistor) { Preconditions.checkArgument(key!=null && key.length()>0,"Invalid key provided: %s",key); int partitionId = 0; //Get first 4 byte if exist in key... for (int i=0;i<4;i++) { int b; if (key.length()>i) b = key.getByte(i) & 0xFF; else b = 0; partitionId = (partitionId<<8) + b; } assert manager.partitionBitWidth>=0 && manager.partitionBitWidth<=32; //and then extract the number of partitions bits if (manager.partitionBitWidth==0) partitionId=0; else partitionId = partitionId>>>(32-manager.partitionBitWidth); return add(content, partitionId, persistor); }
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); }
private static StaticBuffer nextBiggerBuffer(StaticBuffer buffer, boolean allowOverflow) { int len = buffer.length(); byte[] next = new byte[len]; boolean carry = true; for (int i = len - 1; i >= 0; i--) { byte b = buffer.getByte(i); if (carry) { b++; if (b != 0) carry = false; } next[i]=b; } if (carry && allowOverflow) { return zeroBuffer(len); } else if (carry) { throw new IllegalArgumentException("Buffer overflow incrementing " + buffer); } else { return StaticArrayBuffer.of(next); } }
private StaticBuffer concatenate(StaticBuffer front, StaticBuffer end, final boolean appendLength) { final boolean addKeyLength = !hasFixedKeyLength() && appendLength; int length = getLength(front); byte[] result = new byte[length + end.length() + (addKeyLength ? variableKeyLengthSize : 0)]; int position = 0; for (int i = 0; i < front.length(); i++) result[position++] = front.getByte(i); for (int i = 0; i < end.length(); i++) result[position++] = end.getByte(i); if (addKeyLength) { result[position++] = (byte) (length >>> 8); result[position] = (byte) length; } return StaticArrayBuffer.of(result); }
StaticBuffer start = local.getAt(0); for (int i=4;i<start.length() && !truncatedBits;i++) { if (start.getByte(i)!=0) truncatedBits=true;