Skip to content

Commit

Permalink
Use buffered streams for exporting
Browse files Browse the repository at this point in the history
  • Loading branch information
xxDark committed Jun 20, 2021
1 parent 56c3b78 commit 994a183
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -3,7 +3,7 @@
<groupId>me.coley</groupId>
<artifactId>recaf</artifactId>
<url>https://github.com/Col-E/Recaf/</url>
<version>2.20.1</version>
<version>2.20.2</version>
<name>Recaf</name>
<description>A modern java bytecode editor</description>
<!-- Variables -->
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/coley/recaf/Recaf.java
Expand Up @@ -31,7 +31,7 @@
* @author Matt
*/
public class Recaf {
public static final String VERSION = "2.20.1";
public static final String VERSION = "2.20.2";
public static final String DOC_URL = "https://col-e.github.io/Recaf-documentation/";
public static final int ASM_VERSION = Opcodes.ASM9;
private static Controller currentController;
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/me/coley/recaf/command/impl/Export.java
Expand Up @@ -125,11 +125,11 @@ public static void writeDirectory(File output, Map<String, byte[]> content) thro
*/
public static void writeArchive(File output, Map<String, byte[]> content) throws IOException {
String extension = IOUtil.getExtension(output.toPath());
// Build file structure in memory
// Use buffered streams
// See https://github.com/Col-E/Recaf/issues/391
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
try (ZipOutputStream jos = ("zip".equals(extension)) ? new ZipOutputStream(bytes) :
/* Let's assume it's a jar */ new JarOutputStream(bytes)) {
OutputStream os = new BufferedOutputStream(Files.newOutputStream(output.toPath()), 1048576);
try (ZipOutputStream jos = ("zip".equals(extension)) ? new ZipOutputStream(os) :
/* Let's assume it's a jar */ new JarOutputStream(os)) {
PluginsManager pluginsManager = PluginsManager.getInstance();
Set<String> dirsVisited = new HashSet<>();
// Contents is iterated in sorted order (because 'archiveContent' is TreeMap).
Expand Down Expand Up @@ -164,7 +164,6 @@ public static void writeArchive(File output, Map<String, byte[]> content) throws
jos.closeEntry();
}
}
Files.write(output.toPath(), bytes.toByteArray());
}

private void put(Map<String, byte[]> content, JavaResource res) {
Expand Down

0 comments on commit 994a183

Please sign in to comment.