streammodule.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 603 行 · 第 1/2 页

JAVA
603
字号
        length = Integer.MAX_VALUE;      StringValue line = file.readLine(length);      if (line == null)        return BooleanValue.FALSE;      int lineLength = line.length();      if (lineLength == 0)        return line;      char tail = line.charAt(lineLength - 1);      if (tail == '\n')        return line.substring(0, line.length() - 1);      else if (tail == '\r')        return line.substring(0, line.length() - 1);      else        return line;    } catch (IOException e) {      throw new QuercusModuleException(e);    }  }  /**   * Returns the metadata of this stream.   *    * XXX: TODO   */  public static Value stream_get_meta_data(Env env,                                           BinaryStream stream )  {    if (stream == null)      return BooleanValue.FALSE;        env.stub("stream_get_meta_data");        ArrayValue array = new ArrayValueImpl();        array.put(env.createString("timed_out"), BooleanValue.FALSE);        return array;  }  /**   * Returns the available transports.   */  public static Value stream_get_transports(Env env)  {    ArrayValue value = new ArrayValueImpl();    value.append(env.createString("tcp"));    value.append(env.createString("udp"));    return value;  }  /**   * Returns the available wrappers.   */  public static Value stream_get_wrappers(Env env)  {    return _wrapperArray;  }  public static boolean stream_register_wrapper(Env env, StringValue protocol,                                                String className)  {    return stream_wrapper_register(env, protocol, className);  }  /**   * stream_set_blocking is stubbed since Quercus should wait for   * any stream (unless a non-web-server Quercus is developed.)   */  public static boolean stream_set_blocking(Env env,                                            @NotNull Value stream,                                            int mode)  {    env.stub("stream_set_blocking()");        if (stream == null)      return false;    else      return true;  }    public static boolean stream_set_timeout(Env env,                                           @NotNull Value stream,                                           int seconds,                                           @Optional("-1") int milliseconds)  {    if (stream == null)      return false;    Object obj = stream.toJavaObject();    if (obj instanceof AbstractBinaryInputOutput)      ((AbstractBinaryInputOutput) obj).setTimeout(1000L * seconds);    return true;  }  /**   * Sets the write buffer.   */  public static int stream_set_write_buffer(Env env, BinaryOutput stream,                                            int bufferSize)  {    return 0;  }    /*   * Opens an Internet connection.   */  public static Value stream_socket_client(Env env,                                  @NotNull String remoteSocket,                                  @Optional @Reference Value errorInt,                                  @Optional @Reference Value errorStr,                                  @Optional("120.0") double timeout,                                  @Optional("STREAM_CLIENT_CONNECT") int flags,                                  @Optional StreamContextResource context)  {    try {      if (remoteSocket == null) {        env.warning("socket to connect to must not be null");        return BooleanValue.FALSE;      }            if (flags != STREAM_CLIENT_CONNECT) {        env.stub("unsupported stream_socket_client flag");      }            boolean isSecure = false;      remoteSocket = remoteSocket.trim();      int typeIndex = remoteSocket.indexOf("://");            if (typeIndex > 0) {        String type = remoteSocket.substring(0, typeIndex);        remoteSocket = remoteSocket.substring(typeIndex + 3);        if (type.equals("tcp")) {        }        else if (type.equals("ssl")) {          isSecure = true;        }        else {          env.warning(L.l("unrecognized socket transport: {0}", type));                    return BooleanValue.FALSE;        }      }      int colonIndex = remoteSocket.lastIndexOf(':');            String host = remoteSocket;      int port = 80;            if (colonIndex > 0) {        host = remoteSocket.substring(0, colonIndex);                port = 0;                for (int i = colonIndex + 1; i < remoteSocket.length(); i++) {          char ch = remoteSocket.charAt(i);                    if ('0' <= ch && ch <= '9')            port = port * 10 + ch - '0';          else            break;        }      }      Socket socket;            if (isSecure)        socket = SSLSocketFactory.getDefault().createSocket(host, port);      else        socket = SocketFactory.getDefault().createSocket(host, port);      socket.setSoTimeout((int) (timeout * 1000));      SocketInputOutput stream        = new SocketInputOutput(env, socket, SocketInputOutput.Domain.AF_INET);      stream.init();      return env.wrapJava(stream);    }    catch (UnknownHostException e) {      errorStr.set(env.createString(e.getMessage()));            return BooleanValue.FALSE;    }    catch (IOException e) {      errorStr.set(env.createString(e.getMessage()));            return BooleanValue.FALSE;    }  }  public static void stream_wrapper_register(StringValue protocol,                                              ProtocolWrapper wrapper)  {    _wrapperMap.put(protocol.toString(), wrapper);        _wrapperArray.append(protocol);  }  /**   * Register a wrapper for a protocol.   */  public static boolean stream_wrapper_register(Env env, StringValue protocol,                                                String className)  {    if (_wrapperMap.containsKey(protocol.toString()))      return false;    QuercusClass qClass = env.getClass(className);    stream_wrapper_register(protocol, new ProtocolWrapper(qClass));        return true;  }  /**   * Register a wrapper for a protocol.   */  public static boolean stream_wrapper_restore(Env env, StringValue protocol)  {    if (! _unregisteredWrapperMap.containsKey(protocol.toString()))      return false;    ProtocolWrapper oldWrapper =       _unregisteredWrapperMap.remove(protocol.toString());    stream_wrapper_register(protocol, oldWrapper);    return true;  }  /**   * Register a wrapper for a protocol.   */  public static boolean stream_wrapper_unregister(Env env, StringValue protocol)  {    if (! _wrapperMap.containsKey(protocol.toString()))      return false;    _unregisteredWrapperMap.put(protocol.toString(),                                 _wrapperMap.remove(protocol.toString()));    _wrapperArray.remove(protocol);    return true;  }  protected static ProtocolWrapper getWrapper(String protocol)  {    return _wrapperMap.get(protocol);  }  static {    _wrapperArray.append(new StringBuilderValue("quercus"));    _wrapperArray.append(new StringBuilderValue("file"));    _wrapperArray.append(new StringBuilderValue("http"));    _wrapperArray.append(new StringBuilderValue("ftp"));  }  static {    _constMap.put("STREAM_URL_STAT_LINK", new LongValue(STREAM_URL_STAT_LINK));    _constMap.put("STREAM_URL_STAT_QUIET",                   new LongValue(STREAM_URL_STAT_QUIET));    _constMap.put("STREAM_FILTER_READ", new LongValue(STREAM_FILTER_READ));    _constMap.put("STREAM_FILTER_WRITE", new LongValue(STREAM_FILTER_WRITE));    _constMap.put("STREAM_FILTER_ALL", new LongValue(STREAM_FILTER_ALL));    _constMap.put("PSFS_PASS_ON", new LongValue(PSFS_PASS_ON));    _constMap.put("PSFS_FEED_ME", new LongValue(PSFS_FEED_ME));    _constMap.put("PSFS_ERR_FATAL", new LongValue(PSFS_ERR_FATAL));    _constMap.put("STREAM_USE_PATH", new LongValue(STREAM_USE_PATH));    _constMap.put("STREAM_REPORT_ERRORS", new LongValue(STREAM_REPORT_ERRORS));    _constMap.put("STREAM_CLIENT_ASYNC_CONNECT",                  new LongValue(STREAM_CLIENT_ASYNC_CONNECT));    _constMap.put("STREAM_CLIENT_CONNECT",                  new LongValue(STREAM_CLIENT_CONNECT));    _constMap.put("STREAM_CLIENT_PERSISTENT",                  new LongValue(STREAM_CLIENT_PERSISTENT));    _constMap.put("STREAM_SERVER_BIND",                  new LongValue(STREAM_SERVER_BIND));    _constMap.put("STREAM_SERVER_LISTEN",                  new LongValue(STREAM_SERVER_LISTEN));  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?