-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update examples to use Paths * Add examples of reading filters
- Loading branch information
Showing
7 changed files
with
104 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* This file is part of jHDF. A pure Java library for accessing HDF5 files. | ||
* | ||
* http://jhdf.io | ||
* | ||
* Copyright (c) 2022 James Mudd | ||
* | ||
* MIT License see 'LICENSE' file | ||
*/ | ||
package io.jhdf.examples; | ||
|
||
import io.jhdf.HdfFile; | ||
import io.jhdf.api.Dataset; | ||
import io.jhdf.filter.PipelineFilterWithData; | ||
|
||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Example of reading the filters applied to a dataset | ||
*/ | ||
public class ReadFilters { | ||
|
||
public static void main(String[] args) { | ||
try (HdfFile hdfFile = new HdfFile(Paths.get(args[0]))) { | ||
Dataset dataset = hdfFile.getDatasetByPath(args[1]); | ||
List<PipelineFilterWithData> filters = dataset.getFilters(); | ||
System.out.println(filters.stream().map(Objects::toString).collect(Collectors.joining(" -> "))); //NOSONAR - sout in example | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* This file is part of jHDF. A pure Java library for accessing HDF5 files. | ||
* | ||
* http://jhdf.io | ||
* | ||
* Copyright (c) 2022 James Mudd | ||
* | ||
* MIT License see 'LICENSE' file | ||
*/ | ||
package io.jhdf.examples; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import java.net.URL; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.stream.Stream; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
|
||
class ReadFiltersTest { | ||
|
||
private ByteArrayOutputStream outputStream; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
outputStream = new ByteArrayOutputStream(); | ||
System.setOut(new PrintStream(outputStream)); | ||
} | ||
|
||
|
||
static Stream<Arguments> getTests() { | ||
return Stream.of( | ||
Arguments.of("/hdf5/test_byteshuffle_compressed_datasets_latest.hdf5", "/float/float32", "shuffle (id=2) data=[4] -> deflate (id=1) data=[4]"), | ||
Arguments.of("/hdf5/bitshuffle_datasets.hdf5", "float32_bs8_comp2", "bitshuffle (id=32008) data=[0, 4, 4, 8, 2]") | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("getTests") | ||
void testReadFilters(String resourcePath, String datasetPath, String expectedOutput) throws Exception { | ||
|
||
URL resource = ReadFiltersTest.class.getResource(resourcePath); | ||
Path absolutePath = Paths.get(resource.toURI()).toAbsolutePath(); | ||
|
||
ReadFilters.main(new String[]{absolutePath.toString(), datasetPath}); | ||
|
||
assertThat(outputStream.toString(), containsString(expectedOutput)); | ||
} | ||
} |