Package com.google.common.io

Examples of com.google.common.io.ByteSource


                                            @Nonnull final ClientHttpRequestFactory clientHttpRequestFactory,
                                            @Nonnull final String styleString,
                                            @Nonnull final MapfishMapContext mapContext) throws Throwable {

        // try to load xml
        final ByteSource straightByteSource = ByteSource.wrap(styleString.getBytes(Constants.DEFAULT_CHARSET));
        final Optional<Style> styleOptional = tryLoadSLD(straightByteSource, null);

        if (styleOptional.isPresent()) {
            return styleOptional;
        }

        final Integer styleIndex = lookupStyleIndex(styleString).orNull();
        final String styleStringWithoutIndexReference = removeIndexReference(styleString);
        Function<byte[], Optional<Style>> loadFunction = new Function<byte[], Optional<Style>>() {
            @Override
            public Optional<Style> apply(final byte[] input) {
                final ByteSource bytes = ByteSource.wrap(input);
                try {
                    return tryLoadSLD(bytes, styleIndex);
                } catch (IOException e) {
                    throw ExceptionUtils.getRuntimeException(e);
                }
View Full Code Here


    return this;
  }

  public FakeGFileBuilder contents(File file) {
    try {
      ByteSource byteSource = Files.asByteSource(file);
      this.contents = byteSource.openStream();
    } catch (IOException e) {
      Throwables.propagate(e);
    }

    return this;
View Full Code Here

    public void mapping(final String context, final File file) {
        httpServer.createContext(context, new HttpHandler() {
            @Override
            public void handle(HttpExchange httpExchange) throws IOException {
                ByteSource byteSource = Files.asByteSource(file);
                httpExchange.sendResponseHeaders(200, byteSource.size());
                BufferedOutputStream os = new BufferedOutputStream(httpExchange.getResponseBody());
                os.write(byteSource.read());
                os.flush();
                os.close();
            }
        });
    }
View Full Code Here

      assertPayloadEquals(request, "whoops", "application/unknown", false);
   }

   public void testPutPayloadEnclosingGenerateMD5() throws SecurityException, NoSuchMethodException, IOException {
      Invokable<?, ?> method = method(TestTransformers.class, "put", PayloadEnclosing.class);
      ByteSource byteSource = ByteSource.wrap("whoops".getBytes(UTF_8));
      PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl(Payloads.newByteSourcePayload(byteSource));
      payloadEnclosing.getPayload().getContentMetadata().setContentLength(byteSource.size());
      payloadEnclosing.getPayload().getContentMetadata().setContentMD5(byteSource.hash(Hashing.md5()).asBytes());

      GeneratedHttpRequest request = processor.apply(Invocation.create(method,
            ImmutableList.<Object> of(payloadEnclosing)));
      assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1");
      assertNonPayloadHeadersEqual(request, "");
View Full Code Here

   }

   public void testPutInputStreamPayloadEnclosingGenerateMD5() throws SecurityException, NoSuchMethodException,
         IOException {
      Invokable<?, ?> method = method(TestTransformers.class, "put", PayloadEnclosing.class);
      ByteSource byteSource = ByteSource.wrap("whoops".getBytes(UTF_8));
      PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl(
            newInputStreamPayload(byteSource.openStream()));
      payloadEnclosing.getPayload().getContentMetadata().setContentLength(byteSource.size());
      payloadEnclosing.getPayload().getContentMetadata().setContentMD5(byteSource.hash(Hashing.md5()).asBytes());

      GeneratedHttpRequest request = processor.apply(Invocation.create(method,
            ImmutableList.<Object> of(payloadEnclosing)));
      assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1");
      assertNonPayloadHeadersEqual(request, "");
View Full Code Here

      assertPayloadEquals(request, "whoops", "application/unknown", null, null, "en", false);
   }

   public void testPutPayloadWithGeneratedMD5AndNoContentType() throws SecurityException, NoSuchMethodException,
         IOException {
      ByteSource byteSource = ByteSource.wrap("whoops".getBytes(UTF_8));
      Payload payload = Payloads.newByteSourcePayload(byteSource);
      payload.getContentMetadata().setContentLength(byteSource.size());
      payload.getContentMetadata().setContentMD5(byteSource.hash(Hashing.md5()).asBytes());

      Invokable<?, ?> method = method(TestTransformers.class, "put", Payload.class);
      GeneratedHttpRequest request = processor.apply(Invocation.create(method,
            ImmutableList.<Object> of(payload)));
      assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1");
View Full Code Here

      assertPayloadEquals(request, "whoops", "application/unknown", false);
   }

   public void testPutInputStreamPayloadWithMD5() throws NoSuchAlgorithmException, IOException, SecurityException,
         NoSuchMethodException {
      ByteSource byteSource = ByteSource.wrap("whoops".getBytes(UTF_8));
      Payload payload = Payloads.newByteSourcePayload(byteSource);
      payload.getContentMetadata().setContentLength(byteSource.size());
      payload.getContentMetadata().setContentMD5(byteSource.hash(Hashing.md5()).asBytes());

      Invokable<?, ?> method = method(TestTransformers.class, "put", Payload.class);
      GeneratedHttpRequest request = processor.apply(Invocation.create(method,
            ImmutableList.<Object> of(payload)));
      assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1");
View Full Code Here

   @Override
   public Blob getBlob(final String container, final String key) {
      BlobBuilder builder = blobBuilders.get();
      builder.name(key);
      File file = getFileForBlobKey(container, key);
      ByteSource byteSource = Files.asByteSource(file);
      try {
         builder.payload(byteSource)
            .contentLength(byteSource.size())
            .contentMD5(byteSource.hash(Hashing.md5()).asBytes());
      } catch (IOException e) {
         logger.error("An error occurred calculating MD5 for blob %s from container ", key, container);
         Throwables.propagateIfPossible(e);
      }
      Blob blob = builder.build();
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

      // 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

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.