Skip to content

Commit

Permalink
Save a few I/O operations
Browse files Browse the repository at this point in the history
  • Loading branch information
andrebrait committed Feb 22, 2022
1 parent d0d0276 commit 930ae15
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ Currently, DATROMTool supports:

DATROMTool can work with the following archive formats:

| Archive format | Read | Write |
|----------------|------|-------|
| Zip |||
| RAR |* ||
| 7z |||
| TAR |||
| Format | Read | Write |
|--------|------|-------|
| Zip |||
| RAR |* ||
| 7z |||
| TAR |||

- RAR up to version 4 is natively supported
- RAR 5 is supported through external executables
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/io/github/datromtool/io/FileCopier.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,18 @@ private void copy(CopySpec spec) {
listener.reportStart(index, spec.getFrom(), spec.getTo(), 1);
}
try {
BasicFileAttributes fromAttrib = Files.readAttributes(spec.getFrom(), BasicFileAttributes.class);
try (InputStream inputStream = Files.newInputStream(spec.getFrom())) {
try (OutputStream outputStream = Files.newOutputStream(spec.getTo())) {
copyWithProgress(
index,
Files.size(spec.getFrom()),
fromAttrib.size(),
spec.getFrom(),
spec.getTo(),
inputStream::read,
outputStream::write);
}
}
BasicFileAttributes fromAttrib = Files.readAttributes(spec.getFrom(), BasicFileAttributes.class);
BasicFileAttributeView toAttrib = Files.getFileAttributeView(spec.getTo(), BasicFileAttributeView.class);
toAttrib.setTimes(fromAttrib.lastModifiedTime(), fromAttrib.lastAccessTime(), fromAttrib.creationTime());
} catch (Exception e) {
Expand Down Expand Up @@ -390,7 +390,7 @@ private void copy(ArchiveCopySpec spec) {
}
} catch (UnsupportedRarV5Exception e) {
log.error(
"Could not copy contents of '{}' to '{}'. RAR5 is not supported yet",
"Could not copy contents of '{}' to '{}'. RAR5 is not natively supported yet.",
spec.getFrom(),
spec.getTo());
for (Listener listener : listeners) {
Expand Down Expand Up @@ -613,7 +613,7 @@ private void compressZipEntries(CompressionSpec spec, int index) throws IOExcept
zipArchiveOutputStream.putArchiveEntry(archiveEntry);
copyWithProgress(
index,
Files.size(source),
fromAttrib.size(),
source,
destination,
inputStream::read,
Expand Down Expand Up @@ -643,7 +643,7 @@ private void compressSevenZipEntries(CompressionSpec spec, int index) throws IOE
sevenZOutputFile.putArchiveEntry(archiveEntry);
copyWithProgress(
index,
Files.size(source),
fromAttrib.size(),
source,
destination,
inputStream::read,
Expand Down Expand Up @@ -674,7 +674,7 @@ private void compressTarEntries(CompressionSpec spec, int index) throws IOExcept
tarOutputStream.putArchiveEntry(archiveEntry);
copyWithProgress(
index,
Files.size(source),
archiveEntry.getSize(),
source,
destination,
inputStream::read,
Expand Down
13 changes: 5 additions & 8 deletions core/src/test/java/io/github/datromtool/util/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ public static Game createGame(String s) {

public static RegionData getRegionByCode(RegionData regionData, String code, String... codes) {
List<String> codeList = Arrays.asList(codes);
return RegionData.builder().regions(regionData.getRegions()
.stream()
.filter(r -> code.equals(r.getCode()) || codeList.contains(r.getCode()))
.collect(ImmutableSet.toImmutableSet()))
return RegionData.builder()
.regions(regionData.getRegions()
.stream()
.filter(r -> code.equals(r.getCode()) || codeList.contains(r.getCode()))
.collect(ImmutableSet.toImmutableSet()))
.build();
}

Expand All @@ -48,8 +49,4 @@ public static String getFilename(FileScanner.Result i) {
: i.getPath().getFileName().toString();
}

public static String getUnheaderedFilename(FileScanner.Result i) {
return getFilename(i).replace("headered-", "");
}

}

0 comments on commit 930ae15

Please sign in to comment.