/** * Return the substring from {@code beginIndex}, inclusive, to the end of the * string. * * @param beginIndex start at this index * @return substring sharing underlying data * @throws IndexOutOfBoundsException if {@code beginIndex < 0} or * {@code beginIndex > size()}. */ public final ByteString substring(int beginIndex) { return substring(beginIndex, size()); }
/** * Return the substring from {@code beginIndex}, inclusive, to the end of the * string. * * @param beginIndex start at this index * @return substring sharing underlying data * @throws IndexOutOfBoundsException if {@code beginIndex < 0} or * {@code beginIndex > size()}. */ public ByteString substring(int beginIndex) { return substring(beginIndex, size()); }
@Override boolean equalsRange(ByteString other, int offset, int length) { return substring(0, length).equals(other.substring(offset, offset + length)); }
/** * Tests if this bytestring starts with the specified prefix. * Similar to {@link String#startsWith(String)} * * @param prefix the prefix. * @return <code>true</code> if the byte sequence represented by the * argument is a prefix of the byte sequence represented by * this string; <code>false</code> otherwise. */ public boolean startsWith(ByteString prefix) { return size() >= prefix.size() && substring(0, prefix.size()).equals(prefix); }
/** * Tests if this bytestring starts with the specified prefix. * Similar to {@link String#startsWith(String)} * * @param prefix the prefix. * @return <code>true</code> if the byte sequence represented by the * argument is a prefix of the byte sequence represented by * this string; <code>false</code> otherwise. */ public final boolean startsWith(ByteString prefix) { return size() >= prefix.size() && substring(0, prefix.size()).equals(prefix); }
/** * Tests if this bytestring ends with the specified suffix. * Similar to {@link String#endsWith(String)} * * @param suffix the suffix. * @return <code>true</code> if the byte sequence represented by the * argument is a suffix of the byte sequence represented by * this string; <code>false</code> otherwise. */ public final boolean endsWith(ByteString suffix) { return size() >= suffix.size() && substring(size() - suffix.size()).equals(suffix); }
return other.substring(offset, offset + length).equals(substring(0, length));
/** * Generates a payload of desired type and size. Reads compressableBuffer or * uncompressableBuffer as a circular buffer. */ private ByteString generatePayload(ByteString dataBuffer, int offset, int size) { ByteString payload = ByteString.EMPTY; // This offset would never pass the array boundary. int begin = offset; int end = 0; int bytesLeft = size; while (bytesLeft > 0) { end = Math.min(begin + bytesLeft, dataBuffer.size()); // ByteString.substring returns the substring from begin, inclusive, to end, exclusive. payload = payload.concat(dataBuffer.substring(begin, end)); bytesLeft -= (end - begin); begin = end % dataBuffer.size(); } return payload; }
public static ByteStringRange prefix(ByteString prefix) { if (prefix.isEmpty()) { return unbounded(); } int offset = prefix.size() - 1; int curByte = 0xFF; while (offset >= 0) { curByte = prefix.byteAt(offset) & 0xFF; if (curByte != 0xFF) { break; } offset--; } if (offset < 0) { // We got an 0xFFFF... (only FFs) stopRow value which is // the last possible prefix before the end of the table. // So set it to stop at the 'end of the table' return unbounded().startClosed(prefix); } ByteString endPrefix = offset == 0 ? ByteString.EMPTY : prefix.substring(0, offset); ByteString endSuffix = UnsafeByteOperations.unsafeWrap(new byte[] {(byte) (curByte + 1)}); ByteString end = endPrefix.concat(endSuffix); ByteStringRange range = ByteStringRange.unbounded().startClosed(prefix); if (!end.isEmpty()) { range.endOpen(end); } return range; }
/** * List of ByteStrings that encode this block report * * @return ByteStrings */ public List<ByteString> getBlocksBuffers() { final ByteString blocksBuf = getBlocksBuffer(); final List<ByteString> buffers; final int size = blocksBuf.size(); if (size <= CHUNK_SIZE) { buffers = Collections.singletonList(blocksBuf); } else { buffers = new ArrayList<ByteString>(); for (int pos=0; pos < size; pos += CHUNK_SIZE) { // this doesn't actually copy the data buffers.add(blocksBuf.substring(pos, Math.min(pos+CHUNK_SIZE, size))); } } return buffers; }
/** * Return the substring from {@code beginIndex}, inclusive, to the end of the * string. * * @param beginIndex start at this index * @return substring sharing underlying data * @throws IndexOutOfBoundsException if {@code beginIndex < 0} or * {@code beginIndex > size()}. */ public final ByteString substring(int beginIndex) { return substring(beginIndex, size()); }
/** * Return the substring from {@code beginIndex}, inclusive, to the end of the * string. * * @param beginIndex start at this index * @return substring sharing underlying data * @throws IndexOutOfBoundsException if {@code beginIndex < 0} or * {@code beginIndex > size()}. */ public final ByteString substring(int beginIndex) { return substring(beginIndex, size()); }
@Override boolean equalsRange(ByteString other, int offset, int length) { return substring(0, length).equals(other.substring(offset, offset + length)); }
/** * Return the substring from {@code beginIndex}, inclusive, to the end of the * string. * * @param beginIndex start at this index * @return substring sharing underlying data * @throws IndexOutOfBoundsException if {@code beginIndex < 0} or * {@code beginIndex > size()}. */ public ByteString substring(int beginIndex) { return substring(beginIndex, size()); }
public static String getBase64FromByteString(ByteString sign) { byte[] r = sign.substring(0, 32).toByteArray(); byte[] s = sign.substring(32, 64).toByteArray(); byte v = sign.byteAt(64); if (v < 27) { v += 27; //revId -> v } ECDSASignature signature = ECDSASignature.fromComponents(r, s, v); return signature.toBase64(); }
/** * Tests if this bytestring starts with the specified prefix. * Similar to {@link String#startsWith(String)} * * @param prefix the prefix. * @return <code>true</code> if the byte sequence represented by the * argument is a prefix of the byte sequence represented by * this string; <code>false</code> otherwise. */ public final boolean startsWith(ByteString prefix) { return size() >= prefix.size() && substring(0, prefix.size()).equals(prefix); }
/** * Tests if this bytestring ends with the specified suffix. * Similar to {@link String#endsWith(String)} * * @param suffix the suffix. * @return <code>true</code> if the byte sequence represented by the * argument is a suffix of the byte sequence represented by * this string; <code>false</code> otherwise. */ public final boolean endsWith(ByteString suffix) { return size() >= suffix.size() && substring(size() - suffix.size()).equals(suffix); }
ByteString checksum(byte[] data) { byte[] hash = new byte[digest.getDigestSize()]; byte[] hashHash = new byte[digest.getDigestSize()]; digest.reset(); digest.update(data, 0, data.length); digest.doFinal(hash, 0); digest.update(hash, 0, hash.length); digest.doFinal(hashHash, 0); return ByteString.copyFrom(hashHash).substring(0, 20); } }