Java ByteBuffer Fill fill(ByteBuffer buffer, int position, int length, byte filler)

Here you can find the source of fill(ByteBuffer buffer, int position, int length, byte filler)

Description

fill

License

Open Source License

Declaration

public static void fill(ByteBuffer buffer, int position, int length, byte filler) 

Method Source Code

//package com.java2s;
/**//  ww  w .j  a v a2 s  .c om
 *  Copyright (c) 2012, 2014 Sme.UP and others.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 * 
 * Contributors: 
 *   Mattia Rocchi - Initial API and implementation 
 */

import java.nio.ByteBuffer;
import java.util.Arrays;

public class Main {
    public static void fill(ByteBuffer buffer, int position, int length, byte filler) {

        if (buffer.hasArray())
            Arrays.fill(buffer.array(), position, length, filler);
        else {
            for (int i = position; i < length; i++) {
                buffer.put(filler);
            }
        }
    }
}

Related

  1. fill(ByteBuffer buffer, int off, int len, byte val)
  2. fill(ByteBuffer to, byte[] b, int off, int len)
  3. fillBuffer(ByteBuffer buffer, byte[] bytes)
  4. fillBuffer(ByteBuffer buffer, int seed)
  5. fillBufFromTime(ByteBuffer buf, Calendar cal)