Search in sources :

Example 16 with ByteString

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString in project bazel by bazelbuild.

the class GrpcActionCache method createFileFromStream.

private ContentDigest createFileFromStream(Map<ContentDigest, Pair<Path, FileMetadata>> metadataMap, Iterator<CasDownloadReply> replies) throws IOException, CacheNotFoundException {
    Preconditions.checkArgument(replies.hasNext());
    CasDownloadReply reply = replies.next();
    if (reply.hasStatus()) {
        handleDownloadStatus(reply.getStatus());
    }
    BlobChunk chunk = reply.getData();
    ContentDigest digest = chunk.getDigest();
    Preconditions.checkArgument(metadataMap.containsKey(digest));
    Pair<Path, FileMetadata> metadata = metadataMap.get(digest);
    Path path = metadata.first;
    FileSystemUtils.createDirectoryAndParents(path.getParentDirectory());
    try (OutputStream stream = path.getOutputStream()) {
        ByteString data = chunk.getData();
        data.writeTo(stream);
        long bytesLeft = digest.getSizeBytes() - data.size();
        while (bytesLeft > 0) {
            Preconditions.checkArgument(replies.hasNext());
            reply = replies.next();
            if (reply.hasStatus()) {
                handleDownloadStatus(reply.getStatus());
            }
            chunk = reply.getData();
            data = chunk.getData();
            Preconditions.checkArgument(!chunk.hasDigest());
            Preconditions.checkArgument(chunk.getOffset() == digest.getSizeBytes() - bytesLeft);
            data.writeTo(stream);
            bytesLeft -= data.size();
        }
        path.setExecutable(metadata.second.getExecutable());
    }
    return digest;
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) BlobChunk(com.google.devtools.build.lib.remote.RemoteProtocol.BlobChunk) CasDownloadReply(com.google.devtools.build.lib.remote.RemoteProtocol.CasDownloadReply) ByteString(com.google.protobuf.ByteString) OutputStream(java.io.OutputStream) FileMetadata(com.google.devtools.build.lib.remote.RemoteProtocol.FileMetadata) ContentDigest(com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest)

Example 17 with ByteString

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString in project bazel by bazelbuild.

the class Digest method fromVirtualActionInput.

/**
   * Gets the digest and size of a given VirtualActionInput.
   *
   * @param input the VirtualActionInput.
   * @return the digest and size.
   */
public static Pair<ByteString, Long> fromVirtualActionInput(VirtualActionInput input) throws IOException {
    CountingMD5OutputStream md5Stream = new CountingMD5OutputStream();
    input.writeTo(md5Stream);
    ByteString digest = toByteString(md5Stream.getDigest());
    return Pair.of(digest, md5Stream.getSize());
}
Also used : ByteString(com.google.protobuf.ByteString)

Example 18 with ByteString

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString in project grpc-java by grpc.

the class TestServiceImpl method createBufferFromFile.

/**
   * Creates a buffer with data read from a file.
   */
// Not concerned about suppression; expected to be exceedingly rare
@SuppressWarnings("Finally")
private ByteString createBufferFromFile(String fileClassPath) {
    ByteString buffer = ByteString.EMPTY;
    InputStream inputStream = getClass().getResourceAsStream(fileClassPath);
    if (inputStream == null) {
        throw new IllegalArgumentException("Unable to locate file on classpath: " + fileClassPath);
    }
    try {
        buffer = ByteString.readFrom(inputStream);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            inputStream.close();
        } catch (IOException ignorable) {
        // ignore
        }
    }
    return buffer;
}
Also used : ByteString(com.google.protobuf.ByteString) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 19 with ByteString

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString in project bazel by bazelbuild.

the class DigestTest method testFromVirtualInput.

@Test
public void testFromVirtualInput() throws Exception {
    Pair<ByteString, Long> result = Digest.fromVirtualActionInput(new VirtualActionInput() {

        @Override
        public void writeTo(OutputStream out) throws IOException {
            out.write(UGLY.getBytes(UTF_8));
        }

        @Override
        public String getExecPathString() {
            throw new UnsupportedOperationException();
        }

        @Override
        public PathFragment getExecPath() {
            throw new UnsupportedOperationException();
        }
    });
    assertEquals(UGLY_DIGEST, result.first.toStringUtf8());
    assertEquals(UGLY.length(), result.second.longValue());
}
Also used : VirtualActionInput(com.google.devtools.build.lib.actions.cache.VirtualActionInput) ByteString(com.google.protobuf.ByteString) OutputStream(java.io.OutputStream) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 20 with ByteString

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString in project bazel by bazelbuild.

the class SingleBuildFileCacheTest method testUnreadableFileWhenFileSystemSupportsDigest.

@Test
public void testUnreadableFileWhenFileSystemSupportsDigest() throws Exception {
    byte[] expectedDigestRaw = MessageDigest.getInstance("md5").digest("randomtext".getBytes(StandardCharsets.UTF_8));
    ByteString expectedDigest = ByteString.copyFrom(expectedDigestRaw);
    md5Overrides.put("/unreadable", expectedDigestRaw);
    ActionInput input = ActionInputHelper.fromPath("/unreadable");
    Path file = fs.getPath("/unreadable");
    file.getOutputStream().close();
    file.chmod(0);
    ByteString actualDigest = ByteString.copyFrom(underTest.getDigest(input));
    assertThat(expectedDigest).isEqualTo(actualDigest);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ActionInput(com.google.devtools.build.lib.actions.ActionInput) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

ByteString (com.google.protobuf.ByteString)406 Test (org.junit.Test)143 ArrayList (java.util.ArrayList)65 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)63 HashMap (java.util.HashMap)41 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)40 IOException (java.io.IOException)37 List (java.util.List)33 Map (java.util.Map)33 ServerRequest (com.pokegoapi.main.ServerRequest)17 ExecutionException (java.util.concurrent.ExecutionException)16 AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)14 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)14 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)14 Feature (com.google.cloud.vision.v1.Feature)14 Image (com.google.cloud.vision.v1.Image)14 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)14 FileInputStream (java.io.FileInputStream)13 ByteBuffer (java.nio.ByteBuffer)13 WebImage (com.google.cloud.vision.v1.WebDetection.WebImage)12