You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Garret Wilson (Jira)" <ji...@apache.org> on 2021/02/04 15:20:00 UTC
[jira] [Created] (IMAGING-280) Length specifier for
ByteSourceArray.
Garret Wilson created IMAGING-280:
-------------------------------------
Summary: Length specifier for ByteSourceArray.
Key: IMAGING-280
URL: https://issues.apache.org/jira/browse/IMAGING-280
Project: Commons Imaging
Issue Type: Improvement
Reporter: Garret Wilson
Many of the library processing methods take a {{ByteSource}}. The {{ByteSourceArray}} allows a byte source from an array of bytes, but unfortunately it does not allow specification of the number of bytes, assuming that the entire byte array is used; e.g.:
{code:java}
public ByteSourceArray(final byte[] bytes) {
this(null, bytes);
}
{code}
This severely impedes the use of the class if the code using {{ByteSourceArray}} has a byte array partially filled. The obvious case is processing data in a pipeline, when the producer has written to a {{ByteArrayOutputStream}}. Although {{ByteArrayOutputStream.toByteArray()}} provides a copy of the internal data, it is possible to subclass {{ByteArrayOutputStream}} to get access to the underlying bytes to prevent copying. Because {{ByteArrayOutputStream}} grows dynamically, the internal byte array may not be full.
Thus {{ByteSourceArray}} needs a separate constructor to indicate the length (and even the offset), just like {{ByteArrayInputStream}} does:
{code:java}
public ByteArrayInputStream(byte buf[], int offset, int length) {…}
{code}
Moreover this is extremely trivial to add. Without it, however, the developer is forced to basically reimplement the entire class.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)