Package org.elasticsearch.common.io.stream

Examples of org.elasticsearch.common.io.stream.BytesStreamOutput.bytes()


                    // we need to reread and store back, compressed....
                    BytesStreamOutput bStream = new BytesStreamOutput();
                    XContentBuilder builder = XContentFactory.contentBuilder(formatContentType, bStream);
                    builder.copyCurrentStructure(XContentFactory.xContent(contentType).createParser(source));
                    builder.close();
                    source = bStream.bytes();
                    // update the data in the context, so we store it in the translog in this format
                    context.source(source);
                }
            }
        }
View Full Code Here


    private static boolean verifyCacheSerializationSameAsQueryResult(BytesReference cacheData, SearchContext context, QuerySearchResult result) throws Exception {
        BytesStreamOutput out1 = new BytesStreamOutput();
        new BytesQuerySearchResult(context.id(), context.shardTarget(), cacheData).writeTo(out1);
        BytesStreamOutput out2 = new BytesStreamOutput();
        result.writeTo(out2);
        return out1.bytes().equals(out2.bytes());
    }

    private static Key buildKey(ShardSearchRequest request, SearchContext context) throws Exception {
        // TODO: for now, this will create different keys for different JSON order
        // TODO: tricky to get around this, need to parse and order all, which can be expensive
View Full Code Here

            queryPhase.execute(context);
            BytesStreamOutput out = new BytesStreamOutput();
            context.queryResult().writeToNoId(out);
            // for now, keep the paged data structure, which might have unused bytes to fill a page, but better to keep
            // the memory properly paged instead of having varied sized bytes
            BytesReference value = out.bytes();
            assert verifyCacheSerializationSameAsQueryResult(value, context, context.queryResult());
            loaded = true;
            key.shard.queryCache().onCached(key, value);
            return value;
        }
View Full Code Here

    public BytesReference cacheKey() throws IOException {
        BytesStreamOutput out = new BytesStreamOutput();
        this.innerWriteTo(out, true);
        // copy it over, most requests are small, we might as well copy to make sure we are not sliced...
        // we could potentially keep it without copying, but then pay the price of extra unused bytes up to a page
        return out.bytes().copyBytesArray();
    }
}
View Full Code Here

     * @throws IOException in case of I/O errors
     */
    public static byte[] copyToByteArray(InputStream in) throws IOException {
        BytesStreamOutput out = new BytesStreamOutput();
        copy(in, out);
        return out.bytes().toBytes();
    }


    //---------------------------------------------------------------------
    // Copy methods for java.io.Reader / java.io.Writer
View Full Code Here

            builder.value(snapshot.getSnapshot());
        }
        builder.endArray();
        builder.endObject();
        builder.close();
        BytesReference bRef = bStream.bytes();
        try (OutputStream output = snapshotsBlobContainer.createOutput(SNAPSHOTS_FILE)) {
            bRef.writeTo(output);
        }
    }
View Full Code Here

            }
            StreamInput compressed = compressor.streamInput(bytes.streamInput());
            BytesStreamOutput bStream = new BytesStreamOutput();
            Streams.copy(compressed, bStream);
            compressed.close();
            return bStream.bytes();
        }
        return bytes;
    }
}
View Full Code Here

                out.append(" | ");
                pad(new Table.Cell(cell.attr.containsKey("desc") ? cell.attr.get("desc") : "not available"), width[2], request, out);
                out.append("\n");
            }
            out.close();
            channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOutput.bytes(), true));
        } else {
            doRequest(request, channel, client);
        }
    }
}
View Full Code Here

                new MoveAllocationCommand(new ShardId("test", 3), "node2", "node3"),
                new CancelAllocationCommand(new ShardId("test", 4), "node5", true)
        );
        BytesStreamOutput bytes = new BytesStreamOutput();
        AllocationCommands.writeTo(commands, bytes);
        AllocationCommands sCommands = AllocationCommands.readFrom(new BytesStreamInput(bytes.bytes()));

        assertThat(sCommands.commands().size(), equalTo(3));
        assertThat(((AllocateAllocationCommand) (sCommands.commands().get(0))).shardId(), equalTo(new ShardId("test", 1)));
        assertThat(((AllocateAllocationCommand) (sCommands.commands().get(0))).node(), equalTo("node1"));
        assertThat(((AllocateAllocationCommand) (sCommands.commands().get(0))).allowPrimary(), equalTo(true));
View Full Code Here

                    new MappingMetaData.Id(null), new MappingMetaData.Routing(false, null), timestamp, false);

            BytesStreamOutput out = new BytesStreamOutput();
            MappingMetaData.writeTo(expected, out);
            out.close();
            BytesReference bytes = out.bytes();

            MappingMetaData metaData = MappingMetaData.readFrom(new BytesStreamInput(bytes));

            assertThat(metaData, is(expected));
        }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.