@Override public boolean advanceNextPosition() { if (!searchHits.hasNext()) { return false; } SearchHit hit = searchHits.next(); fields = new ArrayList<>(Collections.nCopies(columnHandles.size(), null)); setFieldIfExists("_id", hit.getId()); setFieldIfExists("_index", hit.getIndex()); extractFromSource(hit); if (hit.getSourceRef() != null) { totalBytes += hit.getSourceRef().length(); } return true; }
if (ref == null || ref.length() == 0) { log.error("Empty or null byte reference for {}", id); return null;
final String type = singleGetResponse.getType(); final long version = singleGetResponse.getVersion(); if (ref == null || ref.length() == 0) { log.error("Empty or null byte reference for {}", type); return null;
/** * Check that the given BytesReference is neither <code>null</code> nor of length 0 * Note: Will return <code>true</code> for a BytesReference that purely consists of whitespace. * * @param bytesReference the BytesReference to check (may be <code>null</code>) * @return <code>true</code> if the BytesReference is not null and has length * @see #hasLength(CharSequence) */ public static boolean hasLength(BytesReference bytesReference) { return (bytesReference != null && bytesReference.length() > 0); }
@Override public long estimateSize() { return ((id.length() + type.length()) * 2) + source.length() + 12; }
@Override public boolean isCompressed(BytesReference bytes) { if (bytes.length() < HEADER.length) { return false; } for (int i = 0; i < HEADER.length; ++i) { if (bytes.get(i) != HEADER[i]) { return false; } } return true; }
@Override public long ramBytesUsed() { return BASE_RAM_BYTES_USED + entity.ramBytesUsed() + value.length(); }
/** * Creates a query builder given a query provided as a {@link BytesReference} */ public WrapperQueryBuilder(BytesReference source) { if (source == null || source.length() == 0) { throw new IllegalArgumentException("query source text cannot be null or empty"); } this.source = BytesRef.deepCopyOf(source.toBytesRef()).bytes; }
/** * Writes the data in a "thin" manner, without the actual bytes, assumes * the actual bytes will be appended right after this content. */ public void writeThin(StreamOutput out) throws IOException { super.writeTo(out); out.writeVInt(bytes.length()); }
void logOutboundMessage(TcpChannel channel, BytesReference message) { if (logger.isTraceEnabled()) { try { BytesReference withoutHeader = message.slice(HEADER_SIZE, message.length() - HEADER_SIZE); String logMessage = format(channel, withoutHeader, "WRITE"); logger.trace(logMessage); } catch (IOException e) { logger.trace("an exception occurred formatting a WRITE trace message", e); } } }
private MarkSupportingStreamInputWrapper(BytesReference reference) throws IOException { this.reference = reference; this.input = new BytesReferenceStreamInput(reference.iterator(), reference.length()); }
@Override public int estimatedSizeInBytes() { return (id().length() + type().length()) * 2 + source().length() + 12; }
private void writeAtomic(final String blobName, final BytesReference bytesRef, boolean failIfAlreadyExists) throws IOException { try (InputStream stream = bytesRef.streamInput()) { blobContainer().writeBlobAtomic(blobName, stream, bytesRef.length(), failIfAlreadyExists); } }
@Override public void reset() throws IOException { input = new BytesReferenceStreamInput(reference.iterator(), reference.length()); input.skip(mark); }
BulkRequest internalAdd(IndexRequest request, @Nullable Object payload) { Objects.requireNonNull(request, "'request' must not be null"); applyGlobalMandatoryParameters(request); requests.add(request); addPayload(payload); // lack of source is validated in validate() method sizeInBytes += (request.source() != null ? request.source().length() : 0) + REQUEST_OVERHEAD; indices.add(request.index()); return this; }
private static MapperParsingException wrapInMapperParsingException(SourceToParse source, Exception e) { // if its already a mapper parsing exception, no need to wrap it... if (e instanceof MapperParsingException) { return (MapperParsingException) e; } // Throw a more meaningful message if the document is empty. if (source.source() != null && source.source().length() == 0) { return new MapperParsingException("failed to parse, document is empty"); } return new MapperParsingException("failed to parse", e); }
/** * Writes the bytes reference, including a length header. */ public void writeBytesReference(@Nullable BytesReference bytes) throws IOException { if (bytes == null) { writeVInt(0); return; } writeVInt(bytes.length()); bytes.writeTo(this); }
/** * Writes an optional bytes reference including a length header. Use this if you need to differentiate between null and empty bytes * references. Use {@link #writeBytesReference(BytesReference)} and {@link StreamInput#readBytesReference()} if you do not. */ public void writeOptionalBytesReference(@Nullable BytesReference bytes) throws IOException { if (bytes == null) { writeVInt(0); return; } writeVInt(bytes.length() + 1); bytes.writeTo(this); }
/** true if the bytes were compressed with LZF: only used before elasticsearch 2.0 */ private static boolean isAncient(BytesReference bytes) { return bytes.length() >= 3 && bytes.get(0) == 'Z' && bytes.get(1) == 'V' && (bytes.get(2) == 0 || bytes.get(2) == 1); }
public void writeText(Text text) throws IOException { if (!text.hasBytes()) { final String string = text.string(); spare.copyChars(string); writeInt(spare.length()); write(spare.bytes(), 0, spare.length()); } else { BytesReference bytes = text.bytes(); writeInt(bytes.length()); bytes.writeTo(this); } }