Channels(java.nio.channels.Channels)是Java自带提供的Java NIO Channel读写的工具类。Channels提供了一些工具方法来完成Channel的读写操作。如:
向Channel写入ByteBuffer数据:
private static int write(WritableByteChannel ch, ByteBuffer bb) throws IOException |
通过InputStream流的方式从Channel读:
public static InputStream newInputStream(ReadableByteChannel ch) |
通过OutputStream流的方式向Channel写入:
public static OutputStream newOutputStream(final WritableByteChannel ch) |
通过Channel通道方式从InputStream流中读:
public static ReadableByteChannel newChannel(final InputStream in) |
通过Channel通道方式向OutputStream流中写入:
public static WritableByteChannel newChannel(final OutputStream out) |
通过Reader方式从Channel读:
public static Reader newReader(ReadableByteChannel ch, CharsetDecoder dec, int minBufferCap) |
public static Reader newReader(ReadableByteChannel ch, String csName) |
通过Writer方式向Channel写入:
public static Writer newWriter(final WritableByteChannel ch, final CharsetEncoder enc, final int minBufferCap) |
public static Writer newWriter(WritableByteChannel ch, String csName) |