Java ReadableByteChannel Read copyChannels(ReadableByteChannel in, WritableByteChannel out)

Here you can find the source of copyChannels(ReadableByteChannel in, WritableByteChannel out)

Description

copy Channels

License

Apache License

Declaration

public static void copyChannels(ReadableByteChannel in, WritableByteChannel out) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;

import java.nio.ByteBuffer;

import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;

public class Main {
    public static void copyChannels(ReadableByteChannel in, WritableByteChannel out) throws IOException {
        ByteBuffer buf = ByteBuffer.allocate(16 * 1024);

        while (in.read(buf) != -1) {
            buf.flip();//w  ww . jav a2  s  .  c  o m
            out.write(buf);
            buf.compact();
        }
        buf.flip();
        while (buf.hasRemaining()) {
            out.write(buf);
        }
    }
}

Related

  1. copyChannels(ReadableByteChannel input, WritableByteChannel output, int bufferSize)
  2. fill(ReadableByteChannel in, ByteBuffer buffer)
  3. getNextVIntAsLong(ByteBuffer buffer, ReadableByteChannel readChannel)
  4. infiniteReadableByteChannelFor(ByteBuffer... buffers)