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


Java Streams.readFully方法代码示例

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


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

示例1: randomCorruption

import org.elasticsearch.common.io.Streams; //导入方法依赖的package包/类
protected void randomCorruption(BlobContainer blobContainer, String blobName) throws IOException {
    byte[] buffer = new byte[(int) blobContainer.listBlobsByPrefix(blobName).get(blobName).length()];
    long originalChecksum = checksum(buffer);
    try (InputStream inputStream = blobContainer.readBlob(blobName)) {
        Streams.readFully(inputStream, buffer);
    }
    do {
        int location = randomIntBetween(0, buffer.length - 1);
        buffer[location] = (byte) (buffer[location] ^ 42);
    } while (originalChecksum == checksum(buffer));
    blobContainer.deleteBlob(blobName); // delete original before writing new blob
    BytesArray bytesArray = new BytesArray(buffer);
    try (StreamInput stream = bytesArray.streamInput()) {
        blobContainer.writeBlob(blobName, stream, bytesArray.length());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:BlobStoreFormatIT.java

示例2: xContentType

import org.elasticsearch.common.io.Streams; //导入方法依赖的package包/类
/**
 * Guesses the content type based on the provided input stream without consuming it.
 *
 * @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(InputStream si) throws IOException {
    if (si.markSupported() == false) {
        throw new IllegalArgumentException("Cannot guess the xcontent type without mark/reset support on " + si.getClass());
    }
    si.mark(GUESS_HEADER_LENGTH);
    try {
        final byte[] firstBytes = new byte[GUESS_HEADER_LENGTH];
        final int read = Streams.readFully(si, firstBytes);
        return xContentType(new BytesArray(firstBytes, 0, read));
    } finally {
        si.reset();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:XContentFactory.java

示例3: readBytes

import org.elasticsearch.common.io.Streams; //导入方法依赖的package包/类
@Override
public void readBytes(byte[] b, int offset, int len) throws IOException {
    if (len < 0)
        throw new IndexOutOfBoundsException();
    final int read = Streams.readFully(is, b, offset, len);
    if (read != len) {
        throw new EOFException();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:InputStreamStreamInput.java

示例4: incrementToken

import org.elasticsearch.common.io.Streams; //导入方法依赖的package包/类
@Override
public final boolean incrementToken() throws IOException {
    if (!started) {
        // reset() must be idempotent, this is why we read data in incrementToken
        final int len = Streams.readFully(input, buffer);
        if (len == buffer.length && input.read() != -1) {
            throw new IOException("Cannot read numeric data larger than " + buffer.length + " chars");
        }
        setValue(numericTokenStream, new String(buffer, 0, len));
        numericTokenStream.reset();
        started = true;
    }
    return numericTokenStream.incrementToken();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:15,代码来源:NumericTokenizer.java

示例5: xContentType

import org.elasticsearch.common.io.Streams; //导入方法依赖的package包/类
/**
 * Guesses the content type based on the provided input stream without consuming it.
 */
public static XContentType xContentType(InputStream si) throws IOException {
    if (si.markSupported() == false) {
        throw new IllegalArgumentException("Cannot guess the xcontent type without mark/reset support on " + si.getClass());
    }
    si.mark(GUESS_HEADER_LENGTH);
    try {
        final byte[] firstBytes = new byte[GUESS_HEADER_LENGTH];
        final int read = Streams.readFully(si, firstBytes);
        return xContentType(new BytesArray(firstBytes, 0, read));
    } finally {
        si.reset();
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:XContentFactory.java

示例6: load

import org.elasticsearch.common.io.Streams; //导入方法依赖的package包/类
public FSA load(DataInputStream inputStream) throws IOException {
    this.size = inputStream.readInt();
    this.epsilon = inputStream.readInt();
    this.serialized = new byte[this.size];
    try {
        Streams.readFully(inputStream, serialized);
    } finally {
        inputStream.close();
    }
    final FSA fsa = new ConstantArcSizeFSA(Arrays.copyOf(this.serialized, this.size), this.epsilon);
    this.serialized = null;
    return fsa;
}
 
开发者ID:jprante,项目名称:elasticsearch-plugin-bundle,代码行数:14,代码来源:FSABuilder.java


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