Class ChunkedGZIPRandomAccessFile

  • All Implemented Interfaces:
    java.io.Closeable, java.io.DataInput, java.io.DataOutput, java.lang.AutoCloseable

    public class ChunkedGZIPRandomAccessFile
    extends java.io.RandomAccessFile
    This class can be used to get random access to chunked gzipped hprof files like the openjdk can create them. As described in https://tools.ietf.org/html/rfc1952, a gzip file consists of a number of "members". The openjdk gzipped dumps have a maximum size of data compressed in each "member". This makes it possible to start decompression at each start of a member. In case of the openjdk dumps the maximum size of uncompressed data in a "member" is stored in a comment in the first member. This is used to detect those files (without having to uncompress the whole file).
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      static void compressFileChunked​(java.io.File toCompress, java.io.File compressed)
      Compressed a file to a chunked gzipped file.
      static void compressFileChunked2​(java.io.File toCompress, java.io.File compressed)
      Compressed a file to a chunked gzipped file.
      static void forget​(java.io.File file)
      Forget all cached version of the file.
      static ChunkedGZIPRandomAccessFile get​(java.io.RandomAccessFile raf, java.io.File file, java.lang.String prefix)
      Returns the random access file for the given file or null if not supported for the file.
      long getFilePointer()  
      long getLastPhysicalReadPosition()
      Returns an estimation of the last physical position we read from.
      static boolean isChunkedGZIPFile​(java.io.RandomAccessFile raf)
      Checks if the given file is a chunked gzipped file.
      long length()
      Unknown length is Long.MAX_VALUE
      int read()  
      int read​(byte[] buf)  
      int read​(byte[] buf, int off, int len)  
      int read​(long offset, byte[] b, int off, int len)
      Reads bytes from the gzip file.
      void seek​(long pos)  
      • Methods inherited from class java.io.RandomAccessFile

        getChannel, getFD, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, setLength, skipBytes, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • seek

        public void seek​(long pos)
                  throws java.io.IOException
        Overrides:
        seek in class java.io.RandomAccessFile
        Throws:
        java.io.IOException
      • getFilePointer

        public long getFilePointer()
        Overrides:
        getFilePointer in class java.io.RandomAccessFile
      • length

        public long length()
        Unknown length is Long.MAX_VALUE
        Overrides:
        length in class java.io.RandomAccessFile
      • read

        public int read()
                 throws java.io.IOException
        Overrides:
        read in class java.io.RandomAccessFile
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] buf)
                 throws java.io.IOException
        Overrides:
        read in class java.io.RandomAccessFile
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] buf,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.RandomAccessFile
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.RandomAccessFile
        Throws:
        java.io.IOException
      • getLastPhysicalReadPosition

        public long getLastPhysicalReadPosition()
        Returns an estimation of the last physical position we read from.
        Returns:
        The last physical position.
      • read

        public int read​(long offset,
                        byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Reads bytes from the gzip file.
        Parameters:
        offset - The offset from which to start the read.
        b - The array to read into.
        off - The offset in the array to use.
        len - The number of bytes to read at most.
        Returns:
        The number of bytes read or -1 if we are at the end of the file.
        Throws:
        java.io.IOException - On error.
      • isChunkedGZIPFile

        public static boolean isChunkedGZIPFile​(java.io.RandomAccessFile raf)
                                         throws java.io.IOException
        Checks if the given file is a chunked gzipped file.
        Parameters:
        raf - The file to check.
        Returns:
        true if the file is a chunked gzip file.
        Throws:
        java.io.IOException - On error.
      • get

        public static ChunkedGZIPRandomAccessFile get​(java.io.RandomAccessFile raf,
                                                      java.io.File file,
                                                      java.lang.String prefix)
                                               throws java.io.IOException
        Returns the random access file for the given file or null if not supported for the file.
        Parameters:
        raf - The random access file.
        file - The file name.
        prefix - The prefix of the snapshot.
        Returns:
        The random access file or null.
        Throws:
        java.io.IOException - problem reading the file
      • forget

        public static void forget​(java.io.File file)
        Forget all cached version of the file.
        Parameters:
        file - The file to forget.
      • compressFileChunked

        public static void compressFileChunked​(java.io.File toCompress,
                                               java.io.File compressed)
                                        throws java.io.IOException
        Compressed a file to a chunked gzipped file.
        Parameters:
        toCompress - The file to gzip.
        compressed - The gzipped file.
        Throws:
        java.io.IOException - On error.
      • compressFileChunked2

        public static void compressFileChunked2​(java.io.File toCompress,
                                                java.io.File compressed)
                                         throws java.io.IOException
        Compressed a file to a chunked gzipped file.
        Parameters:
        toCompress - The file to gzip.
        compressed - The gzipped file.
        Throws:
        java.io.IOException - On error.