Skip to content

Commit 6998438

Browse files
tomas-sexenianBeta Bot
authored andcommitted
Cherry pick branch 'genexuslabs:Compress' into beta
1 parent b99739c commit 6998438

File tree

6 files changed

+329
-157
lines changed

6 files changed

+329
-157
lines changed

gxcompress/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
<artifactId>xz</artifactId>
2424
<version>1.9</version>
2525
</dependency>
26+
<dependency>
27+
<groupId>com.github.junrar</groupId>
28+
<artifactId>junrar</artifactId>
29+
<version>7.5.5</version>
30+
</dependency>
2631
<dependency>
2732
<groupId>org.apache.logging.log4j</groupId>
2833
<artifactId>log4j-core</artifactId>
@@ -38,6 +43,12 @@
3843
<artifactId>gxcommon</artifactId>
3944
<version>${project.version}</version>
4045
</dependency>
46+
<dependency>
47+
<groupId>com.genexus</groupId>
48+
<artifactId>gxclassR</artifactId>
49+
<version>${project.version}</version>
50+
<scope>test</scope>
51+
</dependency>
4152
</dependencies>
4253

4354
</project>
Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
package com.genexus.compression;
22

3+
import com.genexus.GXBaseCollection;
4+
import com.genexus.SdtMessages_Message;
35
import org.apache.logging.log4j.Logger;
46

5-
import java.io.File;
7+
import java.io.IOException;
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
import java.nio.file.Paths;
611
import java.util.ArrayList;
7-
import java.util.List;
8-
import java.util.Vector;
12+
import java.util.stream.Stream;
913

1014
public class Compression {
1115
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(Compression.class);
1216

1317
private String path;
1418
private String format;
15-
private List<File> filesToCompress;
19+
private GXBaseCollection<SdtMessages_Message>[] messages;
20+
private ArrayList<String> filesToCompress;
1621

1722
public Compression() {}
1823

19-
public Compression(String path, String format) {
24+
public Compression(String path, String format, GXBaseCollection<SdtMessages_Message>[] messages) {
2025
this.path = path;
2126
this.format = format;
22-
this.filesToCompress = new ArrayList<>();
27+
this.messages = messages;
28+
filesToCompress = new ArrayList<>();
2329
}
2430

2531
public void setPath(String path) {
@@ -31,48 +37,26 @@ public void setFormat(String format) {
3137
}
3238

3339
public void addFile(String filePath) {
34-
File file = new File(filePath);
35-
if (file.exists()) {
36-
filesToCompress.add(file);
37-
} else {
38-
log.error("File does not exist: {}", file.getAbsolutePath());
39-
}
40+
filesToCompress.add(filePath);
4041
}
4142

4243
public void addFolder(String folderPath) {
43-
File folder = new File(folderPath);
44-
if (folder.exists() && folder.isDirectory()) {
45-
File[] files = folder.listFiles();
46-
if (files != null) {
47-
for (File file : files) {
48-
if (file.isDirectory()) {
49-
addFolder(file.getAbsolutePath());
50-
} else {
51-
addFile(file.getAbsolutePath());
52-
}
53-
}
54-
}
55-
} else {
56-
log.error("Folder does not exist or is not a directory: {}", folder.getAbsolutePath());
44+
Path path = Paths.get(folderPath);
45+
try (Stream<Path> stream = Files.walk(path)) {
46+
stream.filter(Files::isRegularFile)
47+
.forEach(p -> addFile(p.toAbsolutePath().toString()));
48+
} catch (IOException e) {
49+
log.error("Failed to process directory: {}", folderPath, e);
5750
}
5851
}
5952

60-
public int save() {
61-
if (filesToCompress.isEmpty()) {
62-
log.error("No files have been added for compression.");
63-
return -4;
64-
}
65-
Vector<String> paths = new Vector<>();
66-
for (File file : filesToCompress) {
67-
paths.add(file.getPath());
68-
}
69-
return GXCompressor.compressFiles(paths, path, format);
53+
public Boolean save() {
54+
return GXCompressor.compressFiles(filesToCompress, path, format, messages);
7055
}
7156

72-
7357
public void clear() {
74-
this.path = "";
75-
this.format = "";
76-
this.filesToCompress = new ArrayList<>();
58+
path = "";
59+
format = "";
60+
filesToCompress = new ArrayList<>();
7761
}
78-
}
62+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.genexus.compression;
22

33
public enum CompressionFormat {
4-
GZIP,TAR, ZIP, SEVENZ
4+
GZIP,TAR, ZIP, SEVENZ, JAR
55
}

0 commit comments

Comments
 (0)