Code example for Exchanger

import java.nio.ByteBuffer; 
import java.nio.channels.FileChannel; 
import java.util.concurrent.Exchanger; 
public class BufferedFile { 
    private final Exchanger<ByteBuffer> mExchanger = new Exchanger<ByteBuffer>();
    private FileInputStream mStream;
    private ByteBuffer mWriteBuffer = ByteBuffer.allocateDirect(1024 * 1024);
    private ByteBuffer mReadBuffer = ByteBuffer.allocateDirect(1024 * 1024);
    private FileChannel mChannel;
    private boolean mFirstRun = true;
    private int mAvailable;
    public BufferedFile(String filename) {
        try { 
            mStream = new FileInputStream(filename);
            mChannel = mStream.getChannel();
        } catch (FileNotFoundException e) {
            throw new Error(e);
Connect your IDE to all the code out there  Get Codota for Java