コード例 #1
0
ファイル: TextView.java プロジェクト: dirkk/basex
 /**
  * Sets the output text.
  *
  * @param out cached output
  */
 public void setText(final ArrayOutput out) {
   final byte[] buf = out.buffer();
   final int size = (int) out.size();
   final byte[] chop = token(DOTS);
   if (out.finished() && size >= chop.length) {
     System.arraycopy(chop, 0, buf, size - chop.length, chop.length);
   }
   text.setText(buf, size);
   header.setText((out.finished() ? CHOPPED : "") + RESULT);
   home.setEnabled(gui.context.data() != null);
 }
コード例 #2
0
 @Override
 protected String run(final String... args) throws IOException {
   try {
     final ArrayOutput ao = new ArrayOutput();
     System.setOut(new PrintStream(ao));
     System.setErr(NULL);
     new BaseX(args);
     return ao.toString();
   } finally {
     System.setOut(OUT);
     System.setErr(ERR);
   }
 }
コード例 #3
0
ファイル: TextView.java プロジェクト: dirkk/basex
 /**
  * Serializes the specified nodes.
  *
  * @param n nodes to display
  */
 private void setText(final DBNodes n) {
   if (visible()) {
     try {
       final ArrayOutput ao = new ArrayOutput();
       ao.setLimit(gui.gopts.get(GUIOptions.MAXTEXT));
       if (n != null) n.serialize(Serializer.get(ao));
       setText(ao);
       cmd = null;
       ns = ao.finished() ? n : null;
     } catch (final IOException ex) {
       Util.debug(ex);
     }
   } else {
     home.setEnabled(gui.context.data() != null);
   }
 }
コード例 #4
0
ファイル: TextView.java プロジェクト: dirkk/basex
  /**
   * Caches the output.
   *
   * @param out cached output
   * @param c command
   * @param r result
   * @throws QueryException query exception
   */
  public void cacheText(final ArrayOutput out, final Command c, final Result r)
      throws QueryException {

    // cache command or node set
    cmd = null;
    ns = null;

    final int mh = gui.context.options.get(MainOptions.MAXHITS);
    boolean parse = false;
    if (mh >= 0 && r != null && r.size() >= mh) {
      parse = true;
    } else if (out.finished()) {
      if (r instanceof DBNodes) ns = (DBNodes) r;
      else parse = true;
    }
    // create new command instance
    if (parse) cmd = new CommandParser(c.toString(), gui.context).parseSingle();
  }
コード例 #5
0
ファイル: SessionTest.java プロジェクト: runeengh/basex
 /**
  * Queries binary content (works only if output stream is specified).
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryBinary() throws IOException {
   if (out == null) return;
   session.execute("create db " + NAME);
   final byte[] tmp = {0, 1, 2, 127, 0, -1, -2, -128};
   session.store("X", new ArrayInput(tmp));
   final String retr = _DB_RETRIEVE.args(NAME, "X");
   // check command
   session.execute("xquery " + RAW + retr + ',' + retr);
   assertTrue(eq(out.toArray(), concat(tmp, tmp)));
   out.reset();
   // check query execution
   session.query(RAW + retr + ',' + retr).execute();
   assertTrue(eq(out.toArray(), concat(tmp, tmp)));
   out.reset();
   // check iterator
   final Query q = session.query(RAW + retr + ',' + retr);
   q.next();
   assertTrue(eq(out.toArray(), tmp));
   out.reset();
   q.next();
   assertTrue(eq(out.toArray(), tmp));
   assertNull(q.next());
 }
コード例 #6
0
ファイル: RESTCmd.java プロジェクト: LukasK/basex
 /**
  * Runs the specified command.
  *
  * @param c command
  * @return string result
  * @throws HTTPException HTTP exception
  */
 final String run(final Command c) throws HTTPException {
   final ArrayOutput ao = new ArrayOutput();
   run(c, ao);
   return ao.toString();
 }
コード例 #7
0
ファイル: SessionTest.java プロジェクト: runeengh/basex
 /**
  * Checks if the most recent output equals the specified string.
  *
  * @param exp expected string
  * @param ret string returned from the client API
  */
 private void assertEqual(final Object exp, final Object ret) {
   final String result = (out != null ? out : ret).toString();
   if (out != null) out.reset();
   assertEquals(exp.toString(), result.replaceAll("\\r|\\n", ""));
 }