Package com.google.common.io

Examples of com.google.common.io.ByteSource


   * @param  key the property key.
   * @return a ByteSource or {@code null} if the property does not exist.
   * @throws java.lang.IllegalArgumentException if the property value cannot be resolved to a byte source.
   */
  public ByteSource asByteSource(String key) {
    ByteSource byteSource = null;
    String path = delegate.getProperty(key);
    if (path != null) {
      // try to treat it as a File path
      File file = new File(path);
      if (file.isFile()) {
View Full Code Here


        if (this.forceConfig == null) {
            File conf = new File(storeDirectory, "je.properties");
            if (!conf.exists()) {
                String resource = stagingDatabase ? "je.properties.staging"
                        : "je.properties.objectdb";
                ByteSource from = Resources.asByteSource((getClass().getResource(resource)));
                try {
                    from.copyTo(Files.asByteSink(conf));
                } catch (IOException e) {
                    Throwables.propagate(e);
                }
            }
View Full Code Here

                return configFile.toURI().toURL();
            } catch (MalformedURLException e) {
                throw Throwables.propagate(e);
            }
        }
        ByteSource from;
        final URL resource = GeogigCLI.class.getResource("logback_default.xml");
        try {
            from = Resources.asByteSource(resource);
        } catch (NullPointerException npe) {
            LOGGER.warn("Couldn't obtain default logging configuration file");
            return null;
        }
        try {
            from.copyTo(Files.asByteSink(configFile));
            return configFile.toURI().toURL();
        } catch (Exception e) {
            LOGGER.warn("Error copying logback_default.xml to {}. Using default configuration.",
                    configFile, e);
            return resource;
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

   }

   @Deprecated
   public static ByteSource asByteSource(final Payload payload) {
      checkNotNull(payload, "payload");
      return new ByteSource() {
         @Override
         public InputStream openStream() throws IOException {
            return payload.openStream();
         }
      };
View Full Code Here

    boolean isFileCopied = false;
    long timeout = System.currentTimeMillis() + waitTime;
    while (!isFileCopied && System.currentTimeMillis() < timeout) {
      final SshjSshClient client = getSSHClient(host, privateKey);
      Assert.isTrue(file.exists(), "File to be copied to remote machine does not exist");
      ByteSource byteSource = com.google.common.io.Files.asByteSource(file);
      ByteSourcePayload payload = new ByteSourcePayload(byteSource);
      long byteSourceSize = -1;
      try {
        byteSourceSize = byteSource.size();
        payload.getContentMetadata().setContentLength(byteSourceSize);
      }
      catch (IOException ioe) {
        throw new IllegalStateException("Unable to retrieve size for file to be copied to remote machine.", ioe);
      }
View Full Code Here

    @Test
    public void testHttpClient() throws Exception {
        HttpClient httpClient = context.utils().http();
        // TODO: how to interpret this?
        URI uri = URI.create(s3Endpoint + "/container/blob");
        ByteSource byteSource = ByteSource.wrap(new byte[1]);
        Payload payload = new ByteSourcePayload(byteSource);
        payload.getContentMetadata().setContentLength(byteSource.size());
        httpClient.put(uri, payload);
        try (InputStream actual = httpClient.get(uri);
             InputStream expected = byteSource.openStream()) {
            assertThat(actual).hasContentEqualTo(expected);
        }
    }
View Full Code Here

    }

    @Test
    public void testBlobPutGet() throws Exception {
        String blobName = "blob";
        ByteSource byteSource = ByteSource.wrap(new byte[42]);
        Blob blob = s3BlobStore.blobBuilder(blobName)
                .payload(byteSource)
                .contentLength(byteSource.size())
                .build();
        s3BlobStore.putBlob(containerName, blob);

        Blob blob2 = s3BlobStore.getBlob(containerName, blobName);
        try (InputStream actual = blob2.getPayload().openStream();
             InputStream expected = byteSource.openStream()) {
            assertThat(actual).hasContentEqualTo(expected);
        }
    }
View Full Code Here

    @Test
    public void testBlobList() throws Exception {
        assertThat(s3BlobStore.list(containerName)).isEmpty();

        // TODO: hang with zero length blobs?
        ByteSource byteSource = ByteSource.wrap(new byte[1]);
        ImmutableSet.Builder<String> builder = ImmutableSet.builder();
        Blob blob1 = s3BlobStore.blobBuilder("blob1")
                .payload(byteSource)
                .contentLength(byteSource.size())
                .build();
        s3BlobStore.putBlob(containerName, blob1);
        for (StorageMetadata metadata : s3BlobStore.list(containerName)) {
            builder.add(metadata.getName());
        }
        assertThat(builder.build()).containsOnly("blob1");

        builder = ImmutableSet.builder();
        Blob blob2 = s3BlobStore.blobBuilder("blob2")
                .payload(byteSource)
                .contentLength(byteSource.size())
                .build();
        s3BlobStore.putBlob(containerName, blob2);
        for (StorageMetadata metadata : s3BlobStore.list(containerName)) {
            builder.add(metadata.getName());
        }
View Full Code Here

    @Test
    public void testBlobListRecursive() throws Exception {
        assertThat(s3BlobStore.list(containerName)).isEmpty();

        ByteSource byteSource = ByteSource.wrap(new byte[1]);
        Blob blob1 = s3BlobStore.blobBuilder("prefix/blob1")
                .payload(byteSource)
                .contentLength(byteSource.size())
                .build();
        s3BlobStore.putBlob(containerName, blob1);

        Blob blob2 = s3BlobStore.blobBuilder("prefix/blob2")
                .payload(byteSource)
                .contentLength(byteSource.size())
                .build();
        s3BlobStore.putBlob(containerName, blob2);

        ImmutableSet.Builder<String> builder = ImmutableSet.builder();
        for (StorageMetadata metadata : s3BlobStore.list(containerName)) {
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.