/** * Creates a query builder given a query provided as a {@link BytesReference} */ public WrapperQueryBuilder(BytesReference source) { this.source = source.array(); this.offset = source.arrayOffset(); this.length = source.length(); }
/** * Returns a {@link String} view of the data. */ public String string() { if (text == null) { if (!bytes.hasArray()) { bytes = bytes.toBytesArray(); } text = new String(bytes.array(), bytes.arrayOffset(), bytes.length(), StandardCharsets.UTF_8); } return text; }
public static int bytesHashCode(BytesReference a) { if (a.hasArray()) { return hashCode(a.array(), a.arrayOffset(), a.length()); } else { return slowHashCode(a); } }
public static StreamInput wrap(BytesReference reference) { if (reference.hasArray() == false) { reference = reference.toBytesArray(); } return wrap(reference.array(), reference.arrayOffset(), reference.length()); }
@Override public XContentParser createParser(BytesReference bytes) throws IOException { if (bytes.hasArray()) { return createParser(bytes.array(), bytes.arrayOffset(), bytes.length()); } return createParser(bytes.streamInput()); }
/** * Writes the binary content of the given BytesReference * Use {@link org.elasticsearch.common.xcontent.XContentParser#binaryValue()} to read the value back */ public XContentBuilder field(String name, BytesReference value) throws IOException { field(name); if (!value.hasArray()) { value = value.toBytesArray(); } generator.writeBinary(value.array(), value.arrayOffset(), value.length()); return this; }
@Override public XContentParser createParser(BytesReference bytes) throws IOException { if (bytes.hasArray()) { return createParser(bytes.array(), bytes.arrayOffset(), bytes.length()); } return createParser(bytes.streamInput()); }
/** * Writes the binary content of the given BytesReference * Use {@link org.elasticsearch.common.xcontent.XContentParser#binaryValue()} to read the value back */ public XContentBuilder field(XContentBuilderString name, BytesReference value) throws IOException { field(name); if (!value.hasArray()) { value = value.toBytesArray(); } generator.writeBinary(value.array(), value.arrayOffset(), value.length()); return this; }
@Override public XContentParser createParser(BytesReference bytes) throws IOException { if (bytes.hasArray()) { return createParser(bytes.array(), bytes.arrayOffset(), bytes.length()); } return createParser(bytes.streamInput()); }
@Override public XContentParser createParser(BytesReference bytes) throws IOException { if (bytes.hasArray()) { return createParser(bytes.array(), bytes.arrayOffset(), bytes.length()); } return createParser(bytes.streamInput()); }
/** * Writes the binary content of the given BytesReference * Use {@link org.elasticsearch.common.xcontent.XContentParser#binaryValue()} to read the value back */ public XContentBuilder value(BytesReference value) throws IOException { if (value == null) { return nullValue(); } if (!value.hasArray()) { value = value.toBytesArray(); } generator.writeBinary(value.array(), value.arrayOffset(), value.length()); return this; }
if (a.hasArray() && b.hasArray()) { final byte[] aBytes = a.array(); int aUpto = a.arrayOffset(); final byte[] bBytes = b.array(); int bUpto = b.arrayOffset();
protected void copyRawValue(BytesReference content, XContent xContent) throws IOException { XContentParser parser = null; try { if (content.hasArray()) { parser = xContent.createParser(content.array(), content.arrayOffset(), content.length()); } else { parser = xContent.createParser(content.streamInput()); } copyCurrentStructure(parser); } finally { if (parser != null) { parser.close(); } } }
builder.flush(); BytesReference bytes = os.bytes(); out.write(bytes.array(), bytes.arrayOffset(), bytes.length()); out.write('\n'); out.flush();
public static String convertToJson(BytesReference bytes, boolean reformatJson, boolean prettyPrint) throws IOException { if (bytes.hasArray()) { return convertToJson(bytes.array(), bytes.arrayOffset(), bytes.length(), reformatJson, prettyPrint); } XContentType xContentType = XContentFactory.xContentType(bytes); if (xContentType == XContentType.JSON && !reformatJson) { BytesArray bytesArray = bytes.toBytesArray(); return new String(bytesArray.array(), bytesArray.arrayOffset(), bytesArray.length(), Charsets.UTF_8); } try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(bytes.streamInput())) { parser.nextToken(); XContentBuilder builder = XContentFactory.jsonBuilder(); if (prettyPrint) { builder.prettyPrint(); } builder.copyCurrentStructure(parser); return builder.string(); } }
/** * Marks this store as corrupted. This method writes a <tt>corrupted_${uuid}</tt> file containing the given exception * message. If a store contains a <tt>corrupted_${uuid}</tt> file {@link #isMarkedCorrupted()} will return <code>true</code>. */ public void markStoreCorrupted(IOException exception) throws IOException { ensureOpen(); if (!isMarkedCorrupted()) { String uuid = CORRUPTED + Strings.randomBase64UUID(); try (IndexOutput output = this.directory().createOutput(uuid, IOContext.DEFAULT)) { CodecUtil.writeHeader(output, CODEC, VERSION); BytesStreamOutput out = new BytesStreamOutput(); out.writeThrowable(exception); BytesReference bytes = out.bytes(); output.writeVInt(bytes.length()); output.writeBytes(bytes.array(), bytes.arrayOffset(), bytes.length()); CodecUtil.writeFooter(output); } catch (IOException ex) { logger.warn("Can't mark store as corrupted", ex); } directory().sync(Collections.singleton(uuid)); } }
public XContentBuilder field(String name, Text value) throws IOException { field(name); if (value.hasBytes() && value.bytes().hasArray()) { generator.writeUTF8String(value.bytes().array(), value.bytes().arrayOffset(), value.bytes().length()); return this; } if (value.hasString()) { generator.writeString(value.string()); return this; } // TODO: TextBytesOptimization we can use a buffer here to convert it? maybe add a request to jackson to support InputStream as well? BytesArray bytesArray = value.bytes().toBytesArray(); generator.writeUTF8String(bytesArray.array(), bytesArray.arrayOffset(), bytesArray.length()); return this; }
public XContentBuilder field(XContentBuilderString name, Text value) throws IOException { field(name); if (value.hasBytes() && value.bytes().hasArray()) { generator.writeUTF8String(value.bytes().array(), value.bytes().arrayOffset(), value.bytes().length()); return this; } if (value.hasString()) { generator.writeString(value.string()); return this; } // TODO: TextBytesOptimization we can use a buffer here to convert it? maybe add a request to jackson to support InputStream as well? BytesArray bytesArray = value.bytes().toBytesArray(); generator.writeUTF8String(bytesArray.array(), bytesArray.arrayOffset(), bytesArray.length()); return this; }
public XContentBuilder value(Text value) throws IOException { if (value == null) { return nullValue(); } if (value.hasBytes() && value.bytes().hasArray()) { generator.writeUTF8String(value.bytes().array(), value.bytes().arrayOffset(), value.bytes().length()); return this; } if (value.hasString()) { generator.writeString(value.string()); return this; } BytesArray bytesArray = value.bytes().toBytesArray(); generator.writeUTF8String(bytesArray.array(), bytesArray.arrayOffset(), bytesArray.length()); return this; }
indexOutput.writeBytes(content.array(), content.arrayOffset(), content.length()); indexState.addRecoveredBytesToFile(request.name(), content.length()); if (indexOutput.getFilePointer() >= request.length() || request.lastChunk()) {