Java ByteBuffer Copy copyByteBuffer(ByteBuffer srcBuf, int srcStep, ByteBuffer dstBuf, int dstStep)

Here you can find the source of copyByteBuffer(ByteBuffer srcBuf, int srcStep, ByteBuffer dstBuf, int dstStep)

Description

copy Byte Buffer

License

Open Source License

Declaration

private static void copyByteBuffer(ByteBuffer srcBuf, int srcStep, ByteBuffer dstBuf, int dstStep) 

Method Source Code

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

import java.nio.ByteBuffer;

public class Main {
    private static void copyByteBuffer(ByteBuffer srcBuf, int srcStep, ByteBuffer dstBuf, int dstStep) {
        assert srcBuf != dstBuf;
        int channels = 3;
        int w = Math.min(srcStep, dstStep);
        int srcLine = srcBuf.position(), dstLine = dstBuf.position();
        byte[] buffer = new byte[channels];
        while (srcLine < srcBuf.capacity() && dstLine < dstBuf.capacity()) {
            srcBuf.position(srcLine);//w  w w .j av a  2 s  .c om
            dstBuf.position(dstLine);
            w = Math.min(Math.min(w, srcBuf.remaining()), dstBuf.remaining());
            for (int x = 0; x < w; x += channels) {
                for (int z = 0; z < channels; z++) {
                    int in = srcBuf.get();
                    byte out;
                    out = (byte) in;
                    buffer[z] = out;
                }
                for (int z = channels - 1; z >= 0; z--) {
                    dstBuf.put(buffer[z]);
                }
            }
            srcLine += srcStep;
            dstLine += dstStep;
        }
    }
}

Related

  1. copyBinary(final ByteBuffer orig)
  2. copyBuffer(ByteBuffer dest, int pos1, ByteBuffer src, int len)
  3. copyBufferToStream(OutputStream out, ByteBuffer in, int offset, int length)
  4. copyByteBuffer(ByteBuffer buf)
  5. copyByteBuffer(ByteBuffer src)
  6. copyByteBuffer(final ByteBuffer pBuffer)
  7. copyByteBuffer(java.nio.ByteBuffer data)
  8. copyBytes(ByteBuffer bytes)
  9. copyBytes(ByteBuffer src, ByteBuffer dst, int length)