@Override public void encode(T value, OutputStream outStream) throws IOException { if (value == null) { throw new CoderException("cannot encode a null SolrDocument"); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); JavaBinCodec codec = new JavaBinCodec(); codec.marshal(value, baos); byte[] bytes = baos.toByteArray(); VarInt.encode(bytes.length, outStream); outStream.write(bytes); }
@Override public void write(OutputStream os) throws IOException { if (useBinary) { new JavaBinCodec().marshal(payload, os); } else { Utils.writeJson(payload, os, false); } }
/** * Write the response object in JavaBin format. * * @param obj the response object * @param channel the ES RestChannel */ private void writeJavaBinResponse(NamedList<Object> obj, RestChannel channel) { ByteArrayOutputStream bo = new ByteArrayOutputStream(); // try to marshal the data try { new JavaBinCodec().marshal(obj, bo); } catch (IOException e) { logger.error("Error writing JavaBin response", e); } // send the response channel.sendResponse(new BytesRestResponse(bo.toByteArray(), contentTypeOctet)); }
public static InputStream toJavabin(Object o) throws IOException { try (final JavaBinCodec jbc = new JavaBinCodec()) { BinaryRequestWriter.BAOS baos = new BinaryRequestWriter.BAOS(); jbc.marshal(o,baos); return new ByteBufferInputStream(ByteBuffer.wrap(baos.getbuf(),0,baos.size())); } }
/** * TODO -- there may be a way to do this without marshal at all... * * @param req * @param rsp * * @return a response object equivalent to what you get from the XML/JSON/javabin parser. Documents become * SolrDocuments, DocList becomes SolrDocumentList etc. * * @since solr 1.4 */ @SuppressWarnings("unchecked") public static NamedList<Object> getParsedResponse(SolrQueryRequest req, SolrQueryResponse rsp) { try { Resolver resolver = new Resolver(req, rsp.getReturnFields()); ByteArrayOutputStream out = new ByteArrayOutputStream(); new JavaBinCodec(resolver).marshal(rsp.getValues(), out); InputStream in = new ByteArrayInputStream(out.toByteArray()); return (NamedList<Object>) new JavaBinCodec(resolver).unmarshal(in); } catch (Exception ex) { throw new RuntimeException(ex); } }
@Override public void write(OutputStream os) throws IOException { new JavaBinCodec().marshal((IteratorWriter) iw -> { while (payload.hasNext()) { Pair<NamedList, Object> next = payload.next(); if (next.second() instanceof ByteBuffer || next.second() instanceof byte[]) { NamedList params = next.first(); if(params.get(ASSUME_CONTENT_TYPE) == null){ String detectedType = detect(next.second()); if(detectedType==null){ throw new RuntimeException("Unknown content type"); } params.add(ASSUME_CONTENT_TYPE, detectedType); } iw.add(params); iw.add(next.second()); } else { throw new RuntimeException("payload value must be byte[] or ByteBuffer"); } } }, os); }
public void write(OutputStream out, SolrQueryRequest req, SolrQueryResponse response) throws IOException { Resolver resolver = new Resolver(req, response.getReturnFields()); Boolean omitHeader = req.getParams().getBool(CommonParams.OMIT_HEADER); if (omitHeader != null && omitHeader) response.getValues().remove("responseHeader"); JavaBinCodec codec = new JavaBinCodec(resolver); codec.marshal(response.getValues(), out); }
codec.marshal(nl, os);
codec.marshal(nl, os);