List of utility methods to do ByteBuffer Write
void | writeSize(final int s, ByteBuffer buffer) write Size if (s == -1) buffer.put((byte) -1); else if (s < 254) buffer.put((byte) s); else buffer.put((byte) -2).putInt(s); |
void | writeSlice(ByteBuffer src, int number, ByteBuffer dst) write Slice ByteBuffer slice = src.slice(); slice.limit(number); dst.put(slice); |
void | writeString(ByteBuffer buf, String s) write String for (int i = 0; i < s.length(); i++) buf.put((byte) s.charAt(i)); |
void | writeString(ByteBuffer buf, String str) write String int len = str.length(); buf.putShort((short) len); for (int i = 0; i < len; i++) { buf.putChar(str.charAt(i)); |
void | writeString(ByteBuffer buf, String value) write String if (value.contains("\0")) { throw new IllegalArgumentException("Null characters are not allowed in null-terminated strings."); int len = value.length(); for (int i = 0; i < len; i++) { buf.put((byte) value.charAt(i)); buf.put((byte) 0); ... |
void | writeString(ByteBuffer buffer, String string) write String try { byte[] abyte = string.getBytes(StandardCharsets.UTF_8); if (abyte.length > 32767) { throw new IOException("String too big (was " + abyte.length + " bytes encoded, max " + 32767 + ")"); } else { writeVarInt(buffer, abyte.length); buffer.put(abyte, 0, abyte.length); } catch (UnsupportedEncodingException e) { throw new IOException(e); |
void | writeString(ByteBuffer byteBuffer, String str) write String if (str == null) { byteBuffer.putInt(0); } else { byte[] b = str.getBytes(); byteBuffer.putInt(b.length + 1); byteBuffer.put(b); byteBuffer.put((byte) 0); |
void | writeString(final String text, final ByteBuffer out) write String Objects.requireNonNull(text, "text can not be null!"); Objects.requireNonNull(out, "out can not be null!"); out.putShort((short) text.length()); out.put(text.getBytes(StandardCharsets.UTF_8)); |
void | writeString(String s, ByteBuffer buff) write String byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
writeVarInt(bytes.length, buff);
buff.put(bytes);
|
void | writeString(String string, ByteBuffer bb) write String bb.putShort((short) string.length());
bb.put(string.getBytes());
|