-
JDK’s native ByteBuffer that after allocate can’t update capacity,
EasyByte
can create a dynamic ByteBuffer. -
Strings are something we need to add frequently but ByteBuffer only support byte array.
-
If you have a container like List,Map,must design a format policy,
EasyByte
can easy to use. -
Annoyed by the read and write mode of the native ByteBuffer. ByteBuffer created from
EasyByte
is read-write separated.
<dependency>
<groupId>io.github.gongxuanzhang</groupId>
<artifactId>easyByte-core</artifactId>
<version>0.0.1</version>
</dependency>
import org.gongxuanzhang.easybyte.core.DynamicByteBuffer;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class HowToUse {
public static void main(String[] args) {
DynamicByteBuffer allocate = DynamicByteBuffer.allocate();
allocate.appendString("hello world");
allocate.appendCollection(helloList());
allocate.appendMap(helloMap());
String helloWorld = allocate.getString();
List<String> list = allocate.getCollection(String.class);
Map<String, String> map = allocate.getMap(String.class, String.class);
System.out.println(helloWorld); // hello world
System.out.println(list); // [hello, world]
System.out.println(map); // {hello=world}
}
private static List<String> helloList() {
return Arrays.asList("hello", "world");
}
private static Map<String, String> helloMap() {
return Collections.singletonMap("hello", "world");
}
}