8269909: getStack method in hprof.parser.Reader should use try-with-resource
Reviewed-by: dholmes, cjplummer, sspitsyn
This commit is contained in:
parent
e4766ee0aa
commit
09ab86b40c
@ -85,8 +85,9 @@ public abstract class Reader {
|
||||
heapFile = heapFile.substring(0, pos);
|
||||
}
|
||||
GzipRandomAccess access = null;
|
||||
try (PositionDataInputStream in = new PositionDataInputStream(
|
||||
new BufferedInputStream(new FileInputStream(heapFile)))) {
|
||||
try (FileInputStream fis = new FileInputStream(heapFile);
|
||||
BufferedInputStream bis = new BufferedInputStream(fis);
|
||||
PositionDataInputStream in = new PositionDataInputStream(bis)) {
|
||||
int i = in.readInt();
|
||||
if (i == HprofReader.MAGIC_NUMBER) {
|
||||
Reader r
|
||||
@ -95,12 +96,12 @@ public abstract class Reader {
|
||||
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();
|
||||
try (BufferedInputStream gzBis = new BufferedInputStream(access.asStream(0));
|
||||
PositionDataInputStream pdin = new PositionDataInputStream(gzBis)) {
|
||||
i = pdin.readInt();
|
||||
if (i == HprofReader.MAGIC_NUMBER) {
|
||||
Reader r
|
||||
= new HprofReader(access.asFileBuffer(), in2, dumpNumber,
|
||||
= new HprofReader(access.asFileBuffer(), pdin, dumpNumber,
|
||||
callStack, debugLevel);
|
||||
return r.read();
|
||||
} else {
|
||||
@ -136,8 +137,9 @@ public abstract class Reader {
|
||||
}
|
||||
heapFile = heapFile.substring(0, pos);
|
||||
}
|
||||
try (PositionDataInputStream in = new PositionDataInputStream(
|
||||
new BufferedInputStream(new FileInputStream(heapFile)))) {
|
||||
try (FileInputStream fis= new FileInputStream(heapFile);
|
||||
BufferedInputStream bis = new BufferedInputStream(fis);
|
||||
PositionDataInputStream in = new PositionDataInputStream(bis)) {
|
||||
int i = in.readInt();
|
||||
if (i == HprofReader.MAGIC_NUMBER) {
|
||||
HprofReader r
|
||||
@ -151,9 +153,9 @@ public abstract class Reader {
|
||||
String deCompressedFile = "heapdump" + System.currentTimeMillis() + ".hprof";
|
||||
File out = new File(deCompressedFile);
|
||||
// Decompress to get dump file.
|
||||
try {
|
||||
GZIPInputStream gis = new GZIPInputStream(new FileInputStream(heapFile));
|
||||
FileOutputStream fos = new FileOutputStream(out);
|
||||
try (FileInputStream heapFis = new FileInputStream(heapFile);
|
||||
GZIPInputStream gis = new GZIPInputStream(heapFis);
|
||||
FileOutputStream fos = new FileOutputStream(out)) {
|
||||
byte[] buffer = new byte[1024 * 1024];
|
||||
int len = 0;
|
||||
while ((len = gis.read(buffer)) > 0) {
|
||||
@ -164,13 +166,13 @@ public abstract class Reader {
|
||||
throw new IOException("Cannot decompress the compressed hprof file", e);
|
||||
}
|
||||
// Check dump data header and print stack trace.
|
||||
try {
|
||||
PositionDataInputStream in2 = new PositionDataInputStream(
|
||||
new BufferedInputStream(new FileInputStream(out)));
|
||||
i = in2.readInt();
|
||||
try (FileInputStream outFis = new FileInputStream(out);
|
||||
BufferedInputStream outBis = new BufferedInputStream(outFis);
|
||||
PositionDataInputStream pdin = new PositionDataInputStream(outBis)) {
|
||||
i = pdin.readInt();
|
||||
if (i == HprofReader.MAGIC_NUMBER) {
|
||||
HprofReader r
|
||||
= new HprofReader(deCompressedFile, in2, dumpNumber,
|
||||
= new HprofReader(deCompressedFile, pdin, dumpNumber,
|
||||
true, debugLevel);
|
||||
r.read();
|
||||
return r.printStackTraces();
|
||||
|
Loading…
x
Reference in New Issue
Block a user