parent
a1f750a0aa
commit
d6e94912a4
|
@ -1,5 +1,5 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'org.springframework.boot' version '2.6.6'
|
id 'org.springframework.boot' version '2.7.0'
|
||||||
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
|
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
|
||||||
id 'java'
|
id 'java'
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ dependencies {
|
||||||
implementation("org.springframework.security:spring-security-config")
|
implementation("org.springframework.security:spring-security-config")
|
||||||
//implementation("io.jsonwebtoken:jjwt:0.9.1") // Use this in case we use auth-tokens later on.
|
//implementation("io.jsonwebtoken:jjwt:0.9.1") // Use this in case we use auth-tokens later on.
|
||||||
|
|
||||||
implementation "org.projectlombok:lombok:1.18.22"
|
implementation 'org.projectlombok:lombok:1.18.24'
|
||||||
|
|
||||||
// Enable the validation annotations.
|
// Enable the validation annotations.
|
||||||
//implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
|
//implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
|
||||||
|
|
|
@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
@ -22,7 +23,7 @@ public class FilesZipper
|
||||||
|
|
||||||
int numZippedFiles = 0;
|
int numZippedFiles = 0;
|
||||||
File zipFile = new File(zipFilename);
|
File zipFile = new File(zipFilename);
|
||||||
try ( ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile), StandardCharsets.UTF_8) )
|
try ( ZipOutputStream zos = new ZipOutputStream(Files.newOutputStream(zipFile.toPath()), StandardCharsets.UTF_8) )
|
||||||
{
|
{
|
||||||
for ( String file : filesToZip ) {
|
for ( String file : filesToZip ) {
|
||||||
if ( zipAFile(file, zos, baseDirectory) )
|
if ( zipAFile(file, zos, baseDirectory) )
|
||||||
|
@ -37,20 +38,16 @@ public class FilesZipper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final int BUFFER_SIZE = 3145728; // 3MB (average fullText-size)
|
private static boolean zipAFile(String fileName, ZipOutputStream zos, String baseDir)
|
||||||
private static final byte[] dataBuffer = new byte[BUFFER_SIZE];
|
|
||||||
|
|
||||||
// This method is "synchronized" to avoid any future problems with shared-buffer, if the requests are asynchronous.
|
|
||||||
private static synchronized boolean zipAFile(String fileName, ZipOutputStream zos, String baseDir)
|
|
||||||
{
|
{
|
||||||
boolean shouldCloseEntry = false; // Useful in order to close the entry in case of an exception.
|
boolean shouldCloseEntry = false; // Useful in order to know if we should close the entry (an Exception may appear, and so we should not try to close it).
|
||||||
String fullFileName = baseDir + fileName;
|
String fullFileName = baseDir + fileName;
|
||||||
try ( BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fullFileName), BUFFER_SIZE) ) {
|
try (FileInputStream fis = new FileInputStream(fullFileName)) {
|
||||||
zos.putNextEntry(new ZipEntry(fileName));
|
zos.putNextEntry(new ZipEntry(fileName));
|
||||||
shouldCloseEntry = true;
|
shouldCloseEntry = true;
|
||||||
int count;
|
int readByte;
|
||||||
while ( (count = bis.read(dataBuffer, 0, BUFFER_SIZE)) != -1 ) {
|
while ( (readByte = fis.read()) != -1 ) {
|
||||||
zos.write(dataBuffer, 0, count);
|
zos.write(readByte);
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException fnfe) {
|
} catch (FileNotFoundException fnfe) {
|
||||||
logger.error("Error zipping file: " + fullFileName, fnfe.getMessage());
|
logger.error("Error zipping file: " + fullFileName, fnfe.getMessage());
|
||||||
|
|
|
@ -26,7 +26,6 @@ public class UriBuilder {
|
||||||
sslEnabled = "false";
|
sslEnabled = "false";
|
||||||
}
|
}
|
||||||
baseUrl += sslEnabled.equals("true") ? "s" : "";
|
baseUrl += sslEnabled.equals("true") ? "s" : "";
|
||||||
|
|
||||||
baseUrl += "://";
|
baseUrl += "://";
|
||||||
|
|
||||||
String hostName = getPublicIP();
|
String hostName = getPublicIP();
|
||||||
|
|
Loading…
Reference in New Issue