當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。