Skip to content

Commit 82c87a4

Browse files
authored
Merge pull request #99 from jamesmudd/fletcher-checksum-workaround
Fletcher checksum workaround
2 parents ee240e0 + 9334350 commit 82c87a4

File tree

5 files changed

+91
-4
lines changed

5 files changed

+91
-4
lines changed

jhdf/src/main/java/io/jhdf/filter/FilterManager.java

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public enum FilterManager {; // Enum singleton pattern
4040
// Load the built in filters
4141
addFilter(new DeflatePipelineFilter());
4242
addFilter(new ByteShuffleFilter());
43+
addFilter(new FletcherChecksumFilter());
4344

4445
// Add dynamically loaded filters
4546
ServiceLoader<Filter> serviceLoader = ServiceLoader.load(Filter.class);

jhdf/src/main/java/io/jhdf/filter/FilterPipeline.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ public class FilterPipeline {
2323

2424
private class PipelineFilterWithData {
2525

26-
final Filter filter;
27-
final int[] filterData;
26+
private final Filter filter;
27+
private final int[] filterData;
2828

29-
public PipelineFilterWithData(Filter filter, int[] filterData) {
29+
private PipelineFilterWithData(Filter filter, int[] filterData) {
3030
this.filter = filter;
3131
this.filterData = filterData;
3232
}
3333

34-
byte[] decode(byte[] data) {
34+
private byte[] decode(byte[] data) {
3535
return filter.decode(data, filterData);
3636
}
3737
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*******************************************************************************
2+
* This file is part of jHDF. A pure Java library for accessing HDF5 files.
3+
*
4+
* http://jhdf.io
5+
*
6+
* Copyright 2019 James Mudd
7+
*
8+
* MIT License see 'LICENSE' file
9+
******************************************************************************/
10+
package io.jhdf.filter;
11+
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
14+
15+
/**
16+
* This is a placeholder for the checksum filter. Currently a no-op allows datasets with a checksum to be read but the
17+
* checksum is not validated.
18+
*
19+
* @author James Mudd
20+
*/
21+
public class FletcherChecksumFilter implements Filter {
22+
private static final Logger logger = LoggerFactory.getLogger(FletcherChecksumFilter.class);
23+
24+
private boolean warningIssued = false;
25+
26+
@Override
27+
public int getId() {
28+
return 3;
29+
}
30+
31+
@Override
32+
public String getName() {
33+
return "fletcher32";
34+
}
35+
36+
@Override
37+
public byte[] decode(byte[] encodedData, int[] filterData) {
38+
if(!warningIssued) {
39+
logger.warn("Fletcher 32 checksum will not be verified");
40+
warningIssued = true;
41+
}
42+
43+
return encodedData;
44+
}
45+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#-------------------------------------------------------------------------------
2+
# This file is part of jHDF. A pure Java library for accessing HDF5 files.
3+
#
4+
# http://jhdf.io
5+
#
6+
# Copyright 2019 James Mudd
7+
#
8+
# MIT License see 'LICENSE' file
9+
#-------------------------------------------------------------------------------
10+
import h5py
11+
12+
import numpy as np
13+
14+
def write_chunked_datasets(f):
15+
16+
data = np.arange(35).reshape(7,5)
17+
18+
float_group = f.create_group('float')
19+
float_group.create_dataset('float32', data=data, dtype='f4', chunks=(2,1), fletcher32=True)
20+
float_group.create_dataset('float64', data=data, dtype='f8', chunks=(3,4), fletcher32=True)
21+
22+
int_group = f.create_group('int')
23+
int_group.create_dataset('int8', data=data, dtype='i1', chunks=(5,3), fletcher32=True)
24+
int_group.create_dataset('int16', data=data, dtype='i2', chunks=(1,1), fletcher32=True)
25+
int_group.create_dataset('int32', data=data, dtype='i4', chunks=(1,3), fletcher32=True)
26+
27+
f.flush()
28+
f.close()
29+
30+
if __name__ == '__main__':
31+
print('Making compressed fletcher checksum dataset test files...')
32+
33+
f = h5py.File('fletcher32_datasets_earliest.hdf5', 'w', libver='earliest')
34+
write_chunked_datasets(f)
35+
print('fletcher32_datasets_earliest.hdf5')
36+
37+
# Start working just on 1.8 files first
38+
# f = h5py.File('fletcher32_datasets_latest.hdf5', 'w', libver='latest')
39+
# write_chunked_datasets(f)
40+
# print('fletcher32_datasets_latest.hdf5')
41+

0 commit comments

Comments
 (0)