Small fix.

This commit is contained in:
zaxar163 2019-01-06 21:46:51 +04:00
parent 05a3b2ba1f
commit a76a566a37
No known key found for this signature in database
GPG key ID: CEE900027AE098E0
2 changed files with 23 additions and 24 deletions

View file

@ -99,7 +99,8 @@ public ArrayList<String> getSuperClasses(String type) {
@Override @Override
public void close() throws IOException { public void close() throws IOException {
cp.stream().forEach(IOHelper::close); cp.stream().forEach(IOHelper::close);
cp.clear();
} }
} }

View file

@ -17,13 +17,10 @@
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
public class StripLineNumbersTask implements LauncherBuildTask { public class StripLineNumbersTask implements LauncherBuildTask {
private final LaunchServer server; private final LaunchServer server;
private final ClassMetadataReader reader;
public StripLineNumbersTask(LaunchServer server) { public StripLineNumbersTask(LaunchServer server) {
this.server = server; this.server = server;
reader = new ClassMetadataReader();
} }
@Override @Override
@ -34,26 +31,27 @@ public String getName() {
@Override @Override
public Path process(Path inputFile) throws IOException { public Path process(Path inputFile) throws IOException {
Path out = server.dir.resolve(server.config.projectName + "-stripped.jar"); Path out = server.dir.resolve(server.config.projectName + "-stripped.jar");
reader.getCp().add(new JarFile(inputFile.toFile())); try (ClassMetadataReader reader = new ClassMetadataReader()) {
try (ZipInputStream input = IOHelper.newZipInput(inputFile); reader.getCp().add(new JarFile(inputFile.toFile()));
ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(out))) { try (ZipInputStream input = IOHelper.newZipInput(inputFile);
ZipEntry e = input.getNextEntry(); ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(out))) {
while (e != null) { ZipEntry e = input.getNextEntry();
String filename = e.getName(); while (e != null) {
output.putNextEntry(IOHelper.newZipEntry(e)); String filename = e.getName();
if (filename.endsWith(".class")) { output.putNextEntry(IOHelper.newZipEntry(e));
byte[] bytes = null; if (filename.endsWith(".class")) {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) { byte[] bytes = null;
IOHelper.transfer(input, outputStream); try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) {
bytes = outputStream.toByteArray(); IOHelper.transfer(input, outputStream);
} bytes = outputStream.toByteArray();
output.write(classFix(bytes, reader)); }
} else output.write(classFix(bytes, reader));
IOHelper.transfer(input, output); } else
e = input.getNextEntry(); IOHelper.transfer(input, output);
} e = input.getNextEntry();
} }
reader.close(); }
}
return out; return out;
} }