Skip to content

Commit ee97d71

Browse files
committed
SonarQube cleanup
1 parent 1bbe998 commit ee97d71

12 files changed

Lines changed: 149 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ hdf5/*/*.h5
4444
/src/main/resources/h5ex_tutr/att/*.h5
4545
/src/main/resources/h5ex_d/*.h5
4646
/src/main/resources/h5ex_d/*.data
47+
/src/main/resources/h5ex_g/
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.hdf5javalib.examples.h5ex_g;
2+
3+
import org.hdf5javalib.datasource.TypedDataSource;
4+
import org.hdf5javalib.utils.HdfDisplayUtils;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
import java.io.IOException;
9+
import java.net.URISyntaxException;
10+
import java.nio.file.Files;
11+
import java.nio.file.Path;
12+
import java.nio.file.Paths;
13+
import java.util.Objects;
14+
import java.util.stream.Stream;
15+
16+
/**
17+
* Demonstrates reading and processing compound data from an HDF5 file.
18+
* <p>
19+
* The {@code CompoundRead} class serves as an example application that reads
20+
* a compound dataset from an HDF5 file, processes it using a {@link TypedDataSource},
21+
* and displays the results. It showcases filtering and mapping operations on the
22+
* dataset, as well as conversion to a custom Java class.
23+
* </p>
24+
*/
25+
public class h5ex_g_read {
26+
private static final Logger log = LoggerFactory.getLogger(h5ex_g_read.class);
27+
/**
28+
* Entry point for the application.
29+
*
30+
* @param args command-line arguments (not used)
31+
*/
32+
public static void main(String[] args) {
33+
new h5ex_g_read().run();
34+
}
35+
36+
/**
37+
* Executes the main logic of reading and displaying compound data from an HDF5 file.
38+
*/
39+
private void run() {
40+
try {
41+
// List all .h5 files in HDF5Examples resources directory
42+
Path dirPath = Paths.get(Objects.requireNonNull(h5ex_g_read.class.getClassLoader().getResource("h5ex_g")).toURI());
43+
try ( Stream<Path> streamList = Files.list(dirPath) ) {
44+
streamList.filter(p -> p.toString().endsWith(".h5"))
45+
.forEach(p -> {
46+
log.info("Running {}", p.getFileName());
47+
HdfDisplayUtils.displayFileContent(p);
48+
});
49+
50+
}
51+
} catch (URISyntaxException | IOException e) {
52+
throw new IllegalStateException(e);
53+
}
54+
}
55+
56+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package org.hdf5javalib.examples.h5ex_g;
2+
3+
import org.hdf5javalib.examples.ResourceLoader;
4+
import org.hdf5javalib.hdfjava.HdfDataset;
5+
import org.hdf5javalib.hdfjava.HdfFileReader;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.nio.channels.SeekableByteChannel;
9+
10+
import static org.junit.jupiter.api.Assertions.*;
11+
12+
public class H5exGReadTest {
13+
14+
@Test
15+
void testCompact1() throws Exception {
16+
try (SeekableByteChannel channel = ResourceLoader.loadResourceAsChannel("h5ex_g/h5ex_g_compact1.h5")) {
17+
new HdfFileReader(channel).readFile();
18+
}
19+
}
20+
21+
@Test
22+
void testCompact2() throws Exception {
23+
try (SeekableByteChannel channel = ResourceLoader.loadResourceAsChannel("h5ex_g/h5ex_g_compact2.h5")) {
24+
HdfFileReader reader = new HdfFileReader(channel).readFile();
25+
reader.getGroup("/G1").orElseThrow();
26+
}
27+
}
28+
29+
@Test
30+
void testCOrder() throws Exception {
31+
try (SeekableByteChannel channel = ResourceLoader.loadResourceAsChannel("h5ex_g/h5ex_g_corder.h5")) {
32+
HdfFileReader reader = new HdfFileReader(channel).readFile();
33+
reader.getDataset("/index_group").orElseThrow().close();
34+
}
35+
}
36+
37+
@Test
38+
void testCreate() throws Exception {
39+
try (SeekableByteChannel channel = ResourceLoader.loadResourceAsChannel("h5ex_g/h5ex_g_create.h5")) {
40+
new HdfFileReader(channel).readFile();
41+
}
42+
}
43+
44+
@Test
45+
void testIntermediate() throws Exception {
46+
try (SeekableByteChannel channel = ResourceLoader.loadResourceAsChannel("h5ex_g/h5ex_g_intermediate.h5")) {
47+
new HdfFileReader(channel).readFile();
48+
}
49+
}
50+
51+
@Test
52+
void testIterate() throws Exception {
53+
try (SeekableByteChannel channel = ResourceLoader.loadResourceAsChannel("h5ex_g/h5ex_g_iterate.h5")) {
54+
HdfFileReader reader = new HdfFileReader(channel).readFile();
55+
reader.getDataset("/DS1").orElseThrow().close();
56+
reader.getDataset("/DT1").orElseThrow().close();
57+
reader.getDataset("/G1/DS2").orElseThrow().close();
58+
HdfDataset dataset = reader.getDataset("/L1").orElseThrow();
59+
assertEquals("/G1/DS2", dataset.getHardLink());
60+
dataset.close();
61+
}
62+
}
63+
64+
@Test
65+
void testPhase() throws Exception {
66+
try (SeekableByteChannel channel = ResourceLoader.loadResourceAsChannel("h5ex_g/h5ex_g_phase.h5")) {
67+
HdfFileReader reader = new HdfFileReader(channel).readFile();
68+
reader.getGroup("/G0").orElseThrow();
69+
}
70+
}
71+
72+
@Test
73+
void testTraverse() throws Exception {
74+
try (SeekableByteChannel channel = ResourceLoader.loadResourceAsChannel("h5ex_g/h5ex_g_traverse.h5")) {
75+
HdfFileReader reader = new HdfFileReader(channel).readFile();
76+
reader.getDataset("/group1/dset1").orElseThrow().close();
77+
HdfDataset dataSet = reader.getDataset("/group1/group3/dset2").orElseThrow();
78+
assertEquals("/group1/dset1", dataSet.getHardLink());
79+
}
80+
}
81+
82+
@Test
83+
void testVisit() throws Exception {
84+
try (SeekableByteChannel channel = ResourceLoader.loadResourceAsChannel("h5ex_g/h5ex_g_visit.h5")) {
85+
HdfFileReader reader = new HdfFileReader(channel).readFile();
86+
reader.getDataset("/group1/dset1").orElseThrow().close();
87+
HdfDataset dataSet = reader.getDataset("/group1/group3/dset2").orElseThrow();
88+
assertEquals("/group1/dset1", dataSet.getHardLink());
89+
dataSet.close();
90+
}
91+
}
92+
}
1.79 KB
Binary file not shown.
342 Bytes
Binary file not shown.
4.09 KB
Binary file not shown.
1.79 KB
Binary file not shown.
3.8 KB
Binary file not shown.
2.86 KB
Binary file not shown.
346 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)