Skip to content

Commit 5cbf6ae

Browse files
committed
google code style
1 parent 9e18db5 commit 5cbf6ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2857
-2482
lines changed
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.scalableminds.zarrjava;
22

33
public class ZarrException extends Exception {
4-
public ZarrException(String message, Throwable cause) {
5-
super(message, cause);
6-
}
74

8-
public ZarrException(String message) {
9-
super(message);
10-
}
5+
public ZarrException(String message, Throwable cause) {
6+
super(message, cause);
7+
}
8+
9+
public ZarrException(String message) {
10+
super(message);
11+
}
1112
}
Lines changed: 120 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,145 @@
11
package com.scalableminds.zarrjava.store;
22

33
import com.scalableminds.zarrjava.utils.Utils;
4-
5-
import javax.annotation.Nonnull;
6-
import javax.annotation.Nullable;
74
import java.io.IOException;
85
import java.nio.ByteBuffer;
96
import java.nio.channels.SeekableByteChannel;
10-
import java.nio.file.*;
7+
import java.nio.file.Files;
8+
import java.nio.file.NoSuchFileException;
9+
import java.nio.file.Path;
10+
import java.nio.file.Paths;
11+
import java.nio.file.StandardOpenOption;
1112
import java.util.stream.Stream;
13+
import javax.annotation.Nonnull;
14+
import javax.annotation.Nullable;
1215

1316
public class FilesystemStore implements Store, Store.ListableStore {
1417

15-
@Nonnull
16-
private final Path path;
18+
@Nonnull
19+
private final Path path;
1720

18-
public FilesystemStore(@Nonnull Path path) {
19-
this.path = path;
20-
}
21+
public FilesystemStore(@Nonnull Path path) {
22+
this.path = path;
23+
}
2124

22-
public FilesystemStore(@Nonnull String path) {
23-
this.path = Paths.get(path);
24-
}
25+
public FilesystemStore(@Nonnull String path) {
26+
this.path = Paths.get(path);
27+
}
2528

26-
Path resolveKeys(String[] keys) {
27-
Path newPath = path;
28-
for (String key : keys) {
29-
newPath = newPath.resolve(key);
30-
}
31-
return newPath;
29+
Path resolveKeys(String[] keys) {
30+
Path newPath = path;
31+
for (String key : keys) {
32+
newPath = newPath.resolve(key);
3233
}
33-
34-
@Override
35-
public boolean exists(String[] keys) {
36-
return Files.exists(resolveKeys(keys));
34+
return newPath;
35+
}
36+
37+
@Override
38+
public boolean exists(String[] keys) {
39+
return Files.exists(resolveKeys(keys));
40+
}
41+
42+
@Nullable
43+
@Override
44+
public ByteBuffer get(String[] keys) {
45+
try {
46+
return ByteBuffer.wrap(Files.readAllBytes(resolveKeys(keys)));
47+
} catch (IOException e) {
48+
return null;
3749
}
38-
39-
@Nullable
40-
@Override
41-
public ByteBuffer get(String[] keys) {
42-
try {
43-
return ByteBuffer.wrap(Files.readAllBytes(resolveKeys(keys)));
44-
} catch (IOException e) {
45-
return null;
46-
}
50+
}
51+
52+
@Nullable
53+
@Override
54+
public ByteBuffer get(String[] keys, long start) {
55+
try (SeekableByteChannel byteChannel = Files.newByteChannel(resolveKeys(keys))) {
56+
long startOffset = 0;
57+
if (start >= 0) {
58+
startOffset = start;
59+
} else {
60+
startOffset = byteChannel.size() + start;
61+
}
62+
long endOffset = byteChannel.size();
63+
ByteBuffer bytes = Utils.allocateNative((int) (endOffset - startOffset));
64+
byteChannel.position(startOffset);
65+
byteChannel.read(bytes);
66+
bytes.rewind();
67+
return bytes;
68+
} catch (IOException e) {
69+
return null;
4770
}
48-
49-
@Nullable
50-
@Override
51-
public ByteBuffer get(String[] keys, long start) {
52-
try (SeekableByteChannel byteChannel = Files.newByteChannel(resolveKeys(keys))) {
53-
long startOffset = 0;
54-
if (start >= 0) {
55-
startOffset = start;
56-
} else {
57-
startOffset = byteChannel.size() + start;
58-
}
59-
long endOffset = byteChannel.size();
60-
ByteBuffer bytes = Utils.allocateNative((int) (endOffset - startOffset));
61-
byteChannel.position(startOffset);
62-
byteChannel.read(bytes);
63-
bytes.rewind();
64-
return bytes;
65-
} catch (IOException e) {
66-
return null;
67-
}
68-
}
69-
70-
@Nullable
71-
@Override
72-
public ByteBuffer get(String[] keys, long start, long end) {
73-
try (SeekableByteChannel byteChannel = Files.newByteChannel(resolveKeys(keys))) {
74-
long startOffset = 0;
75-
if (start >= 0) {
76-
startOffset = start;
77-
} else {
78-
startOffset = byteChannel.size() + start;
79-
}
80-
ByteBuffer bytes = Utils.allocateNative((int) (end - startOffset));
81-
byteChannel.position(startOffset);
82-
byteChannel.read(bytes);
83-
bytes.rewind();
84-
return bytes;
85-
} catch (IOException e) {
86-
return null;
87-
}
71+
}
72+
73+
@Nullable
74+
@Override
75+
public ByteBuffer get(String[] keys, long start, long end) {
76+
try (SeekableByteChannel byteChannel = Files.newByteChannel(resolveKeys(keys))) {
77+
long startOffset = 0;
78+
if (start >= 0) {
79+
startOffset = start;
80+
} else {
81+
startOffset = byteChannel.size() + start;
82+
}
83+
ByteBuffer bytes = Utils.allocateNative((int) (end - startOffset));
84+
byteChannel.position(startOffset);
85+
byteChannel.read(bytes);
86+
bytes.rewind();
87+
return bytes;
88+
} catch (IOException e) {
89+
return null;
8890
}
91+
}
8992

9093

91-
@Override
92-
public void set(String[] keys, ByteBuffer bytes) {
93-
Path keyPath = resolveKeys(keys);
94-
try {
95-
Files.createDirectories(keyPath.getParent());
96-
} catch (IOException e) {
97-
throw new RuntimeException(e);
98-
}
99-
try (SeekableByteChannel channel = Files.newByteChannel(keyPath.toAbsolutePath(), StandardOpenOption.CREATE,
100-
StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) {
101-
channel.write(bytes);
102-
} catch (IOException e) {
103-
throw new RuntimeException(e);
104-
}
105-
}
106-
107-
@Override
108-
public void delete(String[] keys) {
109-
try {
110-
Files.delete(resolveKeys(keys));
111-
} catch (NoSuchFileException e) {
112-
// ignore
113-
} catch (IOException e) {
114-
throw new RuntimeException(e);
115-
}
94+
@Override
95+
public void set(String[] keys, ByteBuffer bytes) {
96+
Path keyPath = resolveKeys(keys);
97+
try {
98+
Files.createDirectories(keyPath.getParent());
99+
} catch (IOException e) {
100+
throw new RuntimeException(e);
116101
}
117-
118-
public String[] list(String[] keys) {
119-
try (Stream<Path> paths = Files.list(resolveKeys(keys))) {
120-
return paths.map(p -> p.toFile().getName()).toArray(String[]::new);
121-
} catch (IOException e) {
122-
throw new RuntimeException(e);
123-
}
102+
try (SeekableByteChannel channel = Files.newByteChannel(keyPath.toAbsolutePath(),
103+
StandardOpenOption.CREATE,
104+
StandardOpenOption.TRUNCATE_EXISTING,
105+
StandardOpenOption.WRITE
106+
)) {
107+
channel.write(bytes);
108+
} catch (IOException e) {
109+
throw new RuntimeException(e);
124110
}
125-
126-
@Nonnull
127-
@Override
128-
public StoreHandle resolve(String... keys) {
129-
return new StoreHandle(this, keys);
111+
}
112+
113+
@Override
114+
public void delete(String[] keys) {
115+
try {
116+
Files.delete(resolveKeys(keys));
117+
} catch (NoSuchFileException e) {
118+
// ignore
119+
} catch (IOException e) {
120+
throw new RuntimeException(e);
130121
}
131-
132-
@Override
133-
public String toString() {
134-
return this.path.toUri().toString().replaceAll("\\/$", "");
122+
}
123+
124+
public String[] list(String[] keys) {
125+
try (Stream<Path> paths = Files.list(resolveKeys(keys))) {
126+
return paths.map(p -> p.toFile()
127+
.getName())
128+
.toArray(String[]::new);
129+
} catch (IOException e) {
130+
throw new RuntimeException(e);
135131
}
132+
}
133+
134+
@Nonnull
135+
@Override
136+
public StoreHandle resolve(String... keys) {
137+
return new StoreHandle(this, keys);
138+
}
139+
140+
@Override
141+
public String toString() {
142+
return this.path.toUri().toString().replaceAll("\\/$", "");
143+
}
136144

137145
}

0 commit comments

Comments
 (0)