use of php.runtime.memory.BinaryMemory in project jphp by jphp-compiler.
the class OutputBuffer method doFlush.
protected void doFlush(boolean flush) throws Throwable {
/*if (buffer.size() == 0)
return;*/
if (flush) {
isFlushed = true;
if (status != HANDLER_START && status != HANDLER_FLUSH)
status = HANDLER_WRITE;
} else {
if (status == HANDLER_FINAL)
status |= HANDLER_CLEAN;
else
status = HANDLER_CLEAN;
}
if (invoker != null) {
invoker.setTrace(trace == null ? TraceInfo.UNKNOWN : trace);
Memory[] args;
if (!binaryInBuffer) {
args = new Memory[] { new StringMemory(buffer.toString(environment.getDefaultCharset().name())), null };
} else
args = new Memory[] { new BinaryMemory(buffer.toByteArray()), null };
args[1] = LongMemory.valueOf(status);
invoker.setTrace(trace == null ? TraceInfo.UNKNOWN : trace);
Memory result;
incLock();
try {
result = invoker.call(args).toValue();
} finally {
decLock();
}
if (result != Memory.FALSE) {
byte[] data = result instanceof BinaryMemory ? result.getBinaryBytes(environment.getDefaultCharset()) : result.toString().getBytes(environment.getDefaultCharset());
if (flush) {
if (output == null)
parentOutput.write(data);
else
output.write(data);
reset();
status = HANDLER_FLUSH;
}
return;
}
}
if (flush) {
status |= HANDLER_FLUSH;
if (output == null)
parentOutput.write(buffer.toByteArray());
else
buffer.writeTo(output);
reset();
}
}
use of php.runtime.memory.BinaryMemory in project jphp by jphp-compiler.
the class BinaryCharArrayMemory method valueOfIndex.
@Override
public Memory valueOfIndex(TraceInfo trace, String index) {
int _index = -1;
Memory tmp = StringMemory.toLong(index);
if (tmp != null)
_index = tmp.toInteger();
if (_index >= 0 && _index < buffer.length())
return new BinaryMemory(buffer.charAt(_index));
else
return CONST_EMPTY_STRING;
}
use of php.runtime.memory.BinaryMemory in project jphp by jphp-compiler.
the class PSqlStatement method bind.
@Signature
public void bind(Environment env, int index, Memory value) throws SQLException {
if (value.instanceOf(WrapTime.class)) {
WrapTime time = value.toObject(WrapTime.class);
statement.setDate(index + 1, new Date(time.getDate().getTime()), time.getCalendar());
} else if (value.instanceOf(Stream.class)) {
statement.setBlob(index + 1, Stream.getInputStream(env, value));
} else if (value.toValue() instanceof BinaryMemory) {
statement.setBytes(index + 1, value.getBinaryBytes(env.getDefaultCharset()));
} else {
if (value.isNull()) {
statement.setNull(index + 1, Types.NULL);
} else {
switch(value.getRealType()) {
case INT:
statement.setLong(index + 1, value.toLong());
break;
case DOUBLE:
statement.setDouble(index + 1, value.toDouble());
break;
case BOOL:
statement.setBoolean(index + 1, value.toBoolean());
break;
default:
statement.setString(index + 1, value.toString());
}
}
}
}
use of php.runtime.memory.BinaryMemory in project jphp by jphp-compiler.
the class BinUtils method of.
@FastMethod
@Signature(@Arg("value"))
public static Memory of(Environment env, Memory... args) {
if (ParameterEntity.checkTypeHinting(env, args[0], HintType.TRAVERSABLE)) {
ForeachIterator iterator = args[0].getNewIterator(env, false, false);
ByteArrayOutputStream tmp = new ByteArrayOutputStream();
while (iterator.next()) {
tmp.write(iterator.getValue().toInteger());
}
return new BinaryMemory(tmp.toByteArray());
}
return new BinaryMemory(args[0].getBinaryBytes(env.getDefaultCharset()));
}
use of php.runtime.memory.BinaryMemory in project jphp by jphp-compiler.
the class ResourceStream method readFully.
@Override
@Signature
public Memory readFully(Environment env, Memory... args) throws IOException {
ByteArrayOutputStream tmp = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int read;
while ((read = stream.read(buf)) > 0) {
tmp.write(buf, 0, read);
position += read;
}
return new BinaryMemory(tmp.toByteArray());
}
Aggregations