This commit is contained in:
Looly
2024-03-12 00:25:48 +08:00
parent 65b9a047ea
commit fe9e8bad84
7 changed files with 60 additions and 81 deletions

View File

@@ -74,6 +74,10 @@
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>commons-lang3</artifactId>
<groupId>org.apache.commons</groupId>
</exclusion>
</exclusions>
<optional>true</optional>
</dependency>
@@ -106,6 +110,10 @@
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>commons-io</artifactId>
<groupId>commons-io</groupId>
</exclusion>
</exclusions>
<optional>true</optional>
</dependency>
@@ -496,7 +504,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.26.0</version>
<version>1.26.1</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@@ -55,7 +55,8 @@ public class SevenZExtractor implements Extractor, RandomAccess {
*/
public SevenZExtractor(final File file, final char[] password) {
try {
this.sevenZFile = new SevenZFile(file, password);
this.sevenZFile = SevenZFile.builder()
.setFile(file).setPassword(password).get();
} catch (final IOException e) {
throw new IORuntimeException(e);
}
@@ -97,7 +98,8 @@ public class SevenZExtractor implements Extractor, RandomAccess {
*/
public SevenZExtractor(final SeekableByteChannel channel, final char[] password) {
try {
this.sevenZFile = new SevenZFile(channel, password);
this.sevenZFile = SevenZFile.builder()
.setSeekableByteChannel(channel).setPassword(password).get();
} catch (final IOException e) {
throw new IORuntimeException(e);
}
@@ -160,7 +162,7 @@ public class SevenZExtractor implements Extractor, RandomAccess {
} else if (entry.hasStream()) {
// 读取entry对应数据流
// 此处直接读取而非调用sevenZFile.getInputStream(entry)因为此方法需要遍历查找entry对应位置性能不好。
FileUtil.writeFromStream(new Seven7EntryInputStream(sevenZFile, entry), outItemFile);
FileUtil.copy(new Seven7EntryInputStream(sevenZFile, entry), outItemFile);
} else {
// 无数据流的文件创建为空文件
FileUtil.touch(outItemFile);

View File

@@ -39,7 +39,7 @@ import java.util.function.Predicate;
*/
public class StreamExtractor implements Extractor {
private final ArchiveInputStream in;
private final ArchiveInputStream<?> in;
/**
* 构造
@@ -81,7 +81,7 @@ public class StreamExtractor implements Extractor {
*/
public StreamExtractor(final Charset charset, final String archiverName, InputStream in) {
if (in instanceof ArchiveInputStream) {
this.in = (ArchiveInputStream) in;
this.in = (ArchiveInputStream<?>) in;
return;
}
@@ -109,7 +109,7 @@ public class StreamExtractor implements Extractor {
@Override
public InputStream getFirst(final Predicate<ArchiveEntry> predicate) {
final ArchiveInputStream in = this.in;
final ArchiveInputStream<?> in = this.in;
ArchiveEntry entry;
try {
while (null != (entry = in.getNextEntry())) {
@@ -156,7 +156,7 @@ public class StreamExtractor implements Extractor {
*/
private void extractInternal(final File targetDir, final Predicate<ArchiveEntry> predicate) throws IOException {
Assert.isTrue(null != targetDir && ((!targetDir.exists()) || targetDir.isDirectory()), "target must be dir.");
final ArchiveInputStream in = this.in;
final ArchiveInputStream<?> in = this.in;
ArchiveEntry entry;
File outItemFile;
while (null != (entry = in.getNextEntry())) {
@@ -173,7 +173,7 @@ public class StreamExtractor implements Extractor {
//noinspection ResultOfMethodCallIgnored
outItemFile.mkdirs();
} else {
FileUtil.writeFromStream(in, outItemFile, false);
FileUtil.copy(in, outItemFile);
}
}
}