Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/main/java/org/mastodon/geff/GeffUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,20 @@ public class GeffUtils
{
private static final Logger LOG = LoggerFactory.getLogger( GeffUtils.class );

private static final Compression DEFAULT_COMPRESSION = createDefaultCompression();
// Lazy-initialization holder: BloscCompression is only instantiated the first
// time a write method is called, NOT when GeffUtils class is loaded (e.g. by
// computeFirstDimChunk). This avoids permanently poisoning the BloscCompression
// class before N5ZarrWriter has had a chance to handle the UnsatisfiedLinkError
// itself, which would cause N5ZarrWriter to crash with NoClassDefFoundError.
private static final class DefaultCompressionHolder
{
static final Compression INSTANCE = createDefaultCompression();
}

private static Compression defaultCompression()
{
return DefaultCompressionHolder.INSTANCE;
}

private static Compression createDefaultCompression()
{
Expand Down Expand Up @@ -157,7 +170,7 @@ public static < T > void writeIntArray(
new long[] { size },
new int[] { chunkSize },
DataType.INT32,
DEFAULT_COMPRESSION );
defaultCompression() );
writer.createDataset( dataset, attributes );
write( data, writer, dataset, attributes );
}
Expand Down Expand Up @@ -199,7 +212,7 @@ public static void writeIntMatrix(
new long[] { numColumns, numRows },
new int[] { numColumns, chunkSize },
DataType.INT32,
DEFAULT_COMPRESSION );
defaultCompression() );
writer.createDataset( dataset, attributes );
write( data, writer, dataset, attributes );
}
Expand All @@ -218,7 +231,7 @@ public static < T > void writeDoubleArray(
new long[] { size },
new int[] { chunkSize },
DataType.FLOAT64,
DEFAULT_COMPRESSION );
defaultCompression() );
writer.createDataset( dataset, attributes );
write( data, writer, dataset, attributes );
}
Expand All @@ -244,7 +257,7 @@ public static < T > void writeDoubleMatrix(
new long[] { numColumns, size },
new int[] { numColumns, chunkSize },
DataType.FLOAT64,
DEFAULT_COMPRESSION );
defaultCompression() );
writer.createDataset( dataset, attributes );
write( data, writer, dataset, attributes );
}
Expand Down Expand Up @@ -1013,7 +1026,7 @@ private static void writeDataArray(
new long[] { numElements },
new int[] { Math.min( chunkSize, ( int ) numElements ) },
dataType,
DEFAULT_COMPRESSION );
defaultCompression() );
writer.createDataset( dataset, attributes );
write( data, writer, dataset, attributes );
}
Expand Down Expand Up @@ -1044,7 +1057,7 @@ private static void writeOffsetsArray(
new long[] { numColumns, numNodes },
new int[] { numColumns, Math.min( chunkSize, numNodes ) },
DataType.UINT64,
DEFAULT_COMPRESSION );
defaultCompression() );
writer.createDataset( dataset, attributes );
write( flatOffsets, writer, dataset, attributes );
}
Expand All @@ -1064,7 +1077,7 @@ private static void writeMissingArray(
new long[] { missing.length },
new int[] { Math.min( chunkSize, missing.length ) },
DataType.UINT8,
DEFAULT_COMPRESSION );
defaultCompression() );
writer.createDataset( dataset, attributes );

final byte[] boolAsBytes = new byte[ missing.length ];
Expand Down
Loading