Skip to content

Commit

Permalink
Merge pull request #221 from jamesmudd/empty-conti-dsets
Browse files Browse the repository at this point in the history
Improve empty dataset detection for contiguous datasets
  • Loading branch information
jamesmudd authored Sep 9, 2020
2 parents 95ade4f + 670d6d6 commit eedc7be
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions jhdf/src/main/java/io/jhdf/dataset/ContiguousDatasetImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@

public class ContiguousDatasetImpl extends DatasetBase implements ContiguousDataset {

final ContiguousDataLayoutMessage contiguousDataLayoutMessage;

public ContiguousDatasetImpl(HdfFileChannel hdfFc, long address, String name, Group parent, ObjectHeader oh) {
super(hdfFc, address, name, parent, oh);
this.contiguousDataLayoutMessage = getHeaderMessage(ContiguousDataLayoutMessage.class);
}

@Override
public ByteBuffer getDataBuffer() {
ContiguousDataLayoutMessage contiguousDataLayoutMessage = getHeaderMessage(ContiguousDataLayoutMessage.class);

// Check for empty dataset
if (contiguousDataLayoutMessage.getAddress() == UNDEFINED_ADDRESS) {
return null;
}

try {
ByteBuffer data = hdfFc.map(contiguousDataLayoutMessage.getAddress(), getSizeInBytes());
convertToCorrectEndiness(data);
Expand All @@ -51,8 +47,11 @@ public ByteBuffer getBuffer() {

@Override
public long getDataAddress() {
ContiguousDataLayoutMessage contiguousDataLayoutMessage = getHeaderMessage(ContiguousDataLayoutMessage.class);
return contiguousDataLayoutMessage.getAddress();
}

@Override
public boolean isEmpty() {
return contiguousDataLayoutMessage.getAddress() == UNDEFINED_ADDRESS;
}
}

0 comments on commit eedc7be

Please sign in to comment.