Skip to content

Commit fcf9afb

Browse files
committed
wip
1 parent 6bc33a7 commit fcf9afb

35 files changed

+777
-567
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<groupId>com.scalableminds</groupId>
5454
<artifactId>blosc-java</artifactId>
5555
<version>0.1-1.21.4-SNAPSHOT</version>
56+
<scope>system</scope>
5657
<systemPath>${project.basedir}/../blosc-java/target/blosc-java-0.1-1.21.4-SNAPSHOT.jar</systemPath>
5758
</dependency>
5859
<dependency>

src/main/java/com/scalableminds/zarrjava/indexing/Indexer.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,31 @@ public static ChunkProjection computeProjection(long[] chunkCoords, long[] array
9696
return new ChunkProjection(chunkCoords, chunkOffset, outOffset, shape);
9797
}
9898

99+
100+
public static long cOrderIndex(long[] chunkCoords, long[] arrayShape) {
101+
long index = 0;
102+
long multiplier = 1;
103+
104+
for (int i = arrayShape.length - 1; i >= 0; i--) {
105+
index += chunkCoords[i] * multiplier;
106+
multiplier *= arrayShape[i];
107+
}
108+
109+
return index;
110+
}
111+
112+
public static long fOrderIndex(long[] chunkCoords, long[] arrayShape) {
113+
int index = 0;
114+
int multiplier = 1;
115+
116+
for (int i = 0; i < arrayShape.length; i++) {
117+
index += chunkCoords[i] * multiplier;
118+
multiplier *= arrayShape[i];
119+
}
120+
121+
return index;
122+
}
123+
99124
public static void copyRegion(Array source, int[] sourceOffset, Array target, int[] targetOffset, int[] shape) {
100125
assert sourceOffset.length == targetOffset.length;
101126
assert source.getRank() == sourceOffset.length;

src/main/java/com/scalableminds/zarrjava/store/ArrayValueHandle.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/main/java/com/scalableminds/zarrjava/store/BufferValueHandle.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/main/java/com/scalableminds/zarrjava/store/FileValueHandle.java

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/main/java/com/scalableminds/zarrjava/store/FilesystemStore.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33
import com.scalableminds.zarrjava.indexing.OpenSlice;
44
import com.scalableminds.zarrjava.v3.Utils;
55

6+
import javax.annotation.Nonnull;
67
import java.io.IOException;
78
import java.nio.ByteBuffer;
89
import java.nio.channels.SeekableByteChannel;
910
import java.nio.file.*;
10-
import java.util.List;
11+
import java.util.Iterator;
1112
import java.util.Optional;
12-
import java.util.stream.Collectors;
13+
import java.util.stream.Stream;
1314

14-
public class FilesystemStore extends Store {
15+
public class FilesystemStore implements Store, Store.ListableStore {
1516

17+
@Nonnull
1618
private final FileSystem fileSystem;
19+
@Nonnull
1720
private final String path;
1821

19-
public FilesystemStore(String path) {
22+
public FilesystemStore(@Nonnull String path) {
2023
this.fileSystem = FileSystems.getDefault();
2124
this.path = path;
2225
}
@@ -90,10 +93,10 @@ public void delete(String key) {
9093
}
9194
}
9295

93-
public List<String> list(String key) {
96+
public Iterator<String> list(String key) {
9497
Path keyPath = fileSystem.getPath(this.path, key);
95-
try {
96-
return Files.list(keyPath).map(p -> p.toFile().getName()).collect(Collectors.toList());
98+
try (Stream<Path> paths = Files.list(keyPath)) {
99+
return paths.map(p -> p.toFile().getName()).iterator();
97100
} catch (IOException e) {
98101
throw new RuntimeException(e);
99102
}

src/main/java/com/scalableminds/zarrjava/store/HttpStore.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package com.scalableminds.zarrjava.store;
22

33
import com.scalableminds.zarrjava.indexing.OpenSlice;
4-
import com.squareup.okhttp.Call;
5-
import com.squareup.okhttp.OkHttpClient;
6-
import com.squareup.okhttp.Request;
7-
import com.squareup.okhttp.Response;
4+
import com.squareup.okhttp.*;
85

6+
import javax.annotation.Nonnull;
97
import java.io.IOException;
108
import java.nio.ByteBuffer;
119
import java.util.Optional;
1210

13-
public class HttpStore extends Store {
11+
public class HttpStore implements Store {
1412

13+
@Nonnull
1514
private final OkHttpClient httpClient;
15+
@Nonnull
1616
private final String path;
1717

18-
public HttpStore(String path) {
18+
public HttpStore(@Nonnull String path) {
1919
this.httpClient = new OkHttpClient();
2020
this.path = path;
2121
}
@@ -47,7 +47,9 @@ public Optional<ByteBuffer> get(String key, OpenSlice byteRange) {
4747
Call call = httpClient.newCall(request);
4848
try {
4949
Response response = call.execute();
50-
return Optional.of(ByteBuffer.wrap(response.body().bytes()));
50+
try (ResponseBody body = response.body()) {
51+
return Optional.of(ByteBuffer.wrap(body.bytes()));
52+
}
5153
} catch (IOException e) {
5254
return Optional.empty();
5355
}

src/main/java/com/scalableminds/zarrjava/store/NoneHandle.java

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.scalableminds.zarrjava.store;
2+
3+
import com.amazonaws.services.s3.AmazonS3;
4+
import com.amazonaws.services.s3.model.ObjectMetadata;
5+
import com.amazonaws.services.s3.model.S3ObjectInputStream;
6+
import com.scalableminds.zarrjava.indexing.OpenSlice;
7+
import com.scalableminds.zarrjava.v3.Utils;
8+
9+
import javax.annotation.Nonnull;
10+
import javax.annotation.Nullable;
11+
import java.io.ByteArrayInputStream;
12+
import java.io.IOException;
13+
import java.io.InputStream;
14+
import java.nio.ByteBuffer;
15+
import java.util.Iterator;
16+
import java.util.Optional;
17+
18+
public class S3Store implements Store, Store.ListableStore {
19+
@Nonnull
20+
private final AmazonS3 s3client;
21+
@Nonnull
22+
private final String bucketName;
23+
@Nullable
24+
private final String prefix;
25+
26+
public S3Store(@Nonnull AmazonS3 s3client, @Nonnull String bucketName, @Nullable String prefix) {
27+
this.s3client = s3client;
28+
this.bucketName = bucketName;
29+
this.prefix = prefix;
30+
}
31+
32+
String dereferencePath(String key) {
33+
if (prefix == null) {
34+
return key;
35+
}
36+
if (key == null || key.length() == 0) {
37+
return prefix;
38+
}
39+
return prefix + "/" + key;
40+
}
41+
42+
@Override
43+
public Optional<ByteBuffer> get(String key, OpenSlice byteRange) {
44+
try (S3ObjectInputStream inputStream = s3client.getObject(bucketName,
45+
dereferencePath(key)).getObjectContent()) {
46+
return Optional.of(Utils.asByteBuffer(inputStream));
47+
} catch (IOException e) {
48+
return Optional.empty();
49+
}
50+
}
51+
52+
@Override
53+
public void set(String key, ByteBuffer bytes, OpenSlice byteRange) {
54+
try (InputStream byteStream = new ByteArrayInputStream(bytes.array())) {
55+
s3client.putObject(bucketName, dereferencePath(key), byteStream, new ObjectMetadata());
56+
} catch (IOException e) {
57+
throw new RuntimeException(e);
58+
}
59+
}
60+
61+
@Override
62+
public void delete(String key) {
63+
64+
}
65+
66+
@Override
67+
public Iterator<String> list(String key) {
68+
final String fullKey = dereferencePath(key);
69+
return s3client.listObjects(bucketName, fullKey).getObjectSummaries().stream().map(
70+
p -> p.getKey().substring(fullKey.length() + 1)).iterator();
71+
}
72+
73+
@Override
74+
public String toString() {
75+
return "s3://" + bucketName + "/" + prefix;
76+
}
77+
}

0 commit comments

Comments
 (0)