Skip to content

Instantly share code, notes, and snippets.

@bogovicj
Created July 10, 2024 13:33
Show Gist options
  • Save bogovicj/ce9fd3fb15576f3ea71cf7473f88494c to your computer and use it in GitHub Desktop.
Save bogovicj/ce9fd3fb15576f3ea71cf7473f88494c to your computer and use it in GitHub Desktop.
/**
* Reads a {@link DataBlock} from an {@link InputStream}.
*
* @param in
* @param datasetAttributes
* @param gridPosition
* @return
* @throws IOException
*/
@SuppressWarnings("incomplete-switch")
protected static DataBlock<?> readBlockNew(
final InputStream in,
final ZarrDatasetAttributes datasetAttributes,
final long... gridPosition) throws IOException {
final int[] blockSize = datasetAttributes.getBlockSize();
final DType dType = datasetAttributes.getDType();
final BlockReader reader = datasetAttributes.getCompression().getReader();
if (dType.getDataType().equals(DataType.UINT8) || dType.getDataType().equals(DataType.INT8))
{
final ByteArrayDataBlock byteBlock = dType.createByteBlock(blockSize, gridPosition);
reader.read(byteBlock, in);
if (dType.getDataType() == DataType.STRING) {
return readVLenStringBlock(in, reader, byteBlock);
}
return byteBlock;
} else {
final DataBlock<?> dataBlock = dType.createDataBlock(blockSize, gridPosition);
reader.read(dataBlock, in);
return dataBlock;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment