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

    https://github.com/apache/jena/pull/427#discussion_r192694578
  
    --- Diff: jena-base/src/main/java/org/apache/jena/atlas/io/IO.java ---
    @@ -77,10 +81,28 @@ static public InputStream openFileEx(String filename) 
throws IOException, FileNo
                 filename = IRILib.decode(filename) ;
             }
             InputStream in = new FileInputStream(filename) ;
    -        if ( filename.endsWith(".gz") )
    -            in = new GZIPInputStream(in) ;
    +        String ext = FileOps.extension(filename);
    +        switch ( ext ) {
    +            case "":        return in;
    +            case "gz":      return new GZIPInputStream(in) ;
    +            case "bz2":     return new BZip2CompressorInputStream(in);
    +            case "sz":      return new SnappyCompressorInputStream(in);
    +        }
             return in ;
         }
    +
    +    private static String[] extensions = { ".gz", ".bz2", ".sz" }; 
    +    
    +    /** The filename without any compression extension, or the original 
filename.
    +     *  It tests for compression types handled by {@link #openFileEx}.
    +     */
    +    static public String filenameNoCompression(String filename) {
    +        for ( String ext : extensions ) {
    +            if ( filename.endsWith(ext) )
    +                return filename.substring(0, 
filename.length()-ext.length());
    +        }
    +        return filename;
    +    }
    --- End diff --
    
    Maybe instead
    
    ```java
        /** The filename without any compression extension, or the original 
filename.
         *  It tests for compression types handled by {@link #openFileEx}.
         */
        static public String filenameNoCompression(String filename) {
            if ( FilenameUtils.isExtension(filename, extensions) ) {
                return FilenameUtils.removeExtension(filename);
            }
            return filename;
        }
    ```
    
    I believe we have commons-io already in the dependencies list. There's some 
extra check for null bytes in the extension check... but that's not so 
important. Just simpler I think.


---

Reply via email to