60
60
import java .util .Map .Entry ;
61
61
import java .util .Set ;
62
62
import java .util .stream .Collectors ;
63
+ import java .util .stream .Stream ;
63
64
64
65
@ Component
65
66
public class ImportExportSerializerImpl implements ImportExportSerializer {
@@ -190,17 +191,22 @@ public <E extends DocumentEntity> void performImport(final Path dir,
190
191
try {
191
192
// Look for matching files
192
193
final String match = "." + entityType + "." ;
193
- final List <Path > paths = Files .walk (dir )
194
- .filter (p -> p .getFileName ().toString ().contains (match ))
195
- .map (p -> {
196
- String name = p .getFileName ().toString ();
197
- name = name .substring (0 , name .indexOf (match ) + match .length () - 1 );
198
- return p .getParent ().resolve (name );
199
- })
200
- .collect (Collectors .toSet ())
201
- .stream ()
202
- .sorted (Comparator .comparingInt (Path ::getNameCount ))
203
- .collect (Collectors .toList ());
194
+ List <Path > paths ;
195
+ try (final Stream <Path > stream = Files .walk (dir )) {
196
+ final Set <Path > set = stream
197
+ .filter (p -> p .getFileName ().toString ().contains (match ))
198
+ .map (p -> {
199
+ String name = p .getFileName ().toString ();
200
+ name = name .substring (0 , name .indexOf (match ) + match .length () - 1 );
201
+ return p .getParent ().resolve (name );
202
+ })
203
+ .collect (Collectors .toSet ());
204
+ try (Stream <Path > s = set .stream ()) {
205
+ paths = s
206
+ .sorted (Comparator .comparingInt (Path ::getNameCount ))
207
+ .collect (Collectors .toList ());
208
+ }
209
+ }
204
210
205
211
paths .forEach (path -> {
206
212
ImportState importState = null ;
@@ -213,21 +219,25 @@ public <E extends DocumentEntity> void performImport(final Path dir,
213
219
214
220
// Find all of the files associated with this document config.
215
221
final String matchingConfig = relativePath .getFileName ().toString ();
216
- final List <Path > parts = Files .list (path .getParent ())
217
- .filter (p -> p .getFileName ().toString ().startsWith (matchingConfig ))
218
- .collect (Collectors .toList ());
219
222
220
223
// Create a map of all of the data required to import this document.
221
224
final Map <String , String > dataMap = new HashMap <>();
222
- parts .forEach (part -> {
223
- try {
224
- final String key = dir .relativize (part ).toString ();
225
- final String content = new String (Files .readAllBytes (part ), Charset .forName ("UTF-8" ));
226
- dataMap .put (key , content );
227
- } catch (final IOException e ) {
228
- LOGGER .error (e .getMessage (), e );
229
- }
230
- });
225
+ try (final Stream <Path > stream = Files .list (path .getParent ())) {
226
+ final List <Path > parts = stream
227
+ .filter (p -> p .getFileName ().toString ().startsWith (matchingConfig ))
228
+ .collect (Collectors .toList ());
229
+
230
+ parts .forEach (part -> {
231
+ try {
232
+ final String key = dir .relativize (part ).toString ();
233
+ final String content = new String (Files .readAllBytes (part ), Charset .forName ("UTF-8" ));
234
+ dataMap .put (key , content );
235
+ } catch (final Throwable e ) {
236
+ LOGGER .error (e .getMessage (), e );
237
+ LOGGER .error ("DATA SIZE = " + dataMap .size ());
238
+ }
239
+ });
240
+ }
231
241
232
242
// Find out if this item exists.
233
243
// TODO : In v6 the UUID will be part of the file name so that we don't have to read the config to get it.
0 commit comments