use of suite.primitive.Bytes in project suite by stupidsing.
the class FileSystemKeySet method remove.
public void remove(Bytes name) {
KeyDataMutator<Bytes> mutator = store.mutateData();
List<NameKey> keys = keyUtil.toNameKeys(name);
for (int i = keys.size() - 1; 0 <= i; i--) {
NameKey key = keys.get(i);
if (key.size == 0) {
Bytes hash = keyUtil.hash(keyUtil.toName(keys.subList(0, i + 1)));
NameKey minKey = boundingKey(hash, 0);
NameKey maxKey = boundingKey(hash, 1);
if (mutator.keys(keyUtil.toBytes(minKey), keyUtil.toBytes(maxKey)) == null)
mutator.removeTerminal(keyUtil.toBytes(key));
} else
mutator.removeTerminal(keyUtil.toBytes(key));
}
}
use of suite.primitive.Bytes in project suite by stupidsing.
the class FileSystemMutatorImpl method read.
public Bytes read(Bytes name) {
KeyDataStore<Bytes> store = mutate.source();
KeyValueMutator<Bytes, Integer> kvm = store.mutate();
KeyDataMutator<Bytes> kdm = store.mutateData();
Bytes hash = keyUtil.hash(name);
Integer size = kvm.get(key(hash, SIZEID, 0));
if (size != null) {
int seq = 0;
BytesBuilder bb = new BytesBuilder();
for (int s = 0; s < size; s += pageSize) bb.append(kdm.getPayload(key(hash, DATAID, seq++)));
return bb.toBytes().range(0, size);
} else
return null;
}
use of suite.primitive.Bytes in project suite by stupidsing.
the class FileSystemMutatorImpl method replace.
public void replace(Bytes name, Bytes bytes) {
KeyDataStore<Bytes> store = mutate.source();
KeyValueMutator<Bytes, Integer> kvm = store.mutate();
KeyDataMutator<Bytes> kdm = store.mutateData();
FileSystemKeySet fsNameKeySet = new FileSystemKeySet(keyUtil, store);
Bytes hash = keyUtil.hash(name);
Bytes sizeKey = key(hash, SIZEID, 0);
Bytes nameBytes0 = fsNameKeySet.list(name, null).first();
boolean isRemove = Objects.equals(nameBytes0, name);
boolean isCreate = bytes != null;
if (isRemove) {
int seq = 0, size = kvm.get(sizeKey);
if (!isCreate)
fsNameKeySet.remove(name);
kvm.remove(sizeKey);
for (int s = 0; s < size; s += pageSize) kdm.removePayload(key(hash, DATAID, seq++));
}
if (isCreate) {
int pos = 0, seq = 0, size = bytes.size();
while (pos < size) {
int pos1 = min(pos + pageSize, size);
kdm.putPayload(key(hash, DATAID, seq++), bytes.range(pos, pos1));
pos = pos1;
}
kvm.put(sizeKey, size);
if (!isRemove)
fsNameKeySet.add(name);
}
store.end(true);
}
use of suite.primitive.Bytes in project suite by stupidsing.
the class FileSystemMutatorImpl method resize.
public void resize(Bytes name, int size1) {
KeyDataStore<Bytes> store = mutate.source();
KeyValueMutator<Bytes, Integer> kvm = store.mutate();
KeyDataMutator<Bytes> kdm = store.mutateData();
Bytes hash = keyUtil.hash(name);
Bytes sizeKey = key(hash, SIZEID, 0);
int size0 = kvm.get(sizeKey);
int nPages0 = (size0 + pageSize - 1) / pageSize;
int nPages1 = (size1 + pageSize - 1) / pageSize;
for (int page = nPages1; page < nPages0; page++) kdm.removePayload(key(hash, DATAID, page));
for (int page = nPages0; page < nPages1; page++) kdm.putPayload(key(hash, DATAID, page), Bytes.empty);
kvm.put(sizeKey, size1);
store.end(true);
}
use of suite.primitive.Bytes in project suite by stupidsing.
the class HttpUtil method httpJre.
@SuppressWarnings("unused")
private static HttpResult httpJre(String method, URL url, Outlet<Bytes> in, Map<String, String> headers) throws IOException {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod(method);
headers.entrySet().forEach(e -> conn.setRequestProperty(e.getKey(), e.getValue()));
try (OutputStream os = conn.getOutputStream()) {
Bytes_.copy(in, os::write);
}
int responseCode = conn.getResponseCode();
Outlet<Bytes> out = To.outlet(conn.getInputStream());
if (//
responseCode == HttpURLConnection.HTTP_MOVED_PERM || //
responseCode == HttpURLConnection.HTTP_MOVED_TEMP || responseCode == HttpURLConnection.HTTP_SEE_OTHER) {
String cookies1 = conn.getHeaderField("Set-Cookie");
URL url1 = To.url(conn.getHeaderField("Location"));
Map<String, String> headers1 = new HashMap<>(headers);
if (cookies1 != null)
headers1.put("Cookie", cookies1);
return http(method, url1, in, headers1);
} else if (responseCode == HttpURLConnection.HTTP_OK)
return new HttpResult(responseCode, out);
else
throw new IOException(//
"HTTP returned " + responseCode + ": " + //
url + ": " + //
conn.getResponseMessage() + ": " + out.collect(As::string));
}
Aggregations