public class BufferUtil extends Object
ByteBuffer
工具类Constructor and Description |
---|
BufferUtil() |
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 ByteBuffer |
create(byte[] data)
创建新Buffer
|
static ByteBuffer |
create(CharSequence data,
Charset charset)
从字符串创建新Buffer
|
static CharBuffer |
createCharBuffer(int capacity)
|
static ByteBuffer |
createUtf8(CharSequence data)
从字符串创建新Buffer,使用UTF-8编码
|
static int |
lineEnd(ByteBuffer buffer)
一行的末尾位置,查找位置时位移ByteBuffer到结束位置
|
static int |
lineEnd(ByteBuffer buffer,
int maxLength)
一行的末尾位置,查找位置时位移ByteBuffer到结束位置
支持的换行符如下: 1. |
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
支持的换行符如下: 1. |
static String |
readStr(ByteBuffer buffer,
Charset charset)
读取剩余部分并转为字符串
|
static String |
readUtf8Str(ByteBuffer buffer)
读取剩余部分并转为UTF-8编码字符串
|
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 String readUtf8Str(ByteBuffer buffer)
buffer
- ByteBufferpublic static String readStr(ByteBuffer buffer, Charset charset)
buffer
- ByteBuffercharset
- 编码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
- ByteBuffer
start
- 开始位置end
- 结束位置public static int lineEnd(ByteBuffer buffer)
buffer
- ByteBuffer
public static int lineEnd(ByteBuffer buffer, int maxLength)
1. \r\n 2. \n
buffer
- ByteBuffer
maxLength
- 读取最大长度public static String readLine(ByteBuffer buffer, Charset charset)
1. \r\n 2. \n
buffer
- ByteBuffercharset
- 编码public static ByteBuffer create(byte[] data)
data
- 数据ByteBuffer
public static ByteBuffer create(CharSequence data, Charset charset)
data
- 数据charset
- 编码ByteBuffer
public static ByteBuffer createUtf8(CharSequence data)
data
- 数据ByteBuffer
public static CharBuffer createCharBuffer(int capacity)
capacity
- 容量CharBuffer
Copyright © 2024. All rights reserved.