Package com.google.common.io

Examples of com.google.common.io.ByteSource


        + artifact.getArtifactId() + "/" + file);
  }

  @Override
  public ByteSource getResource(final String name) throws IOException {
    return new ByteSource() {
      @Override
      public InputStream openStream() throws IOException {
        return jarFile.getInputStream(entry(name));
      }
    };
View Full Code Here


    assertThat(pairList.getValue(), equalTo( c(1,2,3,4) ));
  }
 
  @Test
  public void isRDataFile() throws IOException {
    ByteSource rdata = new ByteSource() {
     
      @Override
      public InputStream openStream() throws IOException {
        InputStream in = getClass().getResourceAsStream("/simple.RData");
        return new GZIPInputStream(in);
      }
    };
    ByteSource notRData = new ByteSource() {
     
      @Override
      public InputStream openStream() throws IOException {
        return getClass().getResourceAsStream("/jarfiletest.jar");
      }
View Full Code Here

   * Sets up imports and exports defined in the NAMESPACE file.
   *
   */
  private void setupImportsExports(Package pkg, Namespace namespace) throws IOException {

    ByteSource namespaceFile = pkg.getResource("NAMESPACE");
    NamespaceDirectiveParser.parse(namespaceFile.asCharSource(Charsets.UTF_8),
        new NamespaceInitHandler(context, this, namespace));
  }
View Full Code Here

            builder = builder.payload(ByteStreams.toByteArray(input));
         } finally {
            input.close();
         }
      } else {
         ByteSource byteSource = Files.asByteSource(new File(payload));
         BlobBuilder.PayloadBlobBuilder payloadBuilder = builder
               .payload(byteSource)
               .contentLength(byteSource.size());
         if (!multipartUpload) {
            payloadBuilder = payloadBuilder.contentMD5(byteSource.hash(Hashing.md5()).asBytes());
         }
         builder = payloadBuilder;
      }

      PutOptions options = multipartUpload ? new PutOptions().multipart(true) : PutOptions.NONE;
View Full Code Here

         closeQuietly(input);
      }
   }

   private void assertValidMd5(final InputStream input) throws IOException {
      assertEquals(base64().encode(new ByteSource() {
         @Override
         public InputStream openStream() {
            return input;
         }
      }.hash(md5()).asBytes()), md5);
View Full Code Here

      @Override
      public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
         try {
            MockResponse response = new MockResponse();
            String expectedMd5 = request.getHeader("Content-MD5");
            ByteSource body = ByteSource.wrap(request.getBody());
            String realMd5FromRequest = base64().encode(body.hash(md5()).asBytes());
            boolean matched = expectedMd5.equals(realMd5FromRequest);
            if (matched) {
               response.addHeader("x-Content-MD5", realMd5FromRequest);
            } else {
               response.setResponseCode(500);
View Full Code Here

      MockWebServer server = mockWebServer(new MockResponse().addHeader("x-Content-Disposition",
            "attachment; filename=photo.jpg"));
      IntegrationTestClient client = client(server.getUrl("/").toString());
      Payload payload = null;
      try {
         ByteSource body = ByteSource.wrap("foo".getBytes());
         payload = newByteSourcePayload(body);
         payload.getContentMetadata().setContentDisposition("attachment; filename=photo.jpg");
         payload.getContentMetadata().setContentLength(body.size());
         Multimap<String, String> headers = client.postPayloadAndReturnHeaders("", payload);
         RecordedRequest request = server.takeRequest();
         assertEquals(request.getHeader("Content-Disposition"), "attachment; filename=photo.jpg");
         assertEquals(headers.get("x-Content-Disposition"), ImmutableList.of("attachment; filename=photo.jpg"));
      } finally {
View Full Code Here

   public void testPostContentEncoding() throws Exception {
      MockWebServer server = mockWebServer(new MockResponse().addHeader("x-Content-Encoding", "gzip"));
      IntegrationTestClient client = client(server.getUrl("/").toString());
      Payload payload = null;
      try {
         ByteSource body = ByteSource.wrap("foo".getBytes());
         payload = newByteSourcePayload(body);
         payload.getContentMetadata().setContentEncoding("gzip");
         payload.getContentMetadata().setContentLength(body.size());
         Multimap<String, String> headers = client.postPayloadAndReturnHeaders("", payload);
         RecordedRequest request = server.takeRequest();
         assertEquals(request.getHeader("Content-Encoding"), "gzip");
         assertEquals(headers.get("x-Content-Encoding"), ImmutableList.of("gzip"));
      } finally {
View Full Code Here

   public void testPostContentLanguage() throws Exception {
      MockWebServer server = mockWebServer(new MockResponse().addHeader("x-Content-Language", "mi, en"));
      IntegrationTestClient client = client(server.getUrl("/").toString());
      Payload payload = null;
      try {
         ByteSource body = ByteSource.wrap("foo".getBytes());
         payload = newByteSourcePayload(body);
         payload.getContentMetadata().setContentLanguage("mi, en");
         payload.getContentMetadata().setContentLength(body.size());
         Multimap<String, String> headers = client.postPayloadAndReturnHeaders("", payload);
         RecordedRequest request = server.takeRequest();
         assertEquals(request.getHeader("Content-Language"), "mi, en");
         assertEquals(headers.get("x-Content-Language"), ImmutableList.of("mi, en"));
      } finally {
View Full Code Here

            tempFile.renameTo(file);
        }
    }

    private boolean isSame(File a, BlobData b) throws IOException {
        ByteSource supplierA = Files.asByteSource(a);
        // ByteSource supplierB = ByteStreams.asByteSource(b);

        return supplierA.contentEquals(b);
    }
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.