5071718: (bf) Add ByteBuffer.slice(int offset, int length)

Reviewed-by: alanb, bchristi, darcy, rriggs
This commit is contained in:
Brian Burkhalter 2019-02-28 12:05:59 -08:00
parent 8f84ae5684
commit fad1f059b0
17 changed files with 367 additions and 77 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,9 +27,9 @@
package java.nio;
import java.util.Objects;
import jdk.internal.misc.Unsafe;
class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
extends {#if[ro]?ByteBufferAs}$Type$Buffer{#if[ro]?$BO$}
{
@ -85,6 +85,18 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
return new ByteBufferAs$Type$Buffer$RW$$BO$(bb, -1, 0, rem, rem, addr);
}
@Override
public $Type$Buffer slice(int index, int length) {
Objects.checkIndex(index, limit() + 1);
Objects.checkIndex(length, limit() - index + 1);
return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
-1,
0,
length,
length,
byteOffset(index));
}
public $Type$Buffer duplicate() {
return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
this.markValue(),