@@ -160,8 +160,7 @@ private static Mesh createMeshWithNoise() {
160160 }
161161
162162 private static Img <FloatType > getTestImage3D () {
163- try {
164- final InputStream is = MeshesTest .class .getResourceAsStream ("/3d_geometric_features_testlabel.bin" );
163+ try (final InputStream is = MeshesTest .class .getResourceAsStream ("/3d_geometric_features_testlabel.bin" )) {
165164 return ArrayImgs .floats (ArrayIO .floats (is ), 13 , 12 , 10 );
166165 } catch (IOException e ) {
167166 throw new RuntimeException (e );
@@ -173,18 +172,18 @@ private static Mesh getMesh() {
173172 // To prevent duplicates, map each (x, y, z) triple to its own index.
174173 final Map <Vector3D , Long > indexMap = new HashMap <>();
175174 final LongArray indices = new LongArray ();
176- try {
177- Files .lines (Paths .get (MeshesTest . class . getResource ( "/3d_geometric_features_mesh.txt" ). toURI ()))
178- .forEach (l -> {
179- String [] coord = l .split (" " );
180- final double x = Double .parseDouble (coord [0 ]);
181- final double y = Double .parseDouble (coord [1 ]);
182- final double z = Double .parseDouble (coord [2 ]);
183- final Vector3D vertex = new Vector3D (x , y , z );
184- final long vIndex = indexMap .computeIfAbsent (vertex , //
185- v -> m .vertices ().add (x , y , z ));
186- indices .add (vIndex );
187- });
175+ final URL url = MeshesTest . class . getResource ( "/3d_geometric_features_mesh.txt" );
176+ try ( Stream < String > lines = Files .lines (Paths .get (url . toURI ()))) {
177+ lines .forEach (l -> {
178+ String [] coord = l .split (" " );
179+ final double x = Double .parseDouble (coord [0 ]);
180+ final double y = Double .parseDouble (coord [1 ]);
181+ final double z = Double .parseDouble (coord [2 ]);
182+ final Vector3D vertex = new Vector3D (x , y , z );
183+ final long vIndex = indexMap .computeIfAbsent (vertex , //
184+ v -> m .vertices ().add (x , y , z ));
185+ indices .add (vIndex );
186+ });
188187 } catch (IOException | URISyntaxException exc ) {
189188 exc .printStackTrace ();
190189 }
0 commit comments