Skip to content

Commit 04700c0

Browse files
committed
refactor v2 code
1 parent 1aa5507 commit 04700c0

3 files changed

Lines changed: 8 additions & 12 deletions

File tree

src/main/java/org/hdf5javalib/examples/hdf5examples/HDF5Debug.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ private void run() {
4848
// ATL03_20250302235544_11742607_006_01
4949
// Path dirPath = Paths.get(Objects.requireNonNull(HDF5Debug.class.getClassLoader().getResource("HDF5Examples/h5ex_g_compact2.h5")).toURI());
5050
// Path dirPath = Paths.get("c:/users/karnicho/Downloads/ATL03_20250302235544_11742607_007_01.h5");
51-
Path dirPath = Paths.get("c:/users/karnicho/Downloads/ATL03_20250302235544_11742607_006_01.h5");
51+
// Path dirPath = Paths.get("c:/users/karnicho/Downloads/ATL03_20250302235544_11742607_006_01.h5");
52+
Path dirPath = Paths.get("c:/users/karnicho/Downloads/SMAP_L1B_TB_57204_D_20251016T224815_R19240_001.h5");
5253
processFile(dirPath);
5354
} catch (Exception e) {
5455
throw new IllegalStateException(e);

src/main/java/org/hdf5javalib/hdffile/dataobjects/messages/LinkMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public LinkMessage(
7171
this.linkInformation = linkInformation;
7272
}
7373

74-
public static HdfMessage parseHeaderMessage(int messageFlags, byte[] data, HdfDataFile hdfDataFile) throws IOException, InvocationTargetException, InstantiationException, IllegalAccessException {
74+
public static LinkMessage parseHeaderMessage(int messageFlags, byte[] data, HdfDataFile hdfDataFile) throws IOException, InvocationTargetException, InstantiationException, IllegalAccessException {
7575
ByteBuffer buffer = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);
7676

7777
int version = Byte.toUnsignedInt(buffer.get());

src/main/java/org/hdf5javalib/hdfjava/HdfFileReader.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,20 +281,15 @@ private void processV2BTreeLinks(HdfGroup group, LinkInfoMessage linkInfoMessage
281281
long fractalHeapOffset = linkInfoMessage.getFractalHeapAddress().getInstance(Long.class);
282282
FractalHeap fractalHeap = FractalHeap.read(fileChannel, fractalHeapOffset, this); // Assuming params
283283

284-
for (BTreeV2Record bTreeV2Record : bTreeV2Reader.getAllRecords()) {
284+
List<BTreeV2Record> allRecs = bTreeV2Reader.getAllRecords();
285+
for (BTreeV2Record bTreeV2Record : allRecs) {
285286
byte[] heapId = ((Type5Record) bTreeV2Record).heapId;
286287
ParsedHeapId parsedHeapId = new ParsedHeapId(heapId, fractalHeap);
287288
byte[] objectData = fractalHeap.getObject(parsedHeapId);
288-
ByteBuffer retrievedData = ByteBuffer.wrap(objectData).order(ByteOrder.LITTLE_ENDIAN);
289289

290-
retrievedData.position(10); // Skip rowHeader
291-
int sLength = Byte.toUnsignedInt(retrievedData.get());
292-
byte[] stringBuffer = new byte[sLength];
293-
retrievedData.get(stringBuffer);
294-
String linkName = new String(stringBuffer);
295-
long objectHeaderOffset = retrievedData.getLong();
290+
LinkMessage linkMessage = LinkMessage.parseHeaderMessage(0, objectData, this);
296291

297-
processLink(group, linkName, objectHeaderOffset);
292+
processLink(group, linkMessage.getLinkName(), linkMessage.getLinkInformation().getInstance(Long.class));
298293
}
299294
}
300295

@@ -1132,7 +1127,7 @@ static HdfObjectHeaderPrefixV2 readV2ObjectHeader(SeekableByteChannel fileChanne
11321127

11331128
// --- 6. Handle Continuation Messages ---
11341129
Function<ByteBuffer, HdfMessage.OBJECT_HEADER_PREFIX> prefixReader = (flags & 0b00000100) > 0 ? HdfMessage.V2OBJECT_HEADER_READ_PREFIX_WITHORDER : HdfMessage.V2_OBJECT_HEADER_READ_PREFIX;
1135-
;
1130+
11361131
parseContinuationMessages(fileChannel, prefixReader, dataObjectHeaderMessages, hdfDataFile);
11371132
// --- 7. Create the V2 Header Prefix Instance ---
11381133
return new HdfObjectHeaderPrefixV2(flags, sizeOfChunk0, checksum,

0 commit comments

Comments
 (0)