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


Java BlobContainer.writeBlob方法代码示例

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


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

示例1: writeBlob

import org.elasticsearch.common.blobstore.BlobContainer; //导入方法依赖的package包/类
/**
 * Writes blob in atomic manner without resolving the blobName using using {@link #blobName} method.
 * <p>
 * The blob will be compressed and checksum will be written if required.
 *
 * @param obj           object to be serialized
 * @param blobContainer blob container
 * @param blobName          blob name
 */
protected void writeBlob(T obj, BlobContainer blobContainer, String blobName) throws IOException {
    BytesReference bytes = write(obj);
    try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
        final String resourceDesc = "ChecksumBlobStoreFormat.writeBlob(blob=\"" + blobName + "\")";
        try (OutputStreamIndexOutput indexOutput = new OutputStreamIndexOutput(resourceDesc, blobName, byteArrayOutputStream, BUFFER_SIZE)) {
            CodecUtil.writeHeader(indexOutput, codec, VERSION);
            try (OutputStream indexOutputOutputStream = new IndexOutputOutputStream(indexOutput) {
                @Override
                public void close() throws IOException {
                    // this is important since some of the XContentBuilders write bytes on close.
                    // in order to write the footer we need to prevent closing the actual index input.
                } }) {
                bytes.writeTo(indexOutputOutputStream);
            }
            CodecUtil.writeFooter(indexOutput);
        }
        BytesArray bytesArray = new BytesArray(byteArrayOutputStream.toByteArray());
        try (InputStream stream = bytesArray.streamInput()) {
            blobContainer.writeBlob(blobName, stream, bytesArray.length());
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:ChecksumBlobStoreFormat.java

示例2: startVerification

import org.elasticsearch.common.blobstore.BlobContainer; //导入方法依赖的package包/类
@Override
public String startVerification() {
    try {
        if (isReadOnly()) {
            // It's readonly - so there is not much we can do here to verify it
            return null;
        } else {
            String seed = UUIDs.randomBase64UUID();
            byte[] testBytes = Strings.toUTF8Bytes(seed);
            BlobContainer testContainer = blobStore().blobContainer(basePath().add(testBlobPrefix(seed)));
            String blobName = "master.dat";
            BytesArray bytes = new BytesArray(testBytes);
            try (InputStream stream = bytes.streamInput()) {
                testContainer.writeBlob(blobName + "-temp", stream, bytes.length());
            }
            // Make sure that move is supported
            testContainer.move(blobName + "-temp", blobName);
            return seed;
        }
    } catch (IOException exp) {
        throw new RepositoryVerificationException(metadata.name(), "path " + basePath() + " is not accessible on master node", exp);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:BlobStoreRepository.java

示例3: verify

import org.elasticsearch.common.blobstore.BlobContainer; //导入方法依赖的package包/类
@Override
public void verify(String seed, DiscoveryNode localNode) {
    BlobContainer testBlobContainer = blobStore().blobContainer(basePath().add(testBlobPrefix(seed)));
    if (testBlobContainer.blobExists("master.dat")) {
        try  {
            BytesArray bytes = new BytesArray(seed);
            try (InputStream stream = bytes.streamInput()) {
                testBlobContainer.writeBlob("data-" + localNode.getId() + ".dat", stream, bytes.length());
            }
        } catch (IOException exp) {
            throw new RepositoryVerificationException(metadata.name(), "store location [" + blobStore() + "] is not accessible on the node [" + localNode + "]", exp);
        }
    } else {
        throw new RepositoryVerificationException(metadata.name(), "a file written by master to the store [" + blobStore() + "] cannot be accessed on the node [" + localNode + "]. "
            + "This might indicate that the store [" + blobStore() + "] is not shared between this node and the master node or "
            + "that permissions on the store don't allow reading files written by the master node");
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:BlobStoreRepository.java

示例4: 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());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:BlobStoreFormatIT.java

示例5: writeBlob

import org.elasticsearch.common.blobstore.BlobContainer; //导入方法依赖的package包/类
/**
 * Writes blob in atomic manner without resolving the blobName using using {@link #blobName} method.
 * <p>
 * The blob will be compressed and checksum will be written if required.
 *
 * @param obj           object to be serialized
 * @param blobContainer blob container
 * @param blobName          blob name
 */
protected void writeBlob(T obj, BlobContainer blobContainer, String blobName) throws IOException {
    BytesReference bytes = write(obj);
    try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
        final String resourceDesc = "ChecksumBlobStoreFormat.writeBlob(blob=\"" + blobName + "\")";
        try (OutputStreamIndexOutput indexOutput = new OutputStreamIndexOutput(resourceDesc, byteArrayOutputStream, BUFFER_SIZE)) {
            CodecUtil.writeHeader(indexOutput, codec, VERSION);
            try (OutputStream indexOutputOutputStream = new IndexOutputOutputStream(indexOutput) {
                @Override
                public void close() throws IOException {
                    // this is important since some of the XContentBuilders write bytes on close.
                    // in order to write the footer we need to prevent closing the actual index input.
                } }) {
                bytes.writeTo(indexOutputOutputStream);
            }
            CodecUtil.writeFooter(indexOutput);
        }
        blobContainer.writeBlob(blobName, new BytesArray(byteArrayOutputStream.toByteArray()));
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:29,代码来源:ChecksumBlobStoreFormat.java

示例6: startVerification

import org.elasticsearch.common.blobstore.BlobContainer; //导入方法依赖的package包/类
@Override
public String startVerification() {
    try {
        if (readOnly()) {
            // It's readonly - so there is not much we can do here to verify it
            return null;
        } else {
            String seed = Strings.randomBase64UUID();
            byte[] testBytes = Strings.toUTF8Bytes(seed);
            BlobContainer testContainer = blobStore().blobContainer(basePath().add(testBlobPrefix(seed)));
            String blobName = "master.dat";
            testContainer.writeBlob(blobName + "-temp", new BytesArray(testBytes));
            // Make sure that move is supported
            testContainer.move(blobName + "-temp", blobName);
            return seed;
        }
    } catch (IOException exp) {
        throw new RepositoryVerificationException(repositoryName, "path " + basePath() + " is not accessible on master node", exp);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:21,代码来源:BlobStoreRepository.java

示例7: verify

import org.elasticsearch.common.blobstore.BlobContainer; //导入方法依赖的package包/类
@Override
public void verify(String seed) {
    BlobContainer testBlobContainer = blobStore.blobContainer(basePath.add(testBlobPrefix(seed)));
    DiscoveryNode localNode = clusterService.localNode();
    if (testBlobContainer.blobExists("master.dat")) {
        try  {
            testBlobContainer.writeBlob("data-" + localNode.getId() + ".dat", new BytesArray(seed));
        } catch (IOException exp) {
            throw new RepositoryVerificationException(repositoryName, "store location [" + blobStore + "] is not accessible on the node [" + localNode + "]", exp);
        }
    } else {
        throw new RepositoryVerificationException(repositoryName, "a file written by master to the store [" + blobStore + "] cannot be accessed on the node [" + localNode + "]. "
                + "This might indicate that the store [" + blobStore + "] is not shared between this node and the master node or "
                + "that permissions on the store don't allow reading files written by the master node");
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:BlobStoreIndexShardRepository.java

示例8: writeBlob

import org.elasticsearch.common.blobstore.BlobContainer; //导入方法依赖的package包/类
private static void writeBlob(BlobContainer container, String blobName, BytesArray bytesArray) throws IOException {
    try (InputStream stream = bytesArray.streamInput()) {
        container.writeBlob(blobName, stream, bytesArray.length());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:ESBlobStoreTestCase.java

示例9: writeBlob

import org.elasticsearch.common.blobstore.BlobContainer; //导入方法依赖的package包/类
private void writeBlob(final BlobContainer container, final String blobName, final BytesArray bytesArray) throws IOException {
    try (InputStream stream = bytesArray.streamInput()) {
        container.writeBlob(blobName, stream, bytesArray.length());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:ESBlobStoreContainerTestCase.java


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