本文整理匯總了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());
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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();
}
}
示例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;
}