public static byte[] toByteArray(ByteBuffer buffer, int length) {if(buffer.hasArray() && buffer.arrayOffset() == 0) {return buffer.array();}checkByteSizeLimit(length);byte[] data = new byte[length];buffer.get(data);return data;}
public static byte[] ToByteArray(ByteBuffer buffer, int length){if (buffer.HasBuffer && buffer.Offset == 0){return buffer.Buffer;}byte[] data = new byte[length];buffer.Read(data);return data;}