31
31
import ru .olegcherednik .zip4jvm .model .password .PasswordProvider ;
32
32
import ru .olegcherednik .zip4jvm .model .src .SrcZip ;
33
33
import ru .olegcherednik .zip4jvm .utils .ZipUtils ;
34
+ import ru .olegcherednik .zip4jvm .utils .quitely .Quietly ;
34
35
import ru .olegcherednik .zip4jvm .utils .time .DosTimestampConverterUtils ;
35
36
36
37
import lombok .RequiredArgsConstructor ;
@@ -105,31 +106,31 @@ protected List<ZipEntry> getEntriesByPrefix(String prefix) {
105
106
.collect (Collectors .toList ());
106
107
}
107
108
108
- // ----------
109
-
110
109
protected void extractEntry (Path dstDir , Map <String , String > map ) {
111
- try (ConsecutiveAccessDataInput in = createConsecutiveDataInput (zipModel . getSrcZip () )) {
110
+ try (ConsecutiveAccessDataInput in = createConsecutiveDataInput ()) {
112
111
Iterator <ZipEntry > it = zipModel .absOffsAscIterator ();
113
112
114
113
while (it .hasNext ()) {
115
114
ZipEntry zipEntry = it .next ();
116
115
117
- if (map == null || map .containsKey (zipEntry .getFileName ())) {
118
- in .seekForward (zipEntry .getLocalFileHeaderAbsOffs ());
116
+ if (map != null && !map .containsKey (zipEntry .getFileName ()))
117
+ continue ;
118
+
119
+ String fileName = Optional .ofNullable (map )
120
+ .map (m -> m .get (zipEntry .getFileName ()))
121
+ .orElse (zipEntry .getFileName ());
122
+ Path file = dstDir .resolve (fileName );
119
123
120
- String fileName = Optional .ofNullable (map )
121
- .map (m -> m .get (zipEntry .getFileName ()))
122
- .orElse (zipEntry .getFileName ());
123
- Path file = dstDir .resolve (fileName );
124
- extractEntry (file , zipEntry , in );
125
- }
124
+ extractEntry (file , zipEntry , in );
126
125
}
127
126
} catch (IOException e ) {
128
127
throw new Zip4jvmException (e );
129
128
}
130
129
}
131
130
132
- protected void extractEntry (Path file , ZipEntry zipEntry , DataInput in ) throws IOException {
131
+ protected void extractEntry (Path file , ZipEntry zipEntry , ConsecutiveAccessDataInput in ) throws IOException {
132
+ in .seekForward (zipEntry .getLocalFileHeaderAbsOffs ());
133
+
133
134
if (zipEntry .isSymlink ())
134
135
extractSymlink (file , zipEntry , in );
135
136
else if (zipEntry .isDirectory ())
@@ -142,7 +143,7 @@ else if (zipEntry.isDirectory())
142
143
setFileLastModifiedTime (file , zipEntry );
143
144
}
144
145
145
- protected static void extractSymlink (Path symlink , ZipEntry zipEntry , DataInput in ) throws IOException {
146
+ protected void extractSymlink (Path symlink , ZipEntry zipEntry , DataInput in ) throws IOException {
146
147
String target = IOUtils .toString (zipEntry .createInputStream (in ), Charsets .UTF_8 );
147
148
148
149
if (target .startsWith ("/" ))
@@ -154,7 +155,7 @@ else if (target.contains(":"))
154
155
ZipSymlinkEngine .createRelativeSymlink (symlink , symlink .getParent ().resolve (target ));
155
156
}
156
157
157
- protected static void extractEmptyDirectory (Path dir ) throws IOException {
158
+ protected void extractEmptyDirectory (Path dir ) throws IOException {
158
159
Files .createDirectories (dir );
159
160
}
160
161
@@ -164,17 +165,24 @@ protected void extractRegularFile(Path file, ZipEntry zipEntry, DataInput in) th
164
165
ZipUtils .copyLarge (zipEntry .createInputStream (in ), getOutputStream (file ));
165
166
}
166
167
167
- protected static void setFileAttributes (Path path , ZipEntry zipEntry ) throws IOException {
168
+ public ConsecutiveAccessDataInput createConsecutiveDataInput () {
169
+ SrcZip srcZip = zipModel .getSrcZip ();
170
+
171
+ return Quietly .doRuntime (() -> srcZip .isSolid () ? new SolidConsecutiveAccessDataInput (srcZip )
172
+ : new SplitConsecutiveAccessDataInput (srcZip ));
173
+ }
174
+
175
+ protected void setFileAttributes (Path path , ZipEntry zipEntry ) throws IOException {
168
176
if (zipEntry .getExternalFileAttributes () != null )
169
177
zipEntry .getExternalFileAttributes ().apply (path );
170
178
}
171
179
172
- private static void setFileLastModifiedTime (Path path , ZipEntry zipEntry ) throws IOException {
180
+ protected void setFileLastModifiedTime (Path path , ZipEntry zipEntry ) throws IOException {
173
181
long lastModifiedTime = DosTimestampConverterUtils .dosToJavaTime (zipEntry .getLastModifiedTime ());
174
182
Files .setLastModifiedTime (path , FileTime .fromMillis (lastModifiedTime ));
175
183
}
176
184
177
- protected static OutputStream getOutputStream (Path file ) throws IOException {
185
+ protected OutputStream getOutputStream (Path file ) throws IOException {
178
186
Path parent = file .getParent ();
179
187
180
188
if (!Files .exists (parent ))
@@ -184,12 +192,4 @@ protected static OutputStream getOutputStream(Path file) throws IOException {
184
192
return Files .newOutputStream (file );
185
193
}
186
194
187
- // ---------- static ----------
188
-
189
- public static ConsecutiveAccessDataInput createConsecutiveDataInput (SrcZip srcZip ) throws IOException {
190
- return srcZip .isSolid () ? new SolidConsecutiveAccessDataInput (srcZip )
191
- : new SplitConsecutiveAccessDataInput (srcZip );
192
-
193
- }
194
-
195
195
}
0 commit comments