提交 66b6d0ec 编写于 作者: J jurgen

NIO

Former-commit-id: 5f5fb05d
上级 7637db4c
......@@ -20,6 +20,12 @@ package org.jkiss.utils;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
/**
* Some IO helper functions
......@@ -38,6 +44,32 @@ public final class IOUtils {
}
}
public static void fastCopy(final InputStream src, final OutputStream dest) throws IOException {
}
public static void fastCopy(final InputStream src, final OutputStream dest, int bufferSize) throws IOException {
final ReadableByteChannel inputChannel = Channels.newChannel(src);
final WritableByteChannel outputChannel = Channels.newChannel(dest);
fastCopy(inputChannel, outputChannel, DEFAULT_BUFFER_SIZE);
}
public static void fastCopy(final ReadableByteChannel src, final WritableByteChannel dest, int bufferSize) throws IOException {
final ByteBuffer buffer = ByteBuffer.allocateDirect(bufferSize);
while(src.read(buffer) != -1) {
buffer.flip();
dest.write(buffer);
buffer.compact();
}
buffer.flip();
while(buffer.hasRemaining()) {
dest.write(buffer);
}
}
public static void copyStream(
java.io.InputStream inputStream,
java.io.OutputStream outputStream)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册