use of suite.primitive.Bytes in project suite by stupidsing.
the class RequestResponseMatcher method onResponseReceived.
public void onResponseReceived(int token, Bytes response) {
Pair<Mutable<Bytes>, Condition> pair = requests.get(token);
Mutable<Bytes> holder = pair.t0;
Condition condition = pair.t1;
condition.thenNotify(() -> holder.set(response));
}
use of suite.primitive.Bytes in project suite by stupidsing.
the class FileSystemKeySet method list.
private Streamlet<Bytes> list(List<NameKey> prefix, List<NameKey> keys0, List<NameKey> keys1) {
Bytes hash = keyUtil.hash(keyUtil.toName(prefix));
NameKey minKey = keys0 != null && !keys0.isEmpty() ? List_.first(keys0) : boundingKey(hash, 0);
NameKey maxKey = keys1 != null && !keys1.isEmpty() ? List_.first(keys1) : boundingKey(hash, 1);
Streamlet<Bytes> st = store.mutateData().keys(keyUtil.toBytes(minKey), increment(keyUtil.toBytes(maxKey)));
return st.concatMap(bytes -> {
NameKey key = keyUtil.toNameKey(bytes);
List<NameKey> prefix1 = List_.concat(prefix, List.of(key));
if (key.size == 0) {
List<NameKey> tailKeys0 = key == minKey ? !keys0.isEmpty() ? List_.right(keys0, 1) : emptyKeys : null;
List<NameKey> tailKeys1 = key == maxKey ? !keys1.isEmpty() ? List_.right(keys1, 1) : emptyKeys : null;
return list(prefix1, tailKeys0, tailKeys1);
} else
return Read.each(keyUtil.toName(prefix1));
});
}
use of suite.primitive.Bytes in project suite by stupidsing.
the class HttpUtil method httpApache.
private static HttpResult httpApache(String method, URL url, Outlet<Bytes> in, Map<String, String> headers) throws IOException {
LogUtil.info("START " + method + " " + url);
CloseableHttpClient client = HttpClients.createDefault();
HttpRequestBase request = new HttpRequestBase() {
{
setURI(URI.create(url.toString()));
headers.entrySet().forEach(e -> addHeader(e.getKey(), e.getValue()));
}
public String getMethod() {
return method;
}
};
CloseableHttpResponse response = client.execute(request);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
InputStream inputStream = response.getEntity().getContent();
Outlet<Bytes> out = //
To.outlet(inputStream).closeAtEnd(//
inputStream).closeAtEnd(//
response).closeAtEnd(//
client).closeAtEnd(() -> LogUtil.info("END__ " + method + " " + url));
if (statusCode == HttpURLConnection.HTTP_OK)
return new HttpResult(statusCode, out);
else
throw new IOException(//
"HTTP returned " + statusCode + ": " + //
url + ": " + //
statusLine.getReasonPhrase() + ": " + out.collect(As::string));
}
use of suite.primitive.Bytes in project suite by stupidsing.
the class LazyIbTreeExtentFilePersister method saveSlot.
private Extent saveSlot(int start, PersistSlot<T> value) {
int bs = ExtentFile.blockSize;
Bytes bytes = To.bytes(dataOutput -> serializer.write(dataOutput, value));
Extent extent = new Extent(start, start + (bytes.size() + bs - 1) / bs);
extentFile.save(extent, bytes);
return extent;
}
use of suite.primitive.Bytes in project suite by stupidsing.
the class ElfWriter method write.
private void write(int org, Bytes code, DataOutput_ do_) throws IOException {
Bytes header = //
new Writer_().db(// e_ident
0x7F).append(//
"ELF".getBytes(Constants.charset)).append(//
new byte[] { 1, 1, 1, 0 }).append(//
new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }).dw(// e_type
2).dw(// e_machine
3).dd(// e_version
1).dd(// e_entry
org + 84).dd(// e_phoff
52).dd(// e_shoff
0).dd(// e_flags
0).dw(// e_ehsize
52).dw(// e_phentsize
32).dw(// e_phnum
1).dw(// e_shentsize
0).dw(// e_shnum
0).dw(// e_shstrndx
0).dd(// p_type
1).dd(// p_offset
0).dd(// p_vaddr
org).dd(// p_paddr
org).dd(// p_filesz
code.size() + 84).dd(// p_memsz
code.size() + 84).dd(// p_flags PF_R|PF_W|PF_X
7).dd(// p_align
0x1000).toBytes();
do_.writeBytes(header);
do_.writeBytes(code);
}
Aggregations