Search in sources :

Example 21 with Bytes

use of suite.primitive.Bytes in project suite by stupidsing.

the class ImperativeCompilerTest method testTag.

@Test
public void testTag() {
    String s = // 
    "constant optional = (tag ( | 0 struct () | 1 int));" + // 
    "declare optional i = newt optional 0 new ();" + // 
    "declare optional j = newt optional 1 2;" + "0";
    Bytes bytes = imperativeCompiler.compile(0, s);
    assertNotNull(bytes);
    System.out.println(bytes);
}
Also used : Bytes(suite.primitive.Bytes) Test(org.junit.Test)

Example 22 with Bytes

use of suite.primitive.Bytes in project suite by stupidsing.

the class ImperativeCompilerTest method testSubroutine.

@Test
public void testSubroutine() {
    Bytes bytes = imperativeCompiler.compile(0, "declare s = function [i,] ( i; ); declare s1 = s; s1 [1,];");
    assertNotNull(bytes);
    System.out.println(bytes);
}
Also used : Bytes(suite.primitive.Bytes) Test(org.junit.Test)

Example 23 with Bytes

use of suite.primitive.Bytes in project suite by stupidsing.

the class ImperativeCompilerTest method testExpr.

@Test
public void testExpr() {
    Bytes bytes = imperativeCompiler.compile(0, "null/* + 1 = 2;");
    assertNotNull(bytes);
    System.out.println(bytes);
}
Also used : Bytes(suite.primitive.Bytes) Test(org.junit.Test)

Example 24 with Bytes

use of suite.primitive.Bytes in project suite by stupidsing.

the class SerializedStoreCache method get.

public V get(K key, Source<V> source) {
    Bytes keyBytes = serialize(keySerializer, key);
    Bytes valueBytes = storeCache.get(keyBytes, () -> serialize(valueSerializer, source.source()));
    return Rethrow.ex(() -> {
        try (ByteArrayInputStream bais = new ByteArrayInputStream(valueBytes.toArray());
            DataInput_ dis = DataInput_.of(bais)) {
            return valueSerializer.read(dis);
        }
    });
}
Also used : Bytes(suite.primitive.Bytes) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInput_(suite.util.DataInput_)

Example 25 with Bytes

use of suite.primitive.Bytes in project suite by stupidsing.

the class To method inputStream.

public static InputStream inputStream(Outlet<Bytes> outlet) {
    return new InputStream() {

        private InputStream is;

        private boolean isOpen = true;

        public int read() throws IOException {
            byte[] b = new byte[1];
            int nBytesRead = read(b, 0, 1);
            return 0 < nBytesRead ? b[0] : nBytesRead;
        }

        public int read(byte[] bs, int offset, int length) throws IOException {
            int nBytesRead = -1;
            while (is == null || (nBytesRead = is.read(bs, offset, length)) < 0) {
                Bytes bytes = outlet.next();
                if (isOpen = (bytes != null))
                    is = bytes.collect(As::inputStream);
                else
                    break;
            }
            return nBytesRead;
        }

        public void close() throws IOException {
            if (isOpen) {
                byte[] bs = new byte[Constants.bufferSize];
                while (0 <= read(bs, 0, bs.length)) ;
            }
        }
    };
}
Also used : Bytes(suite.primitive.Bytes) As(suite.streamlet.As) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

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