/** * 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); }
/** * 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); } }
/** * 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(); }
/** * 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()); }
/** * 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", "")); }