Cleanup (I/O ops in java-decompiler)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -78,13 +78,9 @@ public class ContextUnit {
|
||||
String oldName = cl.qualifiedName;
|
||||
|
||||
StructClass newCl;
|
||||
DataInputFullStream in = loader.getClassStream(oldName);
|
||||
try {
|
||||
try (DataInputFullStream in = loader.getClassStream(oldName)) {
|
||||
newCl = new StructClass(in, cl.isOwn(), loader);
|
||||
}
|
||||
finally {
|
||||
in.close();
|
||||
}
|
||||
|
||||
lstClasses.add(newCl);
|
||||
|
||||
@@ -168,4 +164,4 @@ public class ContextUnit {
|
||||
public List<StructClass> getClasses() {
|
||||
return classes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -119,17 +119,11 @@ public class StructContext {
|
||||
}
|
||||
|
||||
if (filename.endsWith(".class")) {
|
||||
try {
|
||||
DataInputFullStream in = loader.getClassStream(file.getAbsolutePath(), null);
|
||||
try {
|
||||
StructClass cl = new StructClass(in, isOwn, loader);
|
||||
classes.put(cl.qualifiedName, cl);
|
||||
unit.addClass(cl, filename);
|
||||
loader.addClassLink(cl.qualifiedName, new LazyLoader.Link(LazyLoader.Link.CLASS, file.getAbsolutePath(), null));
|
||||
}
|
||||
finally {
|
||||
in.close();
|
||||
}
|
||||
try (DataInputFullStream in = loader.getClassStream(file.getAbsolutePath(), null)) {
|
||||
StructClass cl = new StructClass(in, isOwn, loader);
|
||||
classes.put(cl.qualifiedName, cl);
|
||||
unit.addClass(cl, filename);
|
||||
loader.addClassLink(cl.qualifiedName, new LazyLoader.Link(LazyLoader.Link.CLASS, file.getAbsolutePath(), null));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
String message = "Corrupted class file: " + file;
|
||||
@@ -143,10 +137,8 @@ public class StructContext {
|
||||
}
|
||||
|
||||
private void addArchive(String path, File file, int type, boolean isOwn) throws IOException {
|
||||
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
|
||||
ZipFile archive = type == ContextUnit.TYPE_JAR ? new JarFile(file) : new ZipFile(file);
|
||||
|
||||
try {
|
||||
//noinspection IOResourceOpenedButNotSafelyClosed
|
||||
try (ZipFile archive = type == ContextUnit.TYPE_JAR ? new JarFile(file) : new ZipFile(file)) {
|
||||
Enumeration<? extends ZipEntry> entries = archive.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
@@ -178,12 +170,9 @@ public class StructContext {
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
archive.close();
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, StructClass> getClasses() {
|
||||
return classes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -73,15 +73,15 @@ public class StructMember {
|
||||
|
||||
protected StructGeneralAttribute readAttribute(DataInputFullStream in, ConstantPool pool, String name) throws IOException {
|
||||
StructGeneralAttribute attribute = StructGeneralAttribute.createAttribute(name);
|
||||
int length = in.readInt();
|
||||
if (attribute == null) {
|
||||
in.discard(in.readInt());
|
||||
in.discard(length);
|
||||
}
|
||||
else {
|
||||
byte[] data = new byte[in.readInt()];
|
||||
in.readFull(data);
|
||||
byte[] data = in.read(length);
|
||||
attribute.setInfo(data);
|
||||
attribute.initContent(pool);
|
||||
}
|
||||
return attribute;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -47,17 +47,13 @@ public class LazyLoader {
|
||||
}
|
||||
|
||||
public ConstantPool loadPool(String classname) {
|
||||
try {
|
||||
DataInputFullStream in = getClassStream(classname);
|
||||
if (in == null) return null;
|
||||
|
||||
try {
|
||||
try (DataInputFullStream in = getClassStream(classname)) {
|
||||
if (in != null) {
|
||||
in.discard(8);
|
||||
return new ConstantPool(in);
|
||||
}
|
||||
finally {
|
||||
in.close();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
@@ -67,11 +63,8 @@ public class LazyLoader {
|
||||
public byte[] loadBytecode(StructMethod mt, int codeFullLength) {
|
||||
String className = mt.getClassStruct().qualifiedName;
|
||||
|
||||
try {
|
||||
DataInputFullStream in = getClassStream(className);
|
||||
if (in == null) return null;
|
||||
|
||||
try {
|
||||
try (DataInputFullStream in = getClassStream(className)) {
|
||||
if (in != null) {
|
||||
in.discard(8);
|
||||
|
||||
ConstantPool pool = mt.getClassStruct().getPool();
|
||||
@@ -118,17 +111,13 @@ public class LazyLoader {
|
||||
}
|
||||
|
||||
in.discard(12);
|
||||
byte[] code = new byte[codeFullLength];
|
||||
in.readFull(code);
|
||||
return code;
|
||||
|
||||
return in.read(codeFullLength);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
in.close();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -170,4 +159,4 @@ public class LazyLoader {
|
||||
this.internalPath = internalPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user