< prev index next >

test/lib/jdk/test/lib/hprof/parser/Reader.java

Print this page
rev 58388 : 8237354: Add option to jcmd to write a gzipped heap dump
Reviewed-by:

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -79,18 +79,33 @@
                 System.err.println(msg);
                 throw new IOException(msg);
             }
             heapFile = heapFile.substring(0, pos);
         }
+        GzipRandomAccess access = null;
         try (PositionDataInputStream in = new PositionDataInputStream(
                 new BufferedInputStream(new FileInputStream(heapFile)))) {
             int i = in.readInt();
             if (i == HprofReader.MAGIC_NUMBER) {
                 Reader r
                     = new HprofReader(heapFile, in, dumpNumber,
                                       callStack, debugLevel);
                 return r.read();
+            } else if ((access = GzipRandomAccess.getAccess(heapFile, 16)) != null) {
+                in.close();
+                try (PositionDataInputStream in2 = new PositionDataInputStream(
+                        new BufferedInputStream(access.asStream(0)))) {
+                    i = in2.readInt();
+                    if (i == HprofReader.MAGIC_NUMBER) {
+                        Reader r
+                            = new HprofReader(access.asFileBuffer(), in2, dumpNumber,
+                                              callStack, debugLevel);
+                        return r.read();
+                    } else {
+                         throw new IOException("Unrecognized magic number in gzipped file: " + i);
+                    }
+                }
             } else {
                 throw new IOException("Unrecognized magic number: " + i);
             }
         }
     }
< prev index next >