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