Java File Read via ByteBuffer ClientReadWithBlock(SocketChannel sc)

Here you can find the source of ClientReadWithBlock(SocketChannel sc)

Description

Client Read With Block

License

Open Source License

Declaration

public static ByteBuffer ClientReadWithBlock(SocketChannel sc) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class Main {
    public static ByteBuffer ClientReadWithBlock(SocketChannel sc) {
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        buffer.clear();/*from   w w w.  ja v  a  2s  .c o m*/
        try {
            while (sc.read(buffer) < 1)
                ;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return buffer;

    }
}

Related

  1. blockingRead(SocketChannel so, long timeout, int bytes)
  2. channelCopy(@Nonnull @WillNotClose final ReadableByteChannel aSrc, @Nonnull @WillNotClose final WritableByteChannel aDest)
  3. channelCopy2(ReadableByteChannel src, WritableByteChannel dest)
  4. ClientReadWithWait(SocketChannel sc)
  5. copy(final ReadableByteChannel src, final WritableByteChannel dest)
  6. copy(final ReadableByteChannel srcChannel, final WritableByteChannel destChannel)
  7. copyChannel(int bufferSize, ReadableByteChannel source, WritableByteChannel destination)