List of utility methods to do ByteBuffer Set
void | arrayCopy(ByteBuffer buffer, int position, byte[] bytes, int offset, int length) array Copy if (buffer.hasArray()) System.arraycopy(buffer.array(), buffer.arrayOffset() + position, bytes, offset, length); else ((ByteBuffer) buffer.duplicate().position(position)).get(bytes, offset, length); |
Collection | base64FormatOfBinarySet(Collection Returns a base-64 string of the given bytes List<String> base64Strings = new LinkedList<String>(); for (ByteBuffer b : bs) { base64Strings.add(base64Format(b)); return base64Strings; |
boolean | blockCopy(ByteBuffer source, int srcOffset, byte[] dest, int destOffset, int count) block Copy if ((source == null) || (dest == null)) return false; if ((srcOffset < 0) || (destOffset < 0) || (count <= 0)) return false; if ((source.limit() - srcOffset) < count) return false; if ((dest.length - destOffset) < count) return false; ... |
String | byteBuffersToString(ByteBuffer[] bufs, Charset cs) byte Buffers To String CharsetDecoder cd = cs.newDecoder(); int len = 0; for (ByteBuffer buf : bufs) { len += buf.remaining(); int en = (int) (len * (double) cd.maxCharsPerByte()); char[] ca = new char[en]; cd.reset(); ... |
int | byteIndexOf(ByteBuffer buffer, byte[] temp, int offset) byte Index Of int i; if (temp.length == 0) { return 0; int end = buffer.limit() - temp.length; if (end < 0) { return -1; int start = buffer.position() + offset; if (start > end) { return -1; if (start < 0) { start = 0; byte[] b = buffer.array(); Search: for (i = start; i < end; i++) { if (b[i] != temp[0]) { continue; int k = 1; while (k < temp.length) { if (b[k + i] != temp[k]) { continue Search; k++; return i; return -1; |
ByteBuffer | c_memset(ByteBuffer b, int c_, int size) memset byte c = (byte) c_; ByteBuffer b2 = b.duplicate(); while (size-- != 0) { b2.put(c); return b; |
ByteBuffer | charSequence2ByteBuffer(CharSequence cs, Charset charset) char Sequence Byte Buffer return charset.encode(CharBuffer.wrap(cs));
|
int | charstoUTF8Bytes(char[] srcBuf, int srcOffset, int srcLength, ByteBuffer dest, int destOffset) Custom UTF-8 encoding. int destMark = destOffset; for (int i = srcOffset; i < srcLength;) { char ch = srcBuf[i]; if (ch < 0x0080) { dest.put(destOffset++, (byte) ch); } else if (ch < 0x0800) { dest.put(destOffset++, (byte) (0xc0 | (ch >> 6))); dest.put(destOffset++, (byte) (0x80 | ((ch >> 0) & 0x3f))); ... |
boolean | equals(final ByteBuffer keyValue, final int offset, final int keyLen, final byte[] otherKey) Equals. for (int i = offset; i < offset + keyLen; i++) { if (keyValue.get(i) != otherKey[i - offset]) return false; return true; |
int | find(ByteBuffer buffer, int offset, byte searchKey) find for (int i = buffer.position() + offset; i < buffer.limit(); i++) { byte nextByte = buffer.get(i); if (nextByte == searchKey) { return i; return -1; |