示例#1
0
 @Override
 public Memory unconvert(Environment env, TraceInfo trace, Number arg) throws Throwable {
   if (arg instanceof Double || arg instanceof Float) {
     return DoubleMemory.valueOf(arg.doubleValue());
   } else {
     return LongMemory.valueOf(arg.longValue());
   }
 }
示例#2
0
 @Signature
 public static Memory findAvailableLocalPort(Environment env, Memory... args) {
   try {
     ServerSocket serverSocket = new ServerSocket(0);
     serverSocket.close();
     return LongMemory.valueOf(serverSocket.getLocalPort());
   } catch (IOException e) {
     return Memory.FALSE;
   }
 }
示例#3
0
  @Override
  public Memory write(Environment env, Memory... args) throws IOException {
    int len = args[1].toInteger();
    byte[] bytes = args[0].getBinaryBytes();

    len = len == 0 || len > bytes.length ? bytes.length : len;

    getOutputStream().write(bytes, 0, len);

    return LongMemory.valueOf(len);
  }
示例#4
0
  @Signature
  public PSqlStatement query(Environment env, String sql, @Nullable ArrayMemory args)
      throws Throwable {
    PreparedStatement statement = connection.prepareStatement(sql);
    PSqlStatement sqlStatement = new PSqlStatement(env, statement);

    if (args != null) {
      int index = 0;

      for (ReferenceMemory arg : args) {
        env.invokeMethod(sqlStatement, "bind", LongMemory.valueOf(index), arg.value);
        index += 1;
      }
    }

    return sqlStatement;
  }
示例#5
0
 @Override
 public Memory getPosition(Environment env, Memory... args) {
   return LongMemory.valueOf(position);
 }