2222import java .util .Comparator ;
2323import java .util .List ;
2424import java .util .stream .Collectors ;
25- import java .util .stream .IntStream ;
2625import java .util .stream .Stream ;
2726
2827import static org .hdf5javalib .utils .HdfReadUtils .getResourcePath ;
@@ -97,28 +96,6 @@ void run() throws Exception {
9796 }
9897 }
9998
100- /**
101- * Processes a scalar dataset using a TypedDataSource.
102- *
103- * @param channel the file channel for reading the HDF5 file
104- * @param hdfDataFile the HDF5 file context
105- * @param dataSet the scalar dataset to process
106- * @throws IOException if an I/O error occurs
107- */
108- void tryDataSpliterator (SeekableByteChannel channel , HdfDataFile hdfDataFile , HdfDataset dataSet ) throws IOException , InvocationTargetException , InstantiationException , IllegalAccessException {
109- TypedDataSource <BigInteger > dataSource = new TypedDataSource <>(channel , hdfDataFile , dataSet , BigInteger .class );
110- BigInteger allData = dataSource .readScalar ();
111- log .info ("Scalar dataset name = {}" , dataSet .getObjectName ());
112- log .info ("Scalar readAll stats = {}" , Stream .of (allData )
113- .collect (Collectors .summarizingInt (BigInteger ::intValue )));
114- log .info ("Scalar streaming list = {}" , dataSource .streamScalar ().toList ());
115- log .info ("Scalar parallelStreaming list = {}" , dataSource .parallelStreamScalar ().toList ());
116-
117- new TypedDataSource <>(channel , hdfDataFile , dataSet , HdfFixedPoint .class ).streamScalar ().forEach (item -> log .info ("{}" , item ));
118- new TypedDataSource <>(channel , hdfDataFile , dataSet , String .class ).streamScalar ().forEach (item -> log .info ("{}" , item ));
119- new TypedDataSource <>(channel , hdfDataFile , dataSet , BigDecimal .class ).streamScalar ().forEach (item -> log .info ("{}" , item ));
120- }
121-
12299 /**
123100 * Processes a scalar dataset using a TypedDataSource.
124101 *
@@ -141,31 +118,6 @@ void tryScalarDataSpliterator(SeekableByteChannel channel, HdfDataFile hdfDataFi
141118 new TypedDataSource <>(channel , hdfDataFile , dataSet , BigDecimal .class ).streamScalar ().forEach (item -> log .info ("{}" , item ));
142119 }
143120
144- /**
145- * Processes a vector dataset using a TypedDataSource.
146- *
147- * @param fileChannel the file channel for reading the HDF5 file
148- * @param hdfDataFile the HDF5 file context
149- * @param dataSet the vector dataset to process
150- * @throws IOException if an I/O error occurs
151- */
152- void tryVectorSpliterator (SeekableByteChannel fileChannel , HdfDataFile hdfDataFile , HdfDataset dataSet ) throws IOException , InvocationTargetException , InstantiationException , IllegalAccessException {
153- TypedDataSource <BigInteger > dataSource = new TypedDataSource <>(fileChannel , hdfDataFile , dataSet , BigInteger .class );
154- BigInteger [] allData = dataSource .readVector ();
155- log .info ("Vector readAll stats = {}" , Arrays .stream (allData ).collect (Collectors .summarizingInt (BigInteger ::intValue )));
156- log .info ("Vector streaming stats = {}" , dataSource .streamVector ()
157- .collect (Collectors .summarizingInt (BigInteger ::intValue )));
158- log .info ("Vector parallel streaming stats = {}" , dataSource .parallelStreamVector ()
159- .collect (Collectors .summarizingInt (BigInteger ::intValue )));
160- final BigInteger [] flattenedData = dataSource .readFlattened ();
161- int [] shape = dataSource .getShape ();
162- log .info ("Vector flattenedData stats = {}" , IntStream .rangeClosed (0 , FlattenedArrayUtils .totalSize (shape ) - 1 )
163- .mapToObj (i -> FlattenedArrayUtils .getElement (flattenedData , shape , i ))
164- .collect (Collectors .summarizingInt (BigInteger ::intValue )));
165- BigInteger bdReduced = (BigInteger ) FlattenedArrayUtils .reduceAlongAxis (dataSource .streamFlattened (), shape , 0 , BigInteger ::max , BigInteger .class );
166- log .info ("FlattenedData Streamed Reduced = {}" , bdReduced );
167- }
168-
169121 /**
170122 * Processes a matrix dataset using a TypedDataSource.
171123 *
@@ -282,28 +234,4 @@ void display4DData(SeekableByteChannel fileChannel, HdfDataFile hdfDataFile, Hdf
282234 pieces .forEach (entry -> log .info ("Coords {} → Value: {}" , Arrays .toString (entry .coordinates ), entry .value ));
283235 }
284236
285- /**
286- * Processes a 4D dataset using a TypedDataSource, demonstrating slicing and filtering.
287- *
288- * @param fileChannel the file channel for reading the HDF5 file
289- * @param hdfDataFile the HDF5 file context
290- * @param dataSet the 4D dataset to process
291- * @throws IOException if an I/O error occurs
292- */
293- void displaySalesCube (SeekableByteChannel fileChannel , HdfDataFile hdfDataFile , HdfDataset dataSet ) throws IOException , InvocationTargetException , InstantiationException , IllegalAccessException {
294- TypedDataSource <Double > dataSource = new TypedDataSource <>(fileChannel , hdfDataFile , dataSet , Double .class );
295- int [] shape = dataSource .getShape (); // Should be [60, 100, 50]
296- Double [][] sales2024Jan = (Double [][]) FlattenedArrayUtils .sliceStream (
297- dataSource .streamFlattened (),
298- shape ,
299- new int [][]{{0 }, {}, {}}, // Slice Time=2024-01 (index 0)
300- Double .class
301- );
302- log .info ("Sales for January 2024:" );
303- for (int z = 0 ; z < shape [1 ]; z ++) {
304- for (int p = 0 ; p < shape [2 ]; p ++) {
305- log .info (String .format ("Zip %d, Product %d: %.2f" , z , p , sales2024Jan [z ][p ]));
306- }
307- }
308- }
309237}
0 commit comments