Skip to content

Commit

Permalink
ZIP to GZIP
Browse files Browse the repository at this point in the history
Signed-off-by: Thang PHAM <[email protected]>
  • Loading branch information
thangqp committed Nov 15, 2024
1 parent 85a0baa commit f295c86
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
23 changes: 9 additions & 14 deletions src/main/java/org/gridsuite/ds/server/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
Expand Down Expand Up @@ -94,14 +93,13 @@ public static Property convertProperty(BasicProperty property) {
public static byte[] zip(Path filePath) {
try (InputStream is = Files.newInputStream(filePath);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ZipOutputStream zipOs = new ZipOutputStream(os)) {
zipOs.putNextEntry(new ZipEntry(filePath.getFileName().toString()));
GZIPOutputStream zipOs = new GZIPOutputStream(os)) {
byte[] buffer = new byte[1024];
int length;
while ((length = is.read(buffer)) > 0) {
zipOs.write(buffer, 0, length);
}
zipOs.closeEntry();
zipOs.finish();
return os.toByteArray();
} catch (IOException e) {
throw new UncheckedIOException("Error occurred while zipping the file " + filePath.toAbsolutePath(), e);
Expand All @@ -111,14 +109,11 @@ public static byte[] zip(Path filePath) {
public static void unzip(byte[] zippedBytes, Path filePath) {
try (ByteArrayInputStream is = new ByteArrayInputStream(zippedBytes);
FileOutputStream fos = new FileOutputStream(new File(filePath.toUri()));
ZipInputStream zipIs = new ZipInputStream(is)) {
if (zipIs.getNextEntry() != null) {
byte[] buffer = new byte[1024];
int length;
while ((length = zipIs.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
zipIs.closeEntry();
GZIPInputStream zipIs = new GZIPInputStream(is)) {
byte[] buffer = new byte[1024];
int length;
while ((length = zipIs.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
} catch (IOException e) {
throw new UncheckedIOException("Error occurred while unzipping a zipped content to the file " + filePath.toAbsolutePath(), e);
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ server:
spring:
rabbitmq:
addresses: localhost
port: 5672

powsybl-ws:
database:
Expand Down

0 comments on commit f295c86

Please sign in to comment.