Ejemplo n.º 1
0
  /**
   * Read string until newline or end of stream
   *
   * @param in
   * @throws java.io.IOException
   */
  private String readln(DSpaceTokenStream in) throws IOException {

    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    int b = in.read();

    while ((b != -1) && (b != '\r')) {
      bos.write(b);
      b = in.read();
    }

    if (b == '\r') {
      in.read(); // read '\n'
    }

    return new String(bos.toByteArray(), this.characterEncoding);
  }
Ejemplo n.º 2
0
  /**
   * Parse an inline part
   *
   * @param in
   * @param headers
   * @throws java.io.IOException
   */
  private void parseInlinePart(DSpaceTokenStream in, Hashtable headers) throws IOException {

    // Buffer incoming bytes for proper string decoding (there can be multibyte chars)
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    while (in.getState() == DSpaceTokenStream.STATE_READING) {
      int c = in.read();
      if (c != -1) bos.write(c);
    }

    String field = (String) headers.get("name");
    Vector v = (Vector) this.parts.get(field);

    if (v == null) {
      v = new Vector();
      this.parts.put(field, v);
    }

    v.add(new String(bos.toByteArray(), this.characterEncoding));
  }