예제 #1
0
 /**
  * Indents the next text.
  *
  * @throws IOException I/O exception
  */
 protected void indent() throws IOException {
   if (indent) {
     out.print('\n');
     final int ls = level * indents;
     for (int l = 0; l < ls; l++) out.print(tab);
   }
 }
예제 #2
0
파일: TextView.java 프로젝트: dirkk/basex
  /** Saves the displayed text. */
  private void save() {
    final BaseXFileChooser fc =
        new BaseXFileChooser(SAVE_AS, gui.gopts.get(GUIOptions.WORKPATH), gui).suffix(IO.XMLSUFFIX);

    final IO file = fc.select(Mode.FSAVE);
    if (file == null) return;
    gui.gopts.set(GUIOptions.WORKPATH, file.path());

    gui.cursor(CURSORWAIT, true);
    final MainOptions opts = gui.context.options;
    final int mh = opts.get(MainOptions.MAXHITS);
    opts.set(MainOptions.MAXHITS, -1);
    opts.set(MainOptions.CACHEQUERY, false);

    try (final PrintOutput out = new PrintOutput(file.toString())) {
      if (cmd != null) {
        cmd.execute(gui.context, out);
      } else if (ns != null) {
        ns.serialize(Serializer.get(out));
      } else {
        final byte[] txt = text.getText();
        for (final byte t : txt) if (t < 0 || t > ' ' || ws(t)) out.write(t);
      }
    } catch (final IOException ex) {
      BaseXDialog.error(gui, Util.info(FILE_NOT_SAVED_X, file));
    } finally {
      opts.set(MainOptions.MAXHITS, mh);
      opts.set(MainOptions.CACHEQUERY, true);
      gui.cursor(CURSORARROW, true);
    }
  }
예제 #3
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;
  }
예제 #4
0
 /**
  * Returns a hex entity for the specified codepoint.
  *
  * @param cp codepoint
  * @throws IOException I/O exception
  */
 protected final void printHex(final int cp) throws IOException {
   out.print("&#x");
   boolean o = false;
   for (int i = 3; i >= 0; i--) {
     final int b = (cp >> (i << 3)) & 0xFF;
     if (o || b > 0x0F) {
       out.print(HEX[b >> 4]);
     }
     if (o || b != 0) {
       out.print(HEX[b & 0xF]);
       o = true;
     }
   }
   out.print(';');
 }
예제 #5
0
 @Override
 public void close() throws IOException {
   out.flush();
 }
예제 #6
0
 @Override
 public final boolean finished() {
   return out.finished();
 }
예제 #7
0
 /**
  * Encodes the specified codepoint before printing.
  *
  * @param cp codepoint to be encoded and printed
  * @throws IOException I/O exception
  */
 protected void printChar(final int cp) throws IOException {
   out.print(cp);
 }