Example usage for org.apache.solr.common.util JavaBinCodec marshal

List of usage examples for org.apache.solr.common.util JavaBinCodec marshal

Introduction

In this page you can find the example usage for org.apache.solr.common.util JavaBinCodec marshal.

Prototype

public void marshal(Object nl, OutputStream os) throws IOException 

Source Link

Usage

From source file:com.b2international.index.es.EsDocumentSearcher.java

License:Apache License

private String toSearchAfterToken(final Object[] searchAfter) {
    if (searchAfter == null) {
        return null;
    }//from www.  j  av  a 2 s  . c  om

    try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        final JavaBinCodec codec = new JavaBinCodec();
        codec.marshal(searchAfter, baos);
        codec.close();

        final byte[] tokenBytes = baos.toByteArray();
        return Base64.getUrlEncoder().encodeToString(tokenBytes);
    } catch (IOException e) {
        throw new FormattedRuntimeException("Couldn't encode searchAfter paramaters to a token.", e);
    }
}

From source file:org.alfresco.solr.content.SolrContentStore.java

License:Open Source License

/**
 * Stores a {@link SolrInputDocument} into Alfresco solr content store.
 * @param tenant/*  ww  w . j  av a2 s .c o m*/
 * @param dbId
 * @param doc
 * @throws IOException
 */
public void storeDocOnSolrContentStore(String tenant, long dbId, SolrInputDocument doc) throws IOException {
    ContentContext contentContext = SolrContentUrlBuilder.start().add(SolrContentUrlBuilder.KEY_TENANT, tenant)
            .add(SolrContentUrlBuilder.KEY_DB_ID, String.valueOf(dbId)).getContentContext();
    this.delete(contentContext.getContentUrl());
    ContentWriter writer = this.getWriter(contentContext);
    if (log.isDebugEnabled()) {
        log.debug("Writing doc to " + contentContext.getContentUrl());
    }
    try (OutputStream contentOutputStream = writer.getContentOutputStream();
            // Compresses the document
            GZIPOutputStream gzip = new GZIPOutputStream(contentOutputStream);) {
        JavaBinCodec codec = new JavaBinCodec(resolver);
        codec.marshal(doc, gzip);
    } catch (Exception e) {
        // A failure to write to the store is acceptable as long as it's logged
        log.warn("Failed to write to store using URL: " + contentContext.getContentUrl(), e);
    }
}

From source file:org.apache.beam.sdk.io.solr.JavaBinCodecCoder.java

License:Apache License

@Override
public void encode(T value, OutputStream outStream) throws IOException {
    if (value == null) {
        throw new CoderException("cannot encode a null SolrDocument");
    }//  w w  w . java 2s.  co  m

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JavaBinCodec codec = new JavaBinCodec();
    codec.marshal(value, baos);

    byte[] bytes = baos.toByteArray();
    VarInt.encode(bytes.length, outStream);
    outStream.write(bytes);
}

From source file:org.codelibs.elasticsearch.solr.solr.JavaBinUpdateRequestCodec.java

License:Apache License

/**
 * Converts an UpdateRequest to a NamedList which can be serialized to the
 * given OutputStream in the javabin format
 *
 * @param updateRequest//from www.  ja v  a2 s  .c  o m
 *            the UpdateRequest to be written out
 * @param os
 *            the OutputStream to which the request is to be written
 *
 * @throws IOException
 *             in case of an exception during marshalling or writing to the
 *             stream
 */
public void marshal(final UpdateRequest updateRequest, final OutputStream os) throws IOException {
    final NamedList nl = new NamedList();
    final NamedList params = solrParamsToNamedList(updateRequest.getParams());
    if (updateRequest.getCommitWithin() != -1) {
        params.add("commitWithin", updateRequest.getCommitWithin());
    }
    Iterator<SolrInputDocument> docIter = null;

    if (updateRequest.getDocuments() != null) {
        docIter = updateRequest.getDocuments().iterator();
    }
    if (updateRequest.getDocIterator() != null) {
        docIter = updateRequest.getDocIterator();
    }

    nl.add("params", params);// 0: params
    nl.add("delById", updateRequest.getDeleteById());
    nl.add("delByQ", updateRequest.getDeleteQuery());
    nl.add("docs", docIter);
    final JavaBinCodec codec = new JavaBinCodec();
    codec.marshal(nl, os);
}

From source file:org.vootoo.client.netty.NettySolrClientTest.java

License:Apache License

protected static void writeResponse(NamedList<Object> values, OutputStream out) throws IOException {
    JavaBinCodec codec = new JavaBinCodec(new MockResolver());
    codec.marshal(values, out);
}