public class BufferUtils extends Object
ByteBuffer 工具类| Constructor and Description |
|---|
BufferUtils() |
| Modifier and Type | Method and Description |
|---|---|
static ByteBuffer |
copy(ByteBuffer src,
ByteBuffer dest)
拷贝ByteBuffer
|
static ByteBuffer |
copy(ByteBuffer src,
ByteBuffer dest,
int length)
拷贝ByteBuffer
|
static ByteBuffer |
copy(ByteBuffer src,
int srcStart,
ByteBuffer dest,
int destStart,
int length)
拷贝ByteBuffer
|
static ByteBuffer |
copy(ByteBuffer src,
int start,
int end)
拷贝到一个新的ByteBuffer
|
static int |
lineEnd(ByteBuffer buffer)
一行的末尾位置,查找位置时位移ByteBuffer到结束位置
|
static int |
lineEnd(ByteBuffer buffer,
int maxLength)
一行的末尾位置,查找位置时位移ByteBuffer到结束位置
支持的换行符如下: |
static byte[] |
readBytes(ByteBuffer buffer)
读取剩余部分bytes
|
static byte[] |
readBytes(ByteBuffer buffer,
int maxLength)
读取指定长度的bytes
如果长度不足,则读取剩余部分,此时buffer必须为读模式 |
static byte[] |
readBytes(ByteBuffer buffer,
int start,
int end)
读取指定区间的数据
|
static String |
readLine(ByteBuffer buffer,
Charset charset)
读取一行,如果buffer中最后一部分并非完整一行,则返回null
支持的换行符如下: |
public static ByteBuffer copy(ByteBuffer src, int start, int end)
src - 源ByteBufferstart - 起始位置(包括)end - 结束位置(不包括)public static ByteBuffer copy(ByteBuffer src, ByteBuffer dest)
src - 源ByteBufferdest - 目标ByteBufferpublic static ByteBuffer copy(ByteBuffer src, ByteBuffer dest, int length)
src - 源ByteBufferdest - 目标ByteBufferlength - 长度public static ByteBuffer copy(ByteBuffer src, int srcStart, ByteBuffer dest, int destStart, int length)
src - 源ByteBuffersrcStart - 源开始的位置dest - 目标ByteBufferdestStart - 目标开始的位置length - 长度public static byte[] readBytes(ByteBuffer buffer)
buffer - ByteBufferpublic static byte[] readBytes(ByteBuffer buffer, int maxLength)
buffer - ByteBuffermaxLength - 最大长度public static byte[] readBytes(ByteBuffer buffer, int start, int end)
buffer - ByteBufferstart - 开始位置end - 结束位置public static int lineEnd(ByteBuffer buffer)
buffer - ByteBufferpublic static int lineEnd(ByteBuffer buffer, int maxLength)
1. \r\n 2. \n
buffer - ByteBuffermaxLength - 读取最大长度public static String readLine(ByteBuffer buffer, Charset charset)
1. \r\n 2. \n
buffer - ByteBuffercharset - 编码Copyright © 2019. All rights reserved.