/** * Creates a binary response. */ public BytesRestResponse(RestStatus status, String contentType, byte[] content) { this(status, contentType, new BytesArray(content)); }
/** * Creates a new plain text response. */ public BytesRestResponse(RestStatus status, String content) { this(status, TEXT_CONTENT_TYPE, new BytesArray(content)); }
/** * Creates a new plain text response. */ public BytesRestResponse(RestStatus status, String contentType, String content) { this(status, contentType, new BytesArray(content)); }
@Test public void testComplianceLicenseMap() throws Exception { SearchGuardLicense license = new SearchGuardLicense(XContentHelper .convertToMap(new BytesArray(FileHelper.loadFile("license1.json")), false, JsonXContent.jsonXContent.type()).v2(), cs); Assert.assertFalse(license.hasFeature(Feature.COMPLIANCE)); Assert.assertArrayEquals(license.getFeatures(), new Feature[0]); license = new SearchGuardLicense(XContentHelper .convertToMap(new BytesArray(FileHelper.loadFile("license3.json")), false, JsonXContent.jsonXContent.type()).v2(), cs); Assert.assertFalse(license.hasFeature(Feature.COMPLIANCE)); Assert.assertArrayEquals(license.getFeatures(), new Feature[0]); license = new SearchGuardLicense(XContentHelper .convertToMap(new BytesArray(FileHelper.loadFile("license2.json")), false, JsonXContent.jsonXContent.type()).v2(), cs); Assert.assertTrue(license.hasFeature(Feature.COMPLIANCE)); Assert.assertArrayEquals(license.getFeatures(), Feature.values()); }
/** * Returns a {@link BytesReference} view of the data. */ public BytesReference bytes() { if (bytes == null) { bytes = new BytesArray(text.getBytes(StandardCharsets.UTF_8)); } return bytes; }
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source * @param xContentType The type of content contained within the source */ public PutIndexTemplateRequest mapping(String type, String source, XContentType xContentType) { return mapping(type, new BytesArray(source), xContentType); }
/** * Sets the document source to index. * * Note, its preferable to either set it using {@link #source(org.elasticsearch.common.xcontent.XContentBuilder)} * or using the {@link #source(byte[], XContentType)}. */ public IndexRequest source(String source, XContentType xContentType) { return source(new BytesArray(source), xContentType); }
/** * Sets the aliases that will be associated with the index when it gets created */ public PutIndexTemplateRequest aliases(String source) { return aliases(new BytesArray(source)); }
/** * Reads a bytes reference from this stream, might hold an actual reference to the underlying * bytes of the stream. */ public BytesReference readBytesReference(int length) throws IOException { if (length == 0) { return BytesArray.EMPTY; } byte[] bytes = new byte[length]; readBytes(bytes, 0, length); return new BytesArray(bytes, 0, length); }
/** * Sets the document to index in bytes form (assumed to be safe to be used from different * threads). * * @param source The source to index * @param offset The offset in the byte array * @param length The length of the data */ public IndexRequest source(byte[] source, int offset, int length, XContentType xContentType) { return source(new BytesArray(source, offset, length), xContentType); }
/** * The mapping source definition. */ public PutMappingRequest source(String mappingSource, XContentType xContentType) { return source(new BytesArray(mappingSource), xContentType); }
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source * @param xContentType The content type of the source */ public CreateIndexRequest mapping(String type, String source, XContentType xContentType) { return mapping(type, new BytesArray(source), xContentType); }
/** * Sets the settings and mappings as a single source. */ public CreateIndexRequest source(String source, XContentType xContentType) { return source(new BytesArray(source), xContentType); }
/** * Sets the settings and mappings as a single source. */ public CreateIndexRequest source(byte[] source, int offset, int length, XContentType xContentType) { return source(new BytesArray(source, offset, length), xContentType); }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (source != null) { try (InputStream stream = new BytesArray(source).streamInput()) { builder.rawValue(stream, XContentType.JSON); } } else { builder.startObject().endObject(); } return builder; } }
@Override public void binaryField(FieldInfo fieldInfo, byte[] value) throws IOException { if (sourceFieldName.equals(fieldInfo.name)) { source = new BytesArray(value); } else if (IdFieldMapper.NAME.equals(fieldInfo.name)) { id = Uid.decodeId(value); } else { addValue(fieldInfo.name, new BytesRef(value)); } }
/** * Adds a framed data in binary format */ public BulkRequest add(byte[] data, int from, int length, @Nullable String defaultIndex, @Nullable String defaultType, XContentType xContentType) throws IOException { return add(new BytesArray(data, from, length), defaultIndex, defaultType, xContentType); }
@Override public void write(byte[] b, int offset, int length) throws IOException { sendNextChunk(position, new BytesArray(b, offset, length), md.length() == position + length); position += length; assert md.length() >= position : "length: " + md.length() + " but positions was: " + position; }
@Override 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 new BytesArray(out.bytes().toBytesRef(), true);// do a deep copy }
public ParsedDocument createNoopTombstoneDoc(String index, String reason) throws MapperParsingException { final String id = ""; // _id won't be used. final SourceToParse sourceToParse = SourceToParse.source(index, type, id, new BytesArray("{}"), XContentType.JSON); final ParsedDocument parsedDoc = documentParser.parseDocument(sourceToParse, noopTombstoneMetadataFieldMappers).toTombstone(); // Store the reason of a noop as a raw string in the _source field final BytesRef byteRef = new BytesRef(reason); parsedDoc.rootDoc().add(new StoredField(SourceFieldMapper.NAME, byteRef.bytes, byteRef.offset, byteRef.length)); return parsedDoc; }