本文整理汇总了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;
}