mirror of
https://gitee.com/dromara/hutool.git
synced 2025-07-15 23:13:33 +08:00
fix code
This commit is contained in:
parent
aba953cfd2
commit
ff382aff85
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.core.io.buffer;
|
package org.dromara.hutool.core.io.buffer;
|
||||||
|
|
||||||
|
import org.dromara.hutool.core.io.IORuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代码移植自<a href="https://github.com/biezhi/blade">blade</a><br>
|
* 代码移植自<a href="https://github.com/biezhi/blade">blade</a><br>
|
||||||
* 快速缓冲,将数据存放在缓冲集中,取代以往的单一数组
|
* 快速缓冲,将数据存放在缓冲集中,取代以往的单一数组
|
||||||
@ -264,6 +266,23 @@ public class FastByteBuffer {
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回快速缓冲中的数据,如果缓冲区中的数据长度固定,则直接返回原始数组<br>
|
||||||
|
* 注意此方法共享数组,不能修改数组内容!
|
||||||
|
*
|
||||||
|
* @return 快速缓冲中的数据
|
||||||
|
*/
|
||||||
|
public byte[] toArrayZeroCopyIfPossible() {
|
||||||
|
if(1 == currentBufferIndex){
|
||||||
|
final int len = buffers[0].length;
|
||||||
|
if(len == size){
|
||||||
|
return buffers[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return toArray();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回快速缓冲中的数据
|
* 返回快速缓冲中的数据
|
||||||
*
|
*
|
||||||
|
@ -120,6 +120,16 @@ public class FastByteArrayOutputStream extends OutputStream {
|
|||||||
return buffer.toArray();
|
return buffer.toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转为Byte数组,如果缓冲区中的数据长度固定,则直接返回原始数组<br>
|
||||||
|
* 注意此方法共享数组,不能修改数组内容!
|
||||||
|
*
|
||||||
|
* @return Byte数组
|
||||||
|
*/
|
||||||
|
public byte[] toByteArrayZeroCopyIfPossible() {
|
||||||
|
return buffer.toArrayZeroCopyIfPossible();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return toString(CharsetUtil.defaultCharset());
|
return toString(CharsetUtil.defaultCharset());
|
||||||
|
@ -76,7 +76,7 @@ public class StreamReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//noinspection resource
|
//noinspection resource
|
||||||
return read(length).toByteArray();
|
return read(length).toByteArrayZeroCopyIfPossible();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user