You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "elharo (via GitHub)" <gi...@apache.org> on 2024/01/25 12:38:16 UTC

[PR] Clarify and correct API doc [commons-io]

elharo opened a new pull request, #566:
URL: https://github.com/apache/commons-io/pull/566

   Most of the methods in this class are badly named. Except for the swap method they all just read and write in little endian order. E.g. consider readSwappedInteger
   
   ```
       public static int readSwappedInteger(final InputStream input) throws IOException {
           final int value1 = read(input);
           final int value2 = read(input);
           final int value3 = read(input);
           final int value4 = read(input);
           return ((value1 & 0xff) << 0) + ((value2 & 0xff) << 8) + ((value3 & 0xff) << 16) + ((value4 & 0xff) << 24);
       }
   ```
   
   This always reads four bytes from an input stream and always considers the first byte read to be the least significant. It would have been better named readLittleEndianInteger.
   
   I'm tempted to deprecate the whole thing and replace it with something better named, but for now at least let's correct the Java doc. 
   
   @garydgregory 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clarify and correct EndianUtils API doc [commons-io]

Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on PR #566:
URL: https://github.com/apache/commons-io/pull/566#issuecomment-1911254305

   PTAL


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clarify and correct EndianUtils and SwappedDataInputStream API doc [commons-io]

Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on code in PR #566:
URL: https://github.com/apache/commons-io/pull/566#discussion_r1467733794


##########
src/main/java/org/apache/commons/io/EndianUtils.java:
##########
@@ -182,13 +194,14 @@ public static short readSwappedShort(final InputStream input) throws IOException
     }
 
     /**
-     * Reads an unsigned integer (32-bit) value from a byte array at a given
-     * offset. The value is converted to the opposed endian system while
-     * reading.
+     * Reads a little endian unsigned integer (32-bit) value from a byte array at a given

Review Comment:
   Since Java's ints are signed you can't fit the unsigned int values from ~2.2 billion  to ~4 billion into an int, so you have to return a long. The long will always be <= 2^32, but might be greater than Integer.MAX_INT. Not sure how much of that to say here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clarify and correct EndianUtils API doc [commons-io]

Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on code in PR #566:
URL: https://github.com/apache/commons-io/pull/566#discussion_r1466548537


##########
src/main/java/org/apache/commons/io/EndianUtils.java:
##########
@@ -78,19 +84,20 @@ public static double readSwappedDouble(final InputStream input) throws IOExcepti
     }
 
     /**
-     * Reads a "float" value from a byte array at a given offset. The value is
-     * converted to the opposed endian system while reading.
+     * Reads a little endian "float" value from a byte array at a given offset.

Review Comment:
   Maybe. What's really confusing here is we need to distinguish two different "floats":
   
   1. The Java float primitive in memory in the VM.
   2. A 4 byte chunk read from an input stream or an array. 
   
   I'm not sure I've got this distinction clear enough yet. Let me play with it a bit more.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clarify and correct EndianUtils and SwappedDataInputStream API doc [commons-io]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory merged PR #566:
URL: https://github.com/apache/commons-io/pull/566


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clarify and correct EndianUtils API doc [commons-io]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #566:
URL: https://github.com/apache/commons-io/pull/566#issuecomment-1912008730

   According to Wikipedia, PDP has something close also referred to PDP-endian!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clarify and correct EndianUtils and SwappedDataInputStream API doc [commons-io]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #566:
URL: https://github.com/apache/commons-io/pull/566#discussion_r1467728534


##########
src/main/java/org/apache/commons/io/EndianUtils.java:
##########
@@ -182,13 +194,14 @@ public static short readSwappedShort(final InputStream input) throws IOException
     }
 
     /**
-     * Reads an unsigned integer (32-bit) value from a byte array at a given
-     * offset. The value is converted to the opposed endian system while
-     * reading.
+     * Reads a little endian unsigned integer (32-bit) value from a byte array at a given

Review Comment:
   Hi @elharo 
   
   This is slightly confusing to me: The method returns a `long` (64-bit) but we are reading an 32-bit integer? Should we clarify this point? Something like "Read a foo as a bar".



##########
src/main/java/org/apache/commons/io/EndianUtils.java:
##########
@@ -182,13 +194,14 @@ public static short readSwappedShort(final InputStream input) throws IOException
     }
 
     /**
-     * Reads an unsigned integer (32-bit) value from a byte array at a given
-     * offset. The value is converted to the opposed endian system while
-     * reading.
+     * Reads a little endian unsigned integer (32-bit) value from a byte array at a given

Review Comment:
   Hi @elharo 
   
   This is slightly confusing to me: The method returns a `long` (64-bit) but we are reading an 32-bit integer? Should we clarify this point? Something like "Reads a foo as a bar".



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clarify and correct EndianUtils and SwappedDataInputStream API doc [commons-io]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #566:
URL: https://github.com/apache/commons-io/pull/566#issuecomment-1912039493

   ## [Codecov](https://app.codecov.io/gh/apache/commons-io/pull/566?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   All modified and coverable lines are covered by tests :white_check_mark:
   > Comparison is base [(`4bd93ec`)](https://app.codecov.io/gh/apache/commons-io/commit/4bd93ec056640bc973c9b80c33b12b162a96f9d8?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 85.98% compared to head [(`552d6ad`)](https://app.codecov.io/gh/apache/commons-io/pull/566?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 85.99%.
   > Report is 13 commits behind head on master.
   
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@            Coverage Diff            @@
   ##             master     #566   +/-   ##
   =========================================
     Coverage     85.98%   85.99%           
   - Complexity     3496     3497    +1     
   =========================================
     Files           231      231           
     Lines          8251     8253    +2     
     Branches        964      964           
   =========================================
   + Hits           7095     7097    +2     
   - Misses          865      866    +1     
   + Partials        291      290    -1     
   ```
   
   
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/commons-io/pull/566?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clarify and correct EndianUtils API doc [commons-io]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #566:
URL: https://github.com/apache/commons-io/pull/566#discussion_r1466531754


##########
src/main/java/org/apache/commons/io/EndianUtils.java:
##########
@@ -78,19 +84,20 @@ public static double readSwappedDouble(final InputStream input) throws IOExcepti
     }
 
     /**
-     * Reads a "float" value from a byte array at a given offset. The value is
-     * converted to the opposed endian system while reading.
+     * Reads a little endian "float" value from a byte array at a given offset.

Review Comment:
   I think that using `{@code _type_}` would be better here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clarify and correct EndianUtils API doc [commons-io]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #566:
URL: https://github.com/apache/commons-io/pull/566#discussion_r1467148185


##########
src/main/java/org/apache/commons/io/EndianUtils.java:
##########
@@ -261,7 +275,8 @@ public static float swapFloat(final float value) {
     }
 
     /**
-     * Converts an "int" value between endian systems.
+     * Converts an {@code int} value between endian systems.

Review Comment:
   We should be clear that the toggle is between big and little-endian. We'll then avoid the shadow of even thinking about middle-endian madness.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clarify and correct EndianUtils API doc [commons-io]

Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on code in PR #566:
URL: https://github.com/apache/commons-io/pull/566#discussion_r1467602536


##########
src/main/java/org/apache/commons/io/EndianUtils.java:
##########
@@ -261,7 +275,8 @@ public static float swapFloat(final float value) {
     }
 
     /**
-     * Converts an "int" value between endian systems.
+     * Converts an {@code int} value between endian systems.

Review Comment:
   Good point. Curious, has any system ever actually used middle-endianess or is it just a theoretical possibility? Anyway, let me update this. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clarify and correct EndianUtils and SwappedDataInputStream API doc [commons-io]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #566:
URL: https://github.com/apache/commons-io/pull/566#discussion_r1467769355


##########
src/main/java/org/apache/commons/io/EndianUtils.java:
##########
@@ -182,13 +194,14 @@ public static short readSwappedShort(final InputStream input) throws IOException
     }
 
     /**
-     * Reads an unsigned integer (32-bit) value from a byte array at a given
-     * offset. The value is converted to the opposed endian system while
-     * reading.
+     * Reads a little endian unsigned integer (32-bit) value from a byte array at a given

Review Comment:
   Makes sense, the comment already mentions "unsigned". TY for the clarification. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org