Beispiel #1
0
 /**
  * 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());
 }
Beispiel #2
0
 /**
  * Sends an event to the registered sessions.
  *
  * @param ctx query context
  * @return event result
  * @throws QueryException query exception
  */
 private Item event(final QueryContext ctx) throws QueryException {
   final byte[] name = checkStr(expr[0], ctx);
   final ArrayOutput ao = new ArrayOutput();
   try {
     // run serialization
     final Serializer ser = Serializer.get(ao, ctx.serProp(true));
     final ValueIter ir = ctx.value(expr[1]).iter();
     for (Item it; (it = ir.next()) != null; ) it.serialize(ser);
     ser.close();
   } catch (final SerializerException ex) {
     throw ex.getCause(input);
   } catch (final IOException ex) {
     SERANY.thrw(input, ex);
   }
   // throw exception if event is unknown
   if (!ctx.context.events.notify(ctx.context, name, ao.toArray())) {
     NOEVENT.thrw(input, name);
   }
   return null;
 }
Beispiel #3
0
 /**
  * Returns the output as byte array.
  *
  * @return byte array
  */
 public final byte[] toArray() {
   return ao.toArray();
 }