Skip to content

Commit b6eb9f5

Browse files
Add support for decompressing rar files
1 parent bab7cce commit b6eb9f5

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

gxcompress/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
<artifactId>xz</artifactId>
2424
<version>1.9</version>
2525
</dependency>
26+
<dependency>
27+
<groupId>com.github.junrar</groupId>
28+
<artifactId>junrar</artifactId>
29+
<version>7.5.5</version>
30+
</dependency>
2631
<dependency>
2732
<groupId>org.apache.logging.log4j</groupId>
2833
<artifactId>log4j-core</artifactId>

gxcompress/src/main/java/com/genexus/compression/GXCompressor.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
1313
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
1414
import org.apache.commons.io.IOUtils;
15+
import com.github.junrar.Junrar;
16+
import com.github.junrar.exception.RarException;
1517

1618
import java.io.*;
1719
import java.nio.file.Files;
@@ -112,6 +114,9 @@ public static int decompress(String file, String path) {
112114
case "jar":
113115
decompressJar(toCompress, path);
114116
return 0;
117+
case "rar":
118+
decompressRar(toCompress, path);
119+
return 0;
115120
default:
116121
log.error("Unsupported compression format for decompression: {}", extension);
117122
return -3;
@@ -421,6 +426,10 @@ public static void decompressJar(File jarFile, String outputPath) throws IOExcep
421426
}
422427
}
423428

429+
public static void decompressRar(File rarFile, String destinationPath) throws RarException, IOException{
430+
Junrar.extract(rarFile, new File(destinationPath));
431+
}
432+
424433
private static CompressionFormat getCompressionFormat(String format) {
425434
try {
426435
return CompressionFormat.valueOf(format.toUpperCase());

0 commit comments

Comments
 (0)