Esempio n. 1
0
  /**
   * Reads the total remaining String from inputPort.
   *
   * <p>Convenience method for module implementations that need the whole input present before
   * processing can begin.
   *
   * @param inputPort the port to read from
   * @return The String read
   * @throws IOException if an IO-Error occurs
   * @throws NotSupportedException if the InputPort does not provide a char pipe to read from.
   * @throws InterruptedException if the Thread has been interrupted.
   */
  protected String readStringFromInputPort(InputPort inputPort) throws Exception {

    if (!inputPort.isConnected()) {
      throw new Exception("inputPort is not connected");
    }

    final StringBuilder stringBuilder = new StringBuilder();
    int charCode = inputPort.getInputReader().read();

    while (charCode != -1) {
      if (Thread.interrupted()) {
        throw new InterruptedException("Thread has been interrupted.");
      }
      stringBuilder.append((char) charCode);
      charCode = inputPort.getInputReader().read();
    }

    return stringBuilder.toString();
  }
Esempio n. 2
0
 /**
  * Adds the specified input port.
  *
  * @param port Port to add
  */
 public void addInputPort(InputPort port) {
   this.inputPorts.put(port.getName(), port);
 }