JDK-5071718 : (bf) Add ByteBuffer.slice(int index, int length)
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2004-07-06
  • Updated: 2024-04-26
  • Resolved: 2019-02-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 13
13 b11Fixed
Related Reports
CSR :  
Relates :  
Relates :  
Relates :  
Description
Name: js151677			Date: 07/06/2004


A DESCRIPTION OF THE REQUEST :
it would be nice is there was a method signature:

ByteBuffer slice(int position, int length)

that would allow the user to create a (sub)view of a larger byte buffer,
this is especially useful for record management types of applications

JUSTIFICATION :
for record management styles of applications it would be invaluable to
be able to overlay a ByteBuffer over a larger ByteBuffer that contains
a set of records, mapping the view onto the bounds of a particular
record.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
as with the existing slice(); with additional semantics of starting at
specified position, for length bytes with appropriate overflow/underlfow
semantics
ACTUAL -
see above

CUSTOMER SUBMITTED WORKAROUND :
none that I can see!
(Incident Review ID: 282349) 
======================================================================

We'd also like to request "absolute" versions of the bulk put(byte[] ...) & get (byte[] ...)
methods while we are at it!

:D


###@###.### 2004-07-30
###@###.### 10/6/04 16:15 GMT

Comments
commit https://github.com/openjdk/jdk/commit/fad1f059b0d93d795d6fae15c1ae3c1c4737b67c Author: Brian Burkhalter <bpb@openjdk.org> Date: Thu Feb 28 12:05:59 2019 -0800
26-04-2024

URL: http://hg.openjdk.java.net/jdk/jdk/rev/1542e63eb537 User: bpb Date: 2019-02-28 20:23:09 +0000
28-02-2019

EVALUATION You can already do this, though it does require that you modify the root ByteBuffer: ByteBuffer bb = ...; bb.position(start1).limit(end1); ByteBuffer slice1 = bb.slice(); bb.position(start2).limit(end2); ByteBuffer slice2 = bb.slice(); Still, a ByteBuffer.slice(offset, length) method would be a useful convenience. We'll consider this for a future release. -- ###@###.### 2004/7/12
07-12-0178