[JAVA-1262] Support a binary bson type that can accept a byte array "slice" Created: 04/Jun/14  Updated: 20/Oct/20  Resolved: 20/Oct/20

Status: Closed
Project: Java Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor - P4
Reporter: Daniel Gottlieb (Inactive) Assignee: Unassigned
Resolution: Won't Fix Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The current Binary type contract is to pass in a byte array that represents exactly the data to be saved. It would be nice to be able to express a slice/window of a byte array by also accepting offset and length inputs that are used to calculate the relevant portion of the byte array. This is obviously a performance optimization to help avoid copies in performance sensitive parts of a system.

Justification:
In streaming interfaces it is generally not known how big a binary payload will be. Thus something like a `ByteArrayOutputStream` is used, and even when an implementation provides direct access to the underlying buffer, it's not possible[1] to construct a specially sized byte array for the Binary type without a copy.

[1] I'm totally unfamiliar if java offers a way to unsafely trim a byte array, so my claim is speculation.


Generated at Thu Feb 08 08:54:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.