Github user myui commented on a diff in the pull request:

    https://github.com/apache/incubator-hivemall/pull/97#discussion_r127503646
  
    --- Diff: core/src/main/java/hivemall/utils/io/IOUtils.java ---
    @@ -129,6 +131,29 @@ public static int readInt(final InputStream in) throws 
IOException {
             return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
         }
     
    +    /**
    +     * Look ahead InputStream and decompress it as GZIPInputStream if 
needed
    +     *
    +     * @link https://stackoverflow.com/a/4818946
    +     */
    +    public static InputStream decompressStream(final InputStream is) 
throws IOException {
    +        final PushbackInputStream pb = new PushbackInputStream(is, 2);
    +
    +        // look ahead
    +        int b1 = pb.read();
    +        int b2 = pb.read();
    +
    +        // push back
    +        pb.unread(b2);
    +        pb.unread(b1);
    +
    +        if (((b2 << 8) | b1) == GZIPInputStream.GZIP_MAGIC) {
    --- End diff --
    
    a potential bug. 
    
    should be..
    ```java
    final int streamHeader = ((int) b1 & 0xff) | ((b2 << 8) & 0xff00);
    if (streamHeader == GZIPInputStream.GZIP_MAGIC) {
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to