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, 2018, 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
@ -25,6 +25,7 @@
package java.nio;
import java.util.Objects;
// ## If the sequence is a string, use reflection to share its array
@ -51,6 +52,18 @@ class StringCharBuffer // package-private
offset + this.position());
}
@Override
public CharBuffer slice(int index, int length) {
Objects.checkIndex(index, limit() + 1);
Objects.checkIndex(length, limit() - index + 1);
return new StringCharBuffer(str,
-1,
0,
length,
length,
offset + index);
}
private StringCharBuffer(CharSequence s,
int mark,
int pos,