本文整理汇总了Java中org.elasticsearch.common.blobstore.BlobContainer.readBlob方法的典型用法代码示例。如果您正苦于以下问题:Java BlobContainer.readBlob方法的具体用法?Java BlobContainer.readBlob怎么用?Java BlobContainer.readBlob使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.blobstore.BlobContainer
的用法示例。
在下文中一共展示了BlobContainer.readBlob方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWriteRead
import org.elasticsearch.common.blobstore.BlobContainer; //导入方法依赖的package包/类
public void testWriteRead() throws IOException {
try(BlobStore store = newBlobStore()) {
final BlobContainer container = store.blobContainer(new BlobPath());
byte[] data = randomBytes(randomIntBetween(10, scaledRandomIntBetween(1024, 1 << 16)));
writeBlob(container, "foobar", new BytesArray(data));
try (InputStream stream = container.readBlob("foobar")) {
BytesRefBuilder target = new BytesRefBuilder();
while (target.length() < data.length) {
byte[] buffer = new byte[scaledRandomIntBetween(1, data.length - target.length())];
int offset = scaledRandomIntBetween(0, buffer.length - 1);
int read = stream.read(buffer, offset, buffer.length - offset);
target.append(new BytesRef(buffer, offset, read));
}
assertEquals(data.length, target.length());
assertArrayEquals(data, Arrays.copyOfRange(target.bytes(), 0, target.length()));
}
}
}
示例2: readBlob
import org.elasticsearch.common.blobstore.BlobContainer; //导入方法依赖的package包/类
/**
* Reads blob with specified name without resolving the blobName using using {@link #blobName} method.
*
* @param blobContainer blob container
* @param blobName blob name
*/
public T readBlob(BlobContainer blobContainer, String blobName) throws IOException {
try (InputStream inputStream = blobContainer.readBlob(blobName)) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Streams.copy(inputStream, out);
final byte[] bytes = out.toByteArray();
final String resourceDesc = "ChecksumBlobStoreFormat.readBlob(blob=\"" + blobName + "\")";
try (ByteArrayIndexInput indexInput = new ByteArrayIndexInput(resourceDesc, bytes)) {
CodecUtil.checksumEntireFile(indexInput);
CodecUtil.checkHeader(indexInput, codec, VERSION, VERSION);
long filePointer = indexInput.getFilePointer();
long contentSize = indexInput.length() - CodecUtil.footerLength() - filePointer;
BytesReference bytesReference = new BytesArray(bytes, (int) filePointer, (int) contentSize);
return read(bytesReference);
} catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
// we trick this into a dedicated exception with the original stacktrace
throw new CorruptStateException(ex);
}
}
}
示例3: randomCorruption
import org.elasticsearch.common.blobstore.BlobContainer; //导入方法依赖的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());
}
}
示例4: readBlob
import org.elasticsearch.common.blobstore.BlobContainer; //导入方法依赖的package包/类
/**
* Reads blob with specified name without resolving the blobName using using {@link #blobName} method.
*
* @param blobContainer blob container
* @param blobName blob name
*/
public T readBlob(BlobContainer blobContainer, String blobName) throws IOException {
try (InputStream inputStream = blobContainer.readBlob(blobName)) {
byte[] bytes = ByteStreams.toByteArray(inputStream);
final String resourceDesc = "ChecksumBlobStoreFormat.readBlob(blob=\"" + blobName + "\")";
try (ByteArrayIndexInput indexInput = new ByteArrayIndexInput(resourceDesc, bytes)) {
CodecUtil.checksumEntireFile(indexInput);
CodecUtil.checkHeader(indexInput, codec, VERSION, VERSION);
long filePointer = indexInput.getFilePointer();
long contentSize = indexInput.length() - CodecUtil.footerLength() - filePointer;
BytesReference bytesReference = new BytesArray(bytes, (int) filePointer, (int) contentSize);
return read(bytesReference);
} catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
// we trick this into a dedicated exception with the original stacktrace
throw new CorruptStateException(ex);
}
}
}
示例5: testURLBlobStoreCanReadBlob
import org.elasticsearch.common.blobstore.BlobContainer; //导入方法依赖的package包/类
public void testURLBlobStoreCanReadBlob() throws IOException {
BlobContainer container = urlBlobStore.blobContainer(BlobPath.cleanPath().add("indices"));
try (InputStream stream = container.readBlob(blobName)) {
byte[] bytes = new byte[message.length];
int read = stream.read(bytes);
assertEquals(message.length, read);
assertArrayEquals(message, bytes);
}
}
示例6: testNoBlobFound
import org.elasticsearch.common.blobstore.BlobContainer; //导入方法依赖的package包/类
public void testNoBlobFound() throws IOException {
BlobContainer container = urlBlobStore.blobContainer(BlobPath.cleanPath().add("indices"));
String incorrectBlobName = "incorrect_" + blobName;
try (InputStream ignored = container.readBlob(incorrectBlobName)) {
fail("Should have thrown NoSuchFileException exception");
ignored.read();
} catch (NoSuchFileException e) {
assertEquals(String.format("[%s] blob not found", incorrectBlobName), e.getMessage());
}
}
示例7: readBlobFully
import org.elasticsearch.common.blobstore.BlobContainer; //导入方法依赖的package包/类
public static byte[] readBlobFully(BlobContainer container, String name, int length) throws IOException {
byte[] data = new byte[length];
try (InputStream inputStream = container.readBlob(name)) {
assertThat(inputStream.read(data), equalTo(length));
assertThat(inputStream.read(), equalTo(-1));
}
return data;
}
示例8: readBlob
import org.elasticsearch.common.blobstore.BlobContainer; //导入方法依赖的package包/类
/**
* Reads and parses the blob with given name.
*
* If required the checksum of the blob will be verified.
*
* @param blobContainer blob container
* @param blobName blob name
* @return parsed blob object
*/
public T readBlob(BlobContainer blobContainer, String blobName) throws IOException {
try (InputStream inputStream = blobContainer.readBlob(blobName)) {
return read(new BytesArray(ByteStreams.toByteArray(inputStream)));
}
}