Here you can find the source of slice(final ByteBuffer buffer, final int offset, final int length)
Parameter | Description |
---|---|
buffer | The byte buffer to slice data from. |
offset | The offset of the part to slice. |
length | The length of the part to slice. |
public static ByteBuffer slice(final ByteBuffer buffer, final int offset, final int length)
//package com.java2s; /*/* ww w . j a va 2s . co m*/ * Copyright 2013 Luca Longinotti <l@longi.li> * See LICENSE.md for licensing information. */ import java.nio.ByteBuffer; public class Main { /** * Slices a part of the specified {@link ByteBuffer} into a new byte buffer * and returns it. * * @param buffer * The byte buffer to slice data from. * @param offset * The offset of the part to slice. * @param length * The length of the part to slice. * @return The new byte buffer with the sliced part. */ public static ByteBuffer slice(final ByteBuffer buffer, final int offset, final int length) { final int oldPosition = buffer.position(); final int oldLimit = buffer.limit(); buffer.position(offset); buffer.limit(offset + length); final ByteBuffer slice = buffer.slice(); buffer.position(oldPosition); buffer.limit(oldLimit); return slice; } }