Beispiel #1
0
  /**
   * Constructor.
   *
   * @param os output stream
   * @param sopts serializer options
   * @throws QueryIOException query I/O exception
   */
  protected OutputSerializer(final OutputStream os, final SerializerOptions sopts)
      throws QueryIOException {

    this.sopts = sopts;
    indent = sopts.yes(INDENT);

    // project-specific options
    indents = sopts.get(INDENTS);
    tab = sopts.yes(TABULATOR) ? '\t' : ' ';

    encoding = Strings.normEncoding(sopts.get(ENCODING), true);
    PrintOutput po;
    if (encoding == Strings.UTF8) {
      po = PrintOutput.get(os);
    } else {
      try {
        po = new EncoderOutput(os, Charset.forName(encoding));
      } catch (final Exception ex) {
        throw SERENCODING_X.getIO(encoding);
      }
    }
    final int limit = sopts.get(LIMIT);
    if (limit != -1) po.setLimit(limit);

    final byte[] nl = token(sopts.get(NEWLINE).newline());
    if (nl.length != 1 || nl[0] != '\n') po = new NewlineOutput(po, nl);
    out = po;
  }
Beispiel #2
0
 /**
  * Sets the item separator.
  *
  * @param def default separator
  */
 protected final void itemsep(final String def) {
   final String is = sopts.get(ITEM_SEPARATOR);
   itemsep = sopts.contains(ITEM_SEPARATOR) ? token(is) : def == null ? null : token(def);
 }