Code example for Exchanger

Methods: exchange

0
    } 
 
    public int read(byte[] dst, int estimated) {
        if (mReadBuffer.position() == mAvailable) {
            try { 
                mReadBuffer = mExchanger.exchange(mReadBuffer);
            } catch (InterruptedException e) {
                return 0; 
            } 
        } 
        int read = Math.min(estimated, mAvailable - mReadBuffer.position());
        mReadBuffer.get(dst, 0, read);
        mAvailable -= read;
        return read;
    } 
 
    public void fillBuffer() { 
        try { 
            while (mWriteBuffer.remaining() > 0 && mChannel.read(mWriteBuffer) > 0) ;
        } catch (IOException e) {
Experience pair programming with AI  Get Codota for Java