Package org.eclipse.mat.hprof
Class ChunkedGZIPRandomAccessFile
java.lang.Object
java.io.RandomAccessFile
org.eclipse.mat.hprof.ChunkedGZIPRandomAccessFile
- All Implemented Interfaces:
Closeable,DataInput,DataOutput,AutoCloseable
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).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static voidcompressFileChunked(File toCompress, File compressed) Compressed a file to a chunked gzipped file.static voidcompressFileChunked2(File toCompress, File compressed) Compressed a file to a chunked gzipped file.static voidcompressFileUnchunked(File toCompress, File compressed) Compressed a file to an unchunked gzipped file, but with more header fields compared toGZIPOutputStream.static voidForget all cached version of the file.static ChunkedGZIPRandomAccessFileget(RandomAccessFile raf, File file, String prefix) Returns the random access file for the given file ornullif not supported for the file.longlongReturns an estimation of the last physical position we read from.static booleanChecks if the given file is a chunked gzipped file.longlength()Unknown length is Long.MAX_VALUEintread()intread(byte[] buf) intread(byte[] buf, int off, int len) intread(long offset, byte[] b, int off, int len) Reads bytes from the gzip file.voidseek(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
-
Method Details
-
seek
- Overrides:
seekin classRandomAccessFile- Throws:
IOException
-
getFilePointer
public long getFilePointer()- Overrides:
getFilePointerin classRandomAccessFile
-
length
public long length()Unknown length is Long.MAX_VALUE- Overrides:
lengthin classRandomAccessFile
-
read
- Overrides:
readin classRandomAccessFile- Throws:
IOException
-
read
- Overrides:
readin classRandomAccessFile- Throws:
IOException
-
read
- Overrides:
readin classRandomAccessFile- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classRandomAccessFile- Throws:
IOException
-
getLastPhysicalReadPosition
public long getLastPhysicalReadPosition()Returns an estimation of the last physical position we read from.- Returns:
- The last physical position.
-
read
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:
IOException- On error.
-
isChunkedGZIPFile
Checks if the given file is a chunked gzipped file.- Parameters:
raf- The file to check.- Returns:
trueif the file is a chunked gzip file.- Throws:
IOException- On error.
-
get
public static ChunkedGZIPRandomAccessFile get(RandomAccessFile raf, File file, String prefix) throws IOException Returns the random access file for the given file ornullif 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:
IOException- problem reading the file
-
forget
Forget all cached version of the file.- Parameters:
file- The file to forget.
-
compressFileChunked
Compressed a file to a chunked gzipped file.- Parameters:
toCompress- The file to gzip.compressed- The gzipped file.- Throws:
IOException- On error.
-
compressFileUnchunked
Compressed a file to an unchunked gzipped file, but with more header fields compared toGZIPOutputStream.- Parameters:
toCompress- The file to gzip.compressed- The gzipped file.- Throws:
IOException- On error.
-
compressFileChunked2
Compressed a file to a chunked gzipped file. Note that there is no header CRC.- Parameters:
toCompress- The file to gzip.compressed- The gzipped file.- Throws:
IOException- On error.
-