Package com.google.common.io

Examples of com.google.common.io.ByteSource


      }
      return this;
    }

    boolean wasGenerated(Compilation.Result result, JavaFileObject expected) {
      ByteSource expectedByteSource = JavaFileObjects.asByteSource(expected);
      for (JavaFileObject generated : result.generatedFilesByKind().get(expected.getKind())) {
        try {
          ByteSource generatedByteSource = JavaFileObjects.asByteSource(generated);
          if (expectedByteSource.contentEquals(generatedByteSource)) {
            return true;
          }
        } catch (IOException e) {
          throw new RuntimeException(e);
View Full Code Here


    }
    return Kind.OTHER;
  }

  static ByteSource asByteSource(final JavaFileObject javaFileObject) {
    return new ByteSource() {
      @Override public InputStream openStream() throws IOException {
        return javaFileObject.openInputStream();
      }
    };
  }
View Full Code Here

      assertEquals(request.getFilters().size(), 0);
   }

   public void testSignPutBlobWithGenerate() throws ArrayIndexOutOfBoundsException, SecurityException,
            IllegalArgumentException, NoSuchMethodException, IOException {
      ByteSource byteSource = ByteSource.wrap("foo".getBytes(Charsets.UTF_8));
      Blob blob = blobFactory.get().name(blobName)
         .payload(byteSource)
         .contentLength(byteSource.size())
         .contentMD5(byteSource.hash(Hashing.md5()).asBytes())
         .contentType("text/plain").build();
      byte[] md5 = { -84, -67, 24, -37, 76, -62, -8, 92, -19, -17, 101, 79, -52, -60, -92, -40 };
     
      assertEquals(blob.getPayload().getContentMetadata().getContentMD5(), md5);
View Full Code Here

    @Override
    public HttpContext service(final HttpRequest request, final HttpResponse response)
        throws IOException, HttpException {
      request.setState(HttpMessage.__MSG_EDITABLE);
      this.authorizationHttpHeaders.add(request.getHeader().get("Authorization"));
      this.requestBodies.add(new ByteSource() {
        public InputStream openStream() throws IOException {
          return request.getInputStream();
        }
      }.asCharSource(Charsets.UTF_8).read());
View Full Code Here

    private static class PayloadFn implements Function<JresBulkable, InputSupplier<InputStream>> {
        @Override
        public InputSupplier<InputStream> apply(JresBulkable action) {
            try {

                ByteSource lines = ByteSource.concat(
                        ByteSource.wrap(ObjectMappers.NORMAL.writeValueAsBytes(action.getAction())),
                        NEW_LINE
                );

                Object payload = action.getPayload();
View Full Code Here

    private static class PayloadFn implements Function<JresBulkable, InputSupplier<InputStream>> {
        @Override
        public InputSupplier<InputStream> apply(JresBulkable action) {
            try {

                ByteSource lines = ByteSource.concat(
                        ByteSource.wrap(ObjectMappers.NORMAL.writeValueAsBytes(action.getAction())),
                        NEW_LINE
                );

                Object payload = action.getPayload();
View Full Code Here

      // write files
      storageStrategy.putBlob(CONTAINER_NAME, blob);

      // verify that the files is equal
      File blobFullPath = new File(TARGET_CONTAINER_NAME, blobKey);
      ByteSource expectedInput = Files.asByteSource(sourceFile);
      ByteSource actualInput = Files.asByteSource(blobFullPath);
      assertTrue(expectedInput.contentEquals(actualInput),
            "Files are not equal");
   }
View Full Code Here

      // write files
      storageStrategy.putBlob(CONTAINER_NAME, blob);

      // verify that the files is equal
      File blobFullPath = new File(TARGET_CONTAINER_NAME, blobKey);
      ByteSource expectedInput = Files.asByteSource(sourceFile);
      ByteSource actualInput = Files.asByteSource(blobFullPath);
      assertTrue(expectedInput.contentEquals(actualInput),
            "Files are not equal");
   }
View Full Code Here

        resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options);

        assertNotNull(resultBlob, "Blob exists");
        // checks file content
        ByteSource expectedFile = Files.asByteSource(new File(TARGET_CONTAINER_NAME, blobKey));
        assertEquals(expectedFile.read(), ByteStreams2.toByteArrayAndClose(resultBlob.getPayload().openStream()),
                "Blob payload differs from file content");
        // metadata are verified in the test for blobMetadata, so no need to
        // perform a complete test here
        assertNotNull(resultBlob.getMetadata(), "Metadata null");
        MutableBlobMetadata metadata = resultBlob.getMetadata();
View Full Code Here

   public Blob getBlob(final String container, final String key) {
      BlobBuilder builder = blobBuilders.get();
      builder.name(key);
      File file = getFileForBlobKey(container, key);
      Path path = file.toPath();
      ByteSource byteSource = Files.asByteSource(file);
      try {
         String contentDisposition = null;
         String contentEncoding = null;
         String contentLanguage = null;
         String contentType = null;
         HashCode hashCode = null;
         Date expires = null;
         ImmutableMap.Builder<String, String> userMetadata = ImmutableMap.builder();

         if (getFileStore(file.toPath()).supportsFileAttributeView(UserDefinedFileAttributeView.class)) {
            UserDefinedFileAttributeView view = getFileAttributeView(path, UserDefinedFileAttributeView.class);
            Set<String> attributes = ImmutableSet.copyOf(view.list());

            contentDisposition = readStringAttributeIfPresent(view, attributes, XATTR_CONTENT_DISPOSITION);
            contentEncoding = readStringAttributeIfPresent(view, attributes, XATTR_CONTENT_ENCODING);
            contentLanguage = readStringAttributeIfPresent(view, attributes, XATTR_CONTENT_LANGUAGE);
            contentType = readStringAttributeIfPresent(view, attributes, XATTR_CONTENT_TYPE);
            if (attributes.contains(XATTR_CONTENT_MD5)) {
               ByteBuffer buf = ByteBuffer.allocate(view.size(XATTR_CONTENT_MD5));
               view.read(XATTR_CONTENT_MD5, buf);
               hashCode = HashCode.fromBytes(buf.array());
            }
            if (attributes.contains(XATTR_EXPIRES)) {
               ByteBuffer buf = ByteBuffer.allocate(view.size(XATTR_EXPIRES));
               view.read(XATTR_EXPIRES, buf);
               buf.flip();
               expires = new Date(buf.asLongBuffer().get());
            }
            for (String attribute : attributes) {
               if (!attribute.startsWith(XATTR_USER_METADATA_PREFIX)) {
                  continue;
               }
               String value = readStringAttributeIfPresent(view, attributes, attribute);
               userMetadata.put(attribute.substring(XATTR_USER_METADATA_PREFIX.length()), value);
            }

            builder.payload(byteSource)
               .contentDisposition(contentDisposition)
               .contentEncoding(contentEncoding)
               .contentLanguage(contentLanguage)
               .contentLength(byteSource.size())
               .contentMD5(hashCode)
               .contentType(contentType)
               .expires(expires)
               .userMetadata(userMetadata.build());
         } else {
            builder.payload(byteSource)
               .contentLength(byteSource.size())
               .contentMD5(byteSource.hash(Hashing.md5()).asBytes());
         }
      } catch (IOException e) {
         throw Throwables.propagate(e);
      }
      Blob blob = builder.build();
View Full Code Here

TOP

Related Classes of com.google.common.io.ByteSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.