Search in sources :

Example 51 with Bytes

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));
}
Also used : Condition(suite.concurrent.Condition) Mutable(suite.adt.Mutable) Bytes(suite.primitive.Bytes)

Example 52 with Bytes

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));
    });
}
Also used : Bytes(suite.primitive.Bytes) NameKey(suite.fs.impl.FileSystemKeyUtil.NameKey)

Example 53 with Bytes

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));
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Bytes(suite.primitive.Bytes) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) InputStream(java.io.InputStream) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException)

Example 54 with Bytes

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;
}
Also used : Bytes(suite.primitive.Bytes) Extent(suite.file.ExtentAllocator.Extent)

Example 55 with Bytes

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);
}
Also used : Bytes(suite.primitive.Bytes)

Aggregations

Bytes (suite.primitive.Bytes)56 Test (org.junit.Test)18 BytesBuilder (suite.primitive.Bytes.BytesBuilder)8 IOException (java.io.IOException)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Pair (suite.adt.pair.Pair)4 OutputStream (java.io.OutputStream)3 Path (java.nio.file.Path)3 To (suite.util.To)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Constants (suite.Constants)2 Amd64Interpret (suite.assembler.Amd64Interpret)2 Condition (suite.concurrent.Condition)2 Extent (suite.file.ExtentAllocator.Extent)2 JournalledPageFile (suite.file.JournalledPageFile)2 ImperativeCompiler (suite.ip.ImperativeCompiler)2 DataInput_ (suite.util.DataInput_)2