当前位置: 首页>>代码示例>>Java>>正文


Java BytesReference.length方法代码示例

本文整理汇总了Java中org.elasticsearch.common.bytes.BytesReference.length方法的典型用法代码示例。如果您正苦于以下问题:Java BytesReference.length方法的具体用法?Java BytesReference.length怎么用?Java BytesReference.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.common.bytes.BytesReference的用法示例。


在下文中一共展示了BytesReference.length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toByteBuf

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
/**
 * Turns the given BytesReference into a ByteBuf. Note: the returned ByteBuf will reference the internal
 * pages of the BytesReference. Don't free the bytes of reference before the ByteBuf goes out of scope.
 */
public static ByteBuf toByteBuf(final BytesReference reference) {
    if (reference.length() == 0) {
        return Unpooled.EMPTY_BUFFER;
    }
    if (reference instanceof ByteBufBytesReference) {
        return ((ByteBufBytesReference) reference).toByteBuf();
    } else {
        final BytesRefIterator iterator = reference.iterator();
        // usually we have one, two, or three components from the header, the message, and a buffer
        final List<ByteBuf> buffers = new ArrayList<>(3);
        try {
            BytesRef slice;
            while ((slice = iterator.next()) != null) {
                buffers.add(Unpooled.wrappedBuffer(slice.bytes, slice.offset, slice.length));
            }
            final CompositeByteBuf composite = Unpooled.compositeBuffer(buffers.size());
            composite.addComponents(true, buffers);
            return composite;
        } catch (IOException ex) {
            throw new AssertionError("no IO happens here", ex);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:Netty4Utils.java

示例2: writeToLocal

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
public Location writeToLocal(BytesReference data) throws IOException {
    final long position;
    final long generation;
    try (ReleasableLock lock = writeLock.acquire()) {
        ensureOpen();
        if (writtenOffset > TRANSLOG_ROLLING_SIZE_BYTES) {
            IOUtils.close(writeChannel);
            tmpTranslogGeneration.incrementAndGet();
            writeChannel = FileChannel.open(this.translogPath.resolve(getFileNameFromId(tmpTranslogGeneration.get())), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
            writtenOffset = 0;
        }
        generation = tmpTranslogGeneration.get();
        position = writtenOffset;
        try {
            data.writeTo(writeChannel);
        } catch (Throwable e) {
            throw e;
        }
        writtenOffset = writtenOffset + data.length();
    }
    return new Translog.Location(generation, position, data.length());
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:LocalTranslog.java

示例3: parseSource

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
public void parseSource(BytesReference source) throws SQLParseException {
    XContentParser parser = null;
    try {
        if (source != null && source.length() != 0) {
            parser = XContentFactory.xContent(source).createParser(source);
            parse(parser);
        }
        validate();
    } catch (Exception e) {
        String sSource = "_na_";
        try {
            sSource = XContentHelper.convertToJson(source, false);
        } catch (Throwable e1) {
            // ignore
        }
        throw new SQLParseException("Failed to parse source [" + sSource + "]", e);
    } finally {
        if (parser != null) {
            parser.close();
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:SQLXContentSourceParser.java

示例4: add

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
/**
 * add the given bytes to the translog and return the location they were written at
 */
public Translog.Location add(BytesReference data) throws IOException {
    final long position;
    try (ReleasableLock lock = writeLock.acquire()) {
        ensureOpen();
        position = writtenOffset;
        try {
            data.writeTo(channel);
        } catch (Throwable e) {
            closeWithTragicEvent(e);
            throw e;
        }
        writtenOffset = writtenOffset + data.length();
        operationCounter++;;
    }
    return new Translog.Location(generation, position, data.length());
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:20,代码来源:TranslogWriter.java

示例5: WrapperQueryBuilder

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:WrapperQueryBuilder.java

示例6: contentParser

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
/**
 * A parser for the contents of this request if there is a body, otherwise throws an {@link ElasticsearchParseException}. Use
 * {@link #applyContentParser(CheckedConsumer)} if you want to gracefully handle when the request doesn't have any contents. Use
 * {@link #contentOrSourceParamParser()} for requests that support specifying the request body in the {@code source} param.
 */
public final XContentParser contentParser() throws IOException {
    BytesReference content = content();
    if (content.length() == 0) {
        throw new ElasticsearchParseException("Body required");
    } else if (xContentType.get() == null) {
        throw new IllegalStateException("unknown content type");
    }
    return xContentType.get().xContent().createParser(xContentRegistry, content);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:RestRequest.java

示例7: contentOrSourceParamParser

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
/**
 * A parser for the contents of this request if it has contents, otherwise a parser for the {@code source} parameter if there is one,
 * otherwise throws an {@link ElasticsearchParseException}. Use {@link #withContentOrSourceParamParserOrNull(CheckedConsumer)} instead
 * if you need to handle the absence request content gracefully.
 */
public final XContentParser contentOrSourceParamParser() throws IOException {
    Tuple<XContentType, BytesReference> tuple = contentOrSourceParam();
    BytesReference content = tuple.v2();
    if (content.length() == 0) {
        throw new ElasticsearchParseException("Body required");
    }
    return tuple.v1().xContent().createParser(xContentRegistry, content);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:RestRequest.java

示例8: withContentOrSourceParamParserOrNull

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
/**
 * Call a consumer with the parser for the contents of this request if it has contents, otherwise with a parser for the {@code source}
 * parameter if there is one, otherwise with {@code null}. Use {@link #contentOrSourceParamParser()} if you should throw an exception
 * back to the user when there isn't request content.
 */
public final void withContentOrSourceParamParserOrNull(CheckedConsumer<XContentParser, IOException> withParser) throws IOException {
    Tuple<XContentType, BytesReference> tuple = contentOrSourceParam();
    BytesReference content = tuple.v2();
    XContentType xContentType = tuple.v1();
    if (content.length() > 0) {
        try (XContentParser parser = xContentType.xContent().createParser(xContentRegistry, content)) {
            withParser.accept(parser);
        }
    } else {
        withParser.accept(null);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:RestRequest.java

示例9: isAncient

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
/** 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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:CompressorFactory.java

示例10: isCompressed

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
@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;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:DeflateCompressor.java

示例11: add

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
@Override
public Translog.Location add(BytesReference data) throws IOException {
    try (ReleasableLock lock = writeLock.acquire()) {
        ensureOpen();
        final long offset = totalOffset;
        if (data.length() >= buffer.length) {
            flush();
            // we use the channel to write, since on windows, writing to the RAF might not be reflected
            // when reading through the channel
            try {
                data.writeTo(channel);
            } catch (Throwable ex) {
                closeWithTragicEvent(ex);
                throw ex;
            }
            writtenOffset += data.length();
            totalOffset += data.length();
        } else {
            if (data.length() > buffer.length - bufferCount) {
                flush();
            }
            data.writeTo(bufferOs);
            totalOffset += data.length();
        }
        operationCounter++;
        return new Translog.Location(generation, offset, data.length());
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:29,代码来源:BufferingTranslogWriter.java

示例12: isCompressed

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
@Override
public boolean isCompressed(BytesReference bytes) {
    return bytes.length() >= 3 &&
            bytes.get(0) == LZFChunk.BYTE_Z &&
            bytes.get(1) == LZFChunk.BYTE_V &&
            (bytes.get(2) == LZFChunk.BLOCK_TYPE_COMPRESSED || bytes.get(2) == LZFChunk.BLOCK_TYPE_NON_COMPRESSED);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:8,代码来源:LZFCompressor.java

示例13: add

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
public void add(TermVectorsRequest template, BytesReference data) throws Exception {
    XContentParser.Token token;
    String currentFieldName = null;
    if (data.length() > 0) {
        try (XContentParser parser = XContentFactory.xContent(data).createParser(data)) {
            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                if (token == XContentParser.Token.FIELD_NAME) {
                    currentFieldName = parser.currentName();
                } else if (token == XContentParser.Token.START_ARRAY) {
                    if ("docs".equals(currentFieldName)) {
                        while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                            if (token != XContentParser.Token.START_OBJECT) {
                                throw new IllegalArgumentException("docs array element should include an object");
                            }
                            TermVectorsRequest termVectorsRequest = new TermVectorsRequest(template);
                            TermVectorsRequest.parseRequest(termVectorsRequest, parser);
                            add(termVectorsRequest);
                        }
                    } else if ("ids".equals(currentFieldName)) {
                        while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                            if (!token.isValue()) {
                                throw new IllegalArgumentException("ids array element should only contain ids");
                            }
                            ids.add(parser.text());
                        }
                    } else {
                        throw new ElasticsearchParseException("no parameter named [{}] and type ARRAY", currentFieldName);
                    }
                } else if (token == XContentParser.Token.START_OBJECT && currentFieldName != null) {
                    if ("parameters".equals(currentFieldName)) {
                        TermVectorsRequest.parseRequest(template, parser);
                    } else {
                        throw new ElasticsearchParseException("no parameter named [{}] and type OBJECT", currentFieldName);
                    }
                } else if (currentFieldName != null) {
                    throw new ElasticsearchParseException("_mtermvectors: Parameter [{}] not supported", currentFieldName);
                }
            }
        }
    }
    for (String id : ids) {
        TermVectorsRequest curRequest = new TermVectorsRequest(template);
        curRequest.id(id);
        requests.add(curRequest);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:47,代码来源:MultiTermVectorsRequest.java

示例14: xContentType

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
/**
 * Guesses the content type based on the provided bytes.
 *
 * @deprecated the content type should not be guessed except for few cases where we effectively don't know the content type.
 * The REST layer should move to reading the Content-Type header instead. There are other places where auto-detection may be needed.
 * This method is deprecated to prevent usages of it from spreading further without specific reasons.
 */
@Deprecated
public static XContentType xContentType(BytesReference bytes) {
    int length = bytes.length();
    if (length == 0) {
        return null;
    }
    byte first = bytes.get(0);
    if (first == '{') {
        return XContentType.JSON;
    }
    if (length > 2 && first == SmileConstants.HEADER_BYTE_1 && bytes.get(1) == SmileConstants.HEADER_BYTE_2 && bytes.get(2) == SmileConstants.HEADER_BYTE_3) {
        return XContentType.SMILE;
    }
    if (length > 2 && first == '-' && bytes.get(1) == '-' && bytes.get(2) == '-') {
        return XContentType.YAML;
    }
    // CBOR logic similar to CBORFactory#hasCBORFormat
    if (first == CBORConstants.BYTE_OBJECT_INDEFINITE && length > 1){
        return XContentType.CBOR;
    }
    if (CBORConstants.hasMajorType(CBORConstants.MAJOR_TYPE_TAG, first) && length > 2) {
        // Actually, specific "self-describe tag" is a very good indicator
        if (first == (byte) 0xD9 && bytes.get(1) == (byte) 0xD9 && bytes.get(2) == (byte) 0xF7) {
            return XContentType.CBOR;
        }
    }
    // for small objects, some encoders just encode as major type object, we can safely
    // say its CBOR since it doesn't contradict SMILE or JSON, and its a last resort
    if (CBORConstants.hasMajorType(CBORConstants.MAJOR_TYPE_OBJECT, first)) {
        return XContentType.CBOR;
    }

    int jsonStart = 0;
    // JSON may be preceded by UTF-8 BOM
    if (length > 3 && first == (byte) 0xEF && bytes.get(1) == (byte) 0xBB && bytes.get(2) == (byte) 0xBF) {
        jsonStart = 3;
    }

    // a last chance for JSON
    for (int i = jsonStart; i < length; i++) {
        byte b = bytes.get(i);
        if (b == '{') {
            return XContentType.JSON;
        }
        if (Character.isWhitespace(b) == false) {
            break;
        }
    }
    return null;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:58,代码来源:XContentFactory.java

示例15: parseSource

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
private void parseSource(SearchContext context, BytesReference source) throws SearchParseException {
    // nothing to parse...
    if (source == null || source.length() == 0) {
        return;
    }
    String abc = source.toUtf8();
    XContentParser parser = null;
    try {
        parser = XContentFactory.xContent(source).createParser(source);
        XContentParser.Token token;
        token = parser.nextToken();
        if (token != XContentParser.Token.START_OBJECT) {
            throw new ElasticsearchParseException("failed to parse search source. source must be an object, but found [{}] instead", token.name());
        }
        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (token == XContentParser.Token.FIELD_NAME) {
                String fieldName = parser.currentName();
                parser.nextToken();
                SearchParseElement element = elementParsers.get(fieldName);
                if (element == null) {
                    throw new SearchParseException(context, "failed to parse search source. unknown search element [" + fieldName + "]", parser.getTokenLocation());
                }
                element.parse(parser, context);
            } else {
                if (token == null) {
                    throw new ElasticsearchParseException("failed to parse search source. end of query source reached but query is not complete.");
                } else {
                    throw new ElasticsearchParseException("failed to parse search source. expected field name but got [{}]", token);
                }
            }
        }
    } catch (Throwable e) {
        String sSource = "_na_";
        try {
            sSource = XContentHelper.convertToJson(source, false);
        } catch (Throwable e1) {
            // ignore
        }
        XContentLocation location = parser != null ? parser.getTokenLocation() : null;
        throw new SearchParseException(context, "failed to parse search source [" + sSource + "]", location, e);
    } finally {
        if (parser != null) {
            parser.close();
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:47,代码来源:SearchService.java


注:本文中的org.elasticsearch.common.bytes.BytesReference.length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。