38
38
import org .apache .commons .io .FilenameUtils ;
39
39
import org .apache .commons .io .IOUtils ;
40
40
41
- import java .io .FileNotFoundException ;
42
41
import java .io .IOException ;
43
- import java .io .InputStream ;
44
42
import java .io .OutputStream ;
45
43
import java .nio .file .Files ;
46
44
import java .nio .file .Path ;
57
55
import java .util .Set ;
58
56
import java .util .stream .Collectors ;
59
57
60
- import static ru .olegcherednik .zip4jvm .utils .ValidationUtils .requireNotBlank ;
61
-
62
58
/**
63
59
* @author Oleg Cherednik
64
60
* @since 22.12.2024
@@ -76,13 +72,7 @@ public void extract(Path dstDir, Collection<String> fileNames) throws IOExceptio
76
72
}
77
73
78
74
public ZipFile .Entry extract (String fileName ) throws IOException {
79
- requireNotBlank (fileName , "UnzipIt.fileName" );
80
-
81
75
ZipEntry zipEntry = zipModel .getZipEntryByFileName (ZipUtils .normalizeFileName (fileName ));
82
-
83
- if (zipEntry == null )
84
- throw new FileNotFoundException ("Entry '" + fileName + "' was not found" );
85
-
86
76
zipEntry .setPassword (passwordProvider .getFilePassword (zipEntry .getFileName ()));
87
77
return zipEntry .createImmutableEntry ();
88
78
}
@@ -97,25 +87,25 @@ protected Map<String, String> getEntriesByPrefix(Set<String> fileNames) {
97
87
ZipEntry zipEntry = zipModel .getZipEntryByFileName (entryName );
98
88
map .put (entryName , FilenameUtils .getName (zipEntry .getFileName ()));
99
89
} else {
100
- for (ZipEntry zipEntry : getEntriesNamesByPrefix (entryName + '/' ))
90
+ for (ZipEntry zipEntry : getEntriesByPrefix (entryName + '/' ))
101
91
map .put (zipEntry .getFileName (), zipEntry .getFileName ());
102
92
}
103
93
}
104
94
105
95
return map .isEmpty () ? Collections .emptyMap () : Collections .unmodifiableMap (map );
106
96
}
107
97
108
- protected List <ZipEntry > getEntriesNamesByPrefix (String fileNamePrefix ) {
98
+ protected List <ZipEntry > getEntriesByPrefix (String prefix ) {
109
99
return zipModel .getZipEntries ().stream ()
110
- .filter (entry -> entry .getFileName ().startsWith (fileNamePrefix ))
100
+ .filter (entry -> entry .getFileName ().startsWith (prefix ))
111
101
.collect (Collectors .toList ());
112
102
}
113
103
114
104
// ----------
115
105
116
106
protected void extractEntry (Path dstDir , Map <String , String > map ) throws IOException {
117
107
try (ConsecutiveAccessDataInput in = createConsecutiveDataInput (zipModel .getSrcZip ())) {
118
- Iterator <ZipEntry > it = zipModel .offsAscIterator ();
108
+ Iterator <ZipEntry > it = zipModel .absOffsAscIterator ();
119
109
120
110
while (it .hasNext ()) {
121
111
ZipEntry zipEntry = it .next ();
@@ -147,7 +137,7 @@ else if (zipEntry.isDirectory())
147
137
}
148
138
149
139
protected static void extractSymlink (Path symlink , ZipEntry zipEntry , DataInput in ) throws IOException {
150
- String target = IOUtils .toString (zipEntry .createInputStream (), Charsets .UTF_8 );
140
+ String target = IOUtils .toString (zipEntry .createInputStream (in ), Charsets .UTF_8 );
151
141
152
142
if (target .startsWith ("/" ))
153
143
ZipSymlinkEngine .createAbsoluteSymlink (symlink , Paths .get (target ));
@@ -162,22 +152,10 @@ protected static void extractEmptyDirectory(Path dir) throws IOException {
162
152
Files .createDirectories (dir );
163
153
}
164
154
165
- @ SuppressWarnings ("PMD.CloseResource" )
166
- protected void extractRegularFile (Path file , ZipEntry zipEntry , DataInput di ) throws IOException {
155
+ protected void extractRegularFile (Path file , ZipEntry zipEntry , DataInput in ) throws IOException {
167
156
String fileName = ZipUtils .getFileNameNoDirectoryMarker (zipEntry .getFileName ());
168
157
zipEntry .setPassword (passwordProvider .getFilePassword (fileName ));
169
-
170
- InputStream in = zipEntry .createInputStream (di );
171
-
172
- // if (zipEntry.getAesVersion() != AesVersion.AE_2) {
173
- // in = ChecksumCheckDataInput.builder()
174
- // .setExpectedChecksumValue(zipEntry.getChecksum())
175
- // .setChecksum(new PureJavaCrc32())
176
- // .setInputStream(in)
177
- // .get();
178
- // }
179
-
180
- ZipUtils .copyLarge (in , getOutputStream (file ));
158
+ ZipUtils .copyLarge (zipEntry .createInputStream (in ), getOutputStream (file ));
181
159
}
182
160
183
161
protected static void setFileAttributes (Path path , ZipEntry zipEntry ) throws IOException {
0 commit comments