Piotr Karwasz created IO-882:
--------------------------------

             Summary: Comprehensive integer reading utilities for both 
endiannesses
                 Key: IO-882
                 URL: https://issues.apache.org/jira/browse/IO-882
             Project: Commons IO
          Issue Type: New Feature
            Reporter: Piotr Karwasz


The {{EndianUtils}} class is very useful in Commons Compress and replaces a 
number of earlier utility classes. However, some design aspects limit its ease 
of use:

* *Confusing naming:*  
  The current “swapped” terminology is unintuitive, as it assumes users know 
that the default (“unswapped”) byte order is big endian. This makes the API 
harder to understand at a glance.

* *Missing big-endian counterparts:*  
  {{EndianUtils}} provides convenience methods for little-endian access, but 
not for big-endian access. As a result, users must rely on alternatives when 
reading big-endian values:  
   ** For {{InputStream}}, wrapping in {{DataInputStream}} is required.  
   ** For byte arrays, users must resort to {{ByteBuffer}}.

* *Minor gap:*  
  {{EndianUtils}} lacks a {{readUnsignedByte}} method. While a single byte is 
independent of endianness, unsigned-byte reads are still a common operation 
when consuming variable-width integer formats.

While {{ByteBuffer}} supports both byte orders and may become the preferred 
approach as more libraries migrate to NIO, an improved unified utility within 
Commons IO (or a successor to {{EndianUtils}}) would still offer significant 
value: especially for stream-oriented code.

We might consider introducing a new {{Integers}} class, conceptually similar to 
{{Strings}} in Commons Lang, with the following characteristics:

* Two singleton instances: {{BIG_ENDIAN}} and {{LITTLE_ENDIAN}}.
* Support for reading all Java integer types and their unsigned equivalents.
* Consistent behaviour that throws {{EOFException}} when insufficient data is 
available.
* A clearer, more expressive API without ambiguous terminology.





--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to