Skip to content

Commit 0d87470

Browse files
authored
Merge pull request #11 from tpietzsch/readdata
ReadData and DataBlockCodec
2 parents 010ec28 + 9ec1aa5 commit 0d87470

File tree

5 files changed

+27
-94
lines changed

5 files changed

+27
-94
lines changed

.github/workflows/build-pr.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
- master
77
tags:
88
- "*-[0-9]+.*"
9+
pull_request:
10+
branches:
11+
- master
912

1013
jobs:
1114
build:
@@ -14,7 +17,7 @@ jobs:
1417
steps:
1518
- uses: actions/checkout@v2
1619
- name: Set up Java
17-
uses: actions/setup-java@v2
20+
uses: actions/setup-java@v3
1821
with:
1922
java-version: '8'
2023
distribution: 'zulu'
@@ -28,5 +31,6 @@ jobs:
2831
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
2932
MAVEN_USER: ${{ secrets.MAVEN_USER }}
3033
MAVEN_PASS: ${{ secrets.MAVEN_PASS }}
34+
OSSRH_USER: ${{ secrets.OSSRH_USER }}
3135
OSSRH_PASS: ${{ secrets.OSSRH_PASS }}
3236
SIGNING_ASC: ${{ secrets.SIGNING_ASC }}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Build Status](https://github.com/saalfeldlab/n5-blosc/actions/workflows/build.yml/badge.svg)](https://github.com/saalfeldlab/n5-blosc/actions/workflows/build.yml)
2+
13
[![Build Status](https://github.com/saalfeldlab/n5-blosc/actions/workflows/build-main.yml/badge.svg)](https://github.com/saalfeldlab/n5-blosc/actions/workflows/build-main.yml)
24

35
# n5-blosc

pom.xml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.scijava</groupId>
77
<artifactId>pom-scijava</artifactId>
8-
<version>37.0.0</version>
8+
<version>40.0.0</version>
99
<relativePath />
1010
</parent>
1111

@@ -83,19 +83,10 @@
8383
<license.organizationName>Saalfeld Lab</license.organizationName>
8484
<license.copyrightOwners>Stephan Saalfeld</license.copyrightOwners>
8585

86-
<scijava.jvm.build.version>[1.8.0-101,11]</scijava.jvm.build.version>
87-
8886
<!-- NB: Deploy releases to the SciJava Maven repository. -->
8987
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>
9088

91-
<!-- TODO remove when pom-scijava-base is updated -->
92-
<scijava.jvm.version>8</scijava.jvm.version>
93-
<scijava.jvm.build.version>[1.8.0-101,)</scijava.jvm.build.version>
94-
95-
<maven-enforcer-plugin.version>3.0.0-M3</maven-enforcer-plugin.version>
96-
<jacoco-maven-plugin.version>0.8.6</jacoco-maven-plugin.version>
97-
98-
<n5.version>3.1.2</n5.version>
89+
<n5.version>4.0.0-alpha-1</n5.version>
9990
</properties>
10091

10192
<dependencies>

src/main/java/org/janelia/saalfeldlab/n5/blosc/BloscCompression.java

Lines changed: 18 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,20 @@
2626
package org.janelia.saalfeldlab.n5.blosc;
2727

2828
import java.io.IOException;
29-
import java.io.InputStream;
30-
import java.io.OutputStream;
3129
import java.nio.ByteBuffer;
32-
33-
import org.apache.commons.compress.utils.IOUtils;
3430
import org.blosc.BufferSizes;
3531
import org.blosc.JBlosc;
3632
import org.janelia.saalfeldlab.n5.Compression;
3733
import org.janelia.saalfeldlab.n5.Compression.CompressionType;
38-
import org.janelia.saalfeldlab.n5.DataBlock;
39-
import org.janelia.saalfeldlab.n5.DefaultBlockReader;
40-
import org.janelia.saalfeldlab.n5.DefaultBlockWriter;
34+
import org.janelia.saalfeldlab.n5.readdata.ReadData;
4135

4236
/**
4337
* Compression using JBlosc (https://github.com/Blosc/JBlosc) compressors.
4438
*
4539
* @author Stephan Saalfeld &lt;saalfelds@janelia.hhmi.org&gt;
4640
*/
4741
@CompressionType("blosc")
48-
public class BloscCompression implements DefaultBlockReader, DefaultBlockWriter, Compression {
42+
public class BloscCompression implements Compression {
4943

5044
public static final int NOSHUFFLE = 0;
5145
public static final int SHUFFLE = 1;
@@ -138,68 +132,33 @@ public BloscCompression(final BloscCompression template) {
138132
this.nthreads = template.nthreads;
139133
}
140134

141-
@Override
142-
public <T, B extends DataBlock<T>> void read(
143-
final B dataBlock,
144-
final InputStream in) throws IOException {
145-
146-
final ByteBuffer src = ByteBuffer.wrap(IOUtils.toByteArray(in));
147-
final boolean isByte = dataBlock.getData() instanceof byte[];
135+
private byte[] decode(final byte[] data, final byte[] dstBuffer) {
136+
final ByteBuffer src = ByteBuffer.wrap(data);
148137
final ByteBuffer dst;
149-
if (isByte)
150-
dst = dataBlock.toByteBuffer();
151-
else {
138+
if (dstBuffer != null) {
139+
dst = ByteBuffer.wrap(dstBuffer);
140+
} else {
152141
final BufferSizes sizes = blosc.cbufferSizes(src);
153142
final int dstSize = (int)sizes.getNbytes();
154-
dst = ByteBuffer.allocateDirect(dstSize);
143+
dst = ByteBuffer.allocate(dstSize);
155144
}
156145
JBlosc.decompressCtx(src, dst, dst.capacity(), nthreads);
157-
dataBlock.readData(dst);
146+
return dst.array();
158147
}
159148

160149
@Override
161-
public <T> void write(
162-
final DataBlock<T> dataBlock,
163-
final OutputStream out) throws IOException {
150+
public ReadData decode(final ReadData readData) throws IOException {
151+
return ReadData.from(decode(readData.allBytes(), null));
152+
}
164153

165-
final ByteBuffer src = dataBlock.toByteBuffer();
166-
final ByteBuffer dst = ByteBuffer.allocate(src.limit() + JBlosc.OVERHEAD);
154+
@Override
155+
public ReadData encode(final ReadData readData) throws IOException {
156+
final byte[] serialized = readData.allBytes();
157+
final ByteBuffer src = ByteBuffer.wrap(serialized);
158+
final ByteBuffer dst = ByteBuffer.allocate(serialized.length + JBlosc.OVERHEAD);
167159
JBlosc.compressCtx(clevel, shuffle, 1, src, src.limit(), dst, dst.limit(), cname, blocksize, nthreads);
168160
final BufferSizes sizes = blosc.cbufferSizes(dst);
169161
final int dstSize = (int)sizes.getCbytes();
170-
out.write(dst.array(), 0, dstSize);
171-
out.flush();
172-
}
173-
174-
@Override
175-
public BloscCompression getReader() {
176-
177-
return this;
178-
}
179-
180-
@Override
181-
public BloscCompression getWriter() {
182-
183-
return this;
184-
}
185-
186-
/**
187-
* Not used in this implementation of {@link DefaultBlockWriter} as
188-
* {@link JBlosc} decompresses from and into {@link ByteBuffer}.
189-
*/
190-
@Override
191-
public OutputStream getOutputStream(final OutputStream out) throws IOException {
192-
193-
return null;
194-
}
195-
196-
/**
197-
* Not used in this implementation of {@link DefaultBlockReader} as
198-
* {@link JBlosc} compresses from and into {@link ByteBuffer}.
199-
*/
200-
@Override
201-
public InputStream getInputStream(final InputStream in) throws IOException {
202-
203-
return null;
162+
return ReadData.from(dst.array(), 0, dstSize);
204163
}
205164
}

0 commit comments

Comments
 (0)