- Improve error-handling in file-compression.
- Update dependencies.
This commit is contained in:
parent
2895668417
commit
18cc9e0e68
|
@ -1,5 +1,5 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'org.springframework.boot' version '2.7.15'
|
id 'org.springframework.boot' version '2.7.16'
|
||||||
id 'io.spring.dependency-management' version '1.1.3'
|
id 'io.spring.dependency-management' version '1.1.3'
|
||||||
id 'java'
|
id 'java'
|
||||||
}
|
}
|
||||||
|
@ -44,11 +44,11 @@ dependencies {
|
||||||
// https://mvnrepository.com/artifact/com.google.code.gson/gson
|
// https://mvnrepository.com/artifact/com.google.code.gson/gson
|
||||||
implementation 'com.google.code.gson:gson:2.10.1'
|
implementation 'com.google.code.gson:gson:2.10.1'
|
||||||
|
|
||||||
implementation("org.apache.commons:commons-compress:1.23.0") {
|
implementation("org.apache.commons:commons-compress:1.24.0") {
|
||||||
exclude group: 'com.github.luben', module: 'zstd-jni'
|
exclude group: 'com.github.luben', module: 'zstd-jni'
|
||||||
}
|
}
|
||||||
implementation 'com.github.luben:zstd-jni:1.5.5-5' // Even though this is part of the above dependency, the Apache commons rarely updates it, while the zstd team makes improvements very often.
|
implementation 'com.github.luben:zstd-jni:1.5.5-6' // Even though this is part of the above dependency, the Apache commons rarely updates it, while the zstd team makes improvements very often.
|
||||||
// Also, for compressing, we strangely need it, otherwise it does not work.
|
// Also, for compressing, we strangely need it to be explicitly declared independently, otherwise it does not work.
|
||||||
|
|
||||||
testImplementation 'org.springframework.security:spring-security-test'
|
testImplementation 'org.springframework.security:spring-security-test'
|
||||||
testImplementation "org.springframework.boot:spring-boot-starter-test"
|
testImplementation "org.springframework.boot:spring-boot-starter-test"
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -85,7 +86,9 @@ public class FilesCompressor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( numTarredFiles != filesToTar.size() )
|
if ( numTarredFiles == 0 ) {
|
||||||
|
throw new RuntimeException("None of the requested (" + filesToTar.size() + ") could be tarred, for assignments_" + assignmentsCounter + ", batch_" + tarBatchCounter);
|
||||||
|
} else if ( numTarredFiles != filesToTar.size() )
|
||||||
logger.warn("The number of \"numTarredFiles\" (" + numTarredFiles + ") is different from the number of files requested to be tarred (" + filesToTar.size() + "), for assignments_" + assignmentsCounter + ", batch_" + tarBatchCounter);
|
logger.warn("The number of \"numTarredFiles\" (" + numTarredFiles + ") is different from the number of files requested to be tarred (" + filesToTar.size() + "), for assignments_" + assignmentsCounter + ", batch_" + tarBatchCounter);
|
||||||
// Still, some files may have been tarred, so we move on. It's up to the Controller, to handle such case.
|
// Still, some files may have been tarred, so we move on. It's up to the Controller, to handle such case.
|
||||||
|
|
||||||
|
@ -98,8 +101,7 @@ public class FilesCompressor {
|
||||||
boolean shouldCloseEntry = false; // Useful in order to know if we should close the entry (an Exception may appear when initializing the stream, and so we should not try to close it).
|
boolean shouldCloseEntry = false; // Useful in order to know if we should close the entry (an Exception may appear when initializing the stream, and so we should not try to close it).
|
||||||
|
|
||||||
Path fullFileNamePath = Paths.get(baseDir + fileName);
|
Path fullFileNamePath = Paths.get(baseDir + fileName);
|
||||||
try ( BufferedInputStream fis = new BufferedInputStream(Files.newInputStream(fullFileNamePath), bufferSize) )
|
try ( BufferedInputStream fis = new BufferedInputStream(Files.newInputStream(fullFileNamePath), bufferSize) ) {
|
||||||
{
|
|
||||||
TarArchiveEntry entry = new TarArchiveEntry(fileName);
|
TarArchiveEntry entry = new TarArchiveEntry(fileName);
|
||||||
entry.setSize(Files.size(fullFileNamePath)); // Yes, tar requires that we set the size beforehand..
|
entry.setSize(Files.size(fullFileNamePath)); // Yes, tar requires that we set the size beforehand..
|
||||||
taos.putArchiveEntry(entry);
|
taos.putArchiveEntry(entry);
|
||||||
|
@ -109,6 +111,9 @@ public class FilesCompressor {
|
||||||
while ( (readByte = fis.read()) != -1 ) {
|
while ( (readByte = fis.read()) != -1 ) {
|
||||||
taos.write(readByte);
|
taos.write(readByte);
|
||||||
}
|
}
|
||||||
|
} catch (NoSuchFileException nsfe) {
|
||||||
|
logger.error("NoSuchFileException: " + nsfe.getMessage());
|
||||||
|
return false;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue