Use cache streams to copy over byes, not the byte array
This commit is contained in:
parent
123b21f4ae
commit
7ff07ebaf1
|
@ -20,6 +20,8 @@
|
||||||
package org.elasticsearch.common.io;
|
package org.elasticsearch.common.io;
|
||||||
|
|
||||||
import org.elasticsearch.common.Preconditions;
|
import org.elasticsearch.common.Preconditions;
|
||||||
|
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||||
|
import org.elasticsearch.common.io.stream.CachedStreamOutput;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
|
@ -160,9 +162,14 @@ public abstract class Streams {
|
||||||
* @throws IOException in case of I/O errors
|
* @throws IOException in case of I/O errors
|
||||||
*/
|
*/
|
||||||
public static byte[] copyToByteArray(InputStream in) throws IOException {
|
public static byte[] copyToByteArray(InputStream in) throws IOException {
|
||||||
FastByteArrayOutputStream out = FastByteArrayOutputStream.Cached.cached();
|
CachedStreamOutput.Entry cachedEntry = CachedStreamOutput.popEntry();
|
||||||
|
try {
|
||||||
|
BytesStreamOutput out = cachedEntry.cachedBytes();
|
||||||
copy(in, out);
|
copy(in, out);
|
||||||
return out.copiedByteArray();
|
return out.copiedByteArray();
|
||||||
|
} finally {
|
||||||
|
CachedStreamOutput.pushEntry(cachedEntry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue