Search in sources :

Example 6 with BinaryMemory

use of php.runtime.memory.BinaryMemory in project jphp by jphp-compiler.

the class ByteArrayInputStreamMemoryOperation method unconvert.

@Override
public Memory unconvert(Environment env, TraceInfo trace, ByteArrayInputStream arg) throws Throwable {
    byte[] buffer = new byte[4096];
    try {
        ByteBuffer result = ByteBuffer.allocate(20);
        int len;
        while ((len = arg.read(buffer)) > 0) {
            // nop
            result.put(buffer, 0, len);
        }
        return new BinaryMemory(result.array());
    } catch (IOException e) {
        throw new CriticalException(e);
    }
}
Also used : BinaryMemory(php.runtime.memory.BinaryMemory) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) CriticalException(php.runtime.exceptions.CriticalException)

Aggregations

BinaryMemory (php.runtime.memory.BinaryMemory)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Memory (php.runtime.Memory)2 StringMemory (php.runtime.memory.StringMemory)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1 Signature (php.runtime.annotation.Reflection.Signature)1 FastMethod (php.runtime.annotation.Runtime.FastMethod)1 CriticalException (php.runtime.exceptions.CriticalException)1 Stream (php.runtime.ext.core.classes.stream.Stream)1 WrapTime (php.runtime.ext.core.classes.time.WrapTime)1 ForeachIterator (php.runtime.lang.ForeachIterator)1 LongMemory (php.runtime.memory.LongMemory)1