Java ByteBuffer Get transferUntilTargetPos(ByteBuffer src, ByteBuffer trg, int trgPos)

Here you can find the source of transferUntilTargetPos(ByteBuffer src, ByteBuffer trg, int trgPos)

Description

Copy as many byte from source to target, until either source has no more data, target cannot take more or the trg.position() is equals to limit value.

License

Open Source License

Declaration

public static void transferUntilTargetPos(ByteBuffer src, ByteBuffer trg, int trgPos) 

Method Source Code


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

import java.nio.ByteBuffer;

public class Main {
    /**// ww w  .  j  av  a2s  .com
     * Copy as many byte from source to target, until either source has no more data, target cannot take more or 
     * the trg.position() is equals to limit value.
     */
    public static void transferUntilTargetPos(ByteBuffer src, ByteBuffer trg, int trgPos) {
        int cpySz = Math.min(src.remaining(), Math.min(trgPos - trg.position(), trg.remaining()));
        if (cpySz <= 0) {
            return;
        }
        int oldLimit = src.limit();
        src.limit(src.position() + cpySz);
        trg.put(src);
        src.limit(oldLimit);
    }
}

Related

  1. getWithShortLength(ByteBuffer bb)
  2. getZeroTerminatedStringBytes(ByteBuffer dataBuffer)
  3. getZipEocdCentralDirectorySizeBytes(ByteBuffer zipEndOfCentralDirectory)
  4. insertByteArray(byte[] source, ByteBuffer target)
  5. transfer(ByteBuffer src, FileChannel target, long position, long count)
  6. utf8ByteBuffer(String messageTemplate, Object... args)