Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.junrar:junrar:7.5.5'
}
dependencies {
implementation("com.github.junrar:junrar:7.5.5")
}
<dependency>
<groupId>com.github.junrar</groupId>
<artifactId>junrar</artifactId>
<version>7.5.5</version>
</dependency>
libraryDependencies += "com.github.junrar" % "junrar" % "7.5.5"
:dependencies [[com.github.junrar/junrar "7.5.5"]]
Read and extracts from a .rar file. This is a fork of the junrar codebase, formerly on sourceforge.
Code may not be used to develop a RAR (WinRAR) compatible archiver.
File
and InputStream
File
and OutputStream
implementation "com.github.junrar:junrar:{version}"
implementation("com.github.junrar:junrar:{version}")
<dependency>
<groupId>com.github.junrar</groupId>
<artifactId>junrar</artifactId>
<version>{version}</version>
</dependency>
where {version}
corresponds to version as below:
Apache Commons VFS support has been removed from 5.0.0
, and moved to a dedicated repo: https://github.com/junrar/commons-vfs-rar
Junrar.extract("/tmp/foo.rar", "/tmp");
//or
final File rar = new File("foo.rar");
final File destinationFolder = new File("destinationFolder");
Junrar.extract(rar, destinationFolder);
//or
final InputStream resourceAsStream = Foo.class.getResourceAsStream("foo.rar");//only for a single rar file
Junrar.extract(resourceAsStream, tempFolder);
// Assuming you already have an InputStream from the rar file and an OutputStream for writing to
final Archive archive = new Archive(inputStream);
while (true) {
FileHeader fileHeader = archive.nextFileHeader();
if (fileHeader == null) {
break;
}
archive.extractFile(fileHeader, outputStream);
}
// Assuming you already have an InputStream from the rar file and an OutputStream for writing to
final Archive archive = new Archive(inputStream);
while (true) {
FileHeader fileHeader = archive.nextFileHeader();
if (fileHeader == null) {
break;
}
try (InputStream is = archive.getInputStream(fileHeader)) {
// Then use the InputStream for any method that uses that as an input, ex.:
Files.copy(is, Paths.get("destinationFile.txt"));
}
}
final List<ContentDescription> contentDescriptions = Junrar.getContentsDescription(testDocuments);
Junrar.extract("/tmp/foo.rar", "/tmp", "password");
//or
final File rar = new File("foo.rar");
final File destinationFolder = new File("destinationFolder");
Junrar.extract(rar, destinationFolder, "password");
//or
final InputStream resourceAsStream = Foo.class.getResourceAsStream("foo.rar");//only for a single rar file
Junrar.extract(resourceAsStream, tempFolder, "password");
Junrar.extract("/tmp/foo.001.rar", "/tmp");
Junrar allows for some tuning using System Properties:
Archive#getInputStream(FileHeader)
:
junrar.extractor.buffer-size
: accepts any positive integer. Defaults to 32 * 1024
.
PipedInputStream
.junrar.extractor.use-executor
: accepts either true
or false
. Defaults to true
.
true
, it uses a cached thread pool for extracting the contents, which is generally faster.false
, it will create a new thread on each call. This may be slower, but may require slightly less memory.junrar.extractor.max-threads
: accepts any positive integer. Defaults to 2^31
.
junrar.extractor.thread-keep-alive-seconds
: accepts any positive integer. Defaults to 5
.