Class Reader


  • public final class Reader
    extends Object
    Reader for compressed files.

    Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
    BSD-style license. See OpenTrafficSim License.

    Version:
    $Revision$, $LastChangedDate$, by $Author$, initial version Oct 25, 2018
    Author:
    Alexander Verbraeck, Peter Knoppers, Wouter Schakel
    • Method Detail

      • createInputStream

        public static InputStream createInputStream​(String fileName,
                                                    CompressionType compressionType)
                                             throws IOException
        Construct a InputStream for a compressed data file.
        Parameters:
        fileName - String; the name of the file
        compressionType - CompressionType; the expected type of the data compression in the file
        Returns:
        InputStream that can yield the expanded content of the file.
        Throws:
        IOException - when the file could not be read
      • createInputStream

        public static InputStream createInputStream​(String fileName)
                                             throws IOException
        Construct a InputStream for a compressed data file. The type of compression is auto-detected.
        Parameters:
        fileName - String; the name of the file
        Returns:
        InputStream that can yield the expanded content of the file.
        Throws:
        IOException - when the file can not be opened or read
      • isGZipCompressed

        public static boolean isGZipCompressed​(byte[] bytes)
                                        throws IOException
        Determine if bytes match the GZip compression signature. Derived from http://stackoverflow.com/questions/4818468/how-to-check-if-inputstream-is-gzipped.
        Determines if a byte array is compressed. The java.util.zip GZip implementation does not expose the GZip header so it is difficult to determine if a string is compressed.
        Parameters:
        bytes - byte[]; at least 2 bytes from the start of the stream to determine compression type
        Returns:
        boolean; true if the data appears to be GZip compressed; false otherwise
        Throws:
        IOException - if the byte array couldn't be read