Package org.johnnei.javatorrent.network
Class ByteBufferUtils
- java.lang.Object
-
- org.johnnei.javatorrent.network.ByteBufferUtils
-
public final class ByteBufferUtils extends Object
Helper methods which reduce boiler-plate code forByteBuffer
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]getBytes(ByteBuffer buffer, int length)Gets the nextlengthbytes as a byte array.static StringgetString(ByteBuffer buffer, int length)Gets a UTF-8 string of the given length in bytes.static voidputString(ByteBuffer buffer, String s)Puts the given string as UTF-8 into the buffer.
-
-
-
Method Detail
-
putString
public static void putString(ByteBuffer buffer, String s)
Puts the given string as UTF-8 into the buffer.- Parameters:
buffer- The buffer to append the string to.s- The string to put.
-
getString
public static String getString(ByteBuffer buffer, int length)
Gets a UTF-8 string of the given length in bytes.- Parameters:
buffer- The buffer to get from.length- The amount of bytes to consume.- Returns:
- The read string.
-
getBytes
public static byte[] getBytes(ByteBuffer buffer, int length)
Gets the nextlengthbytes as a byte array.- Parameters:
buffer- The buffer to get from.length- The amount of bytes to consume.- Returns:
- The read byte array.
-
-