Package com.google.common.io

Examples of com.google.common.io.ByteSource


            String path = "__default/lb/data/" + Escaping.escape(host);
            String bucket = "__services";

            String contents = gson.toJson(data);

            ByteSource bytes = ByteSource.wrap(contents.getBytes(Charsets.UTF_8));

            String contentType = "application/json";
            Map<String, String> userAttributes = null;

            storageService.getFileService().putFile(project, bucket, path, FileBlob.build(bytes), contentType,
View Full Code Here


    }

    public void putFile(String path, File src) throws RestClientException {
        HttpRequest request = buildPut(path);

        ByteSource entity = Files.asByteSource(src);
        setRequestContent(request, entity);

        doByteArrayRequest(request);
    }
View Full Code Here

            String path = "services/dns/__default/zones/" + zoneName;
            String bucket = "__services";

            String contents = gson.toJson(zoneData);

            ByteSource bytes = ByteSource.wrap(contents.getBytes(Charsets.UTF_8));

            String contentType = "application/json";
            Map<String, String> userAttributes = null;

            storageService.getFileService().ensureBucket(project, bucket);
View Full Code Here

                return it.hasNext();
            }

            @Override
            public InputStream nextElement() {
                ByteSource is;
                try {
                    FileRange range = it.next();
                    is = getBlob(blobStore, range.getContentKey());

                    if (to != null || from != null) {
                        long start = 0;
                        if (from != null) {
                            start = Math.max(0, from - range.getStart());

                            // Enforced by the skipping logic
                            assert start <= is.size();
                        }
                        long end = is.size();
                        if (to != null) {
                            end = Math.min(to - range.getStart(), is.size());

                            // Enforced by the skipping logic
                            assert end >= 0;
                        }

                        long length = end - start;
                        if (length <= 0) {
                            assert length == 0;
                            // Easier than worrying about hasNext
                            is = EMPTY;
                        } else {
                            is = is.slice(start, length);
                        }
                    }

                    // TODO: Open buffered stream??

                    return is.openStream();
                } catch (IOException e) {
                    throw new IllegalStateException("Error reading data", e);
                }
            }
        });
View Full Code Here

        return is;
    }

    public ByteSource asByteSource(final BlobStore blobStore, final Long from, final Long to) {
        return new ByteSource() {
            @Override
            public InputStream openStream() throws IOException {
                return getInputStream(blobStore, from, to);
            }
        };
View Full Code Here

        return new CaliperConfig(mergeProperties(options.configProperties(), user, defaults));
      } catch (IOException keepGoing) {
      }
    }

    ByteSource supplier = Util.resourceSupplier(CaliperConfig.class, "default-config.properties");
    tryCopyIfNeeded(supplier, configFile);

    ImmutableMap<String, String> user;
    try {
      user = Util.loadProperties(supplier);
View Full Code Here

        // This is done before the files part so that control files can be overridden
        for (String file : CONTROL_RESOURCES) {
            final String path = String.format("/control/%s", file);
            final URL resource = DropwizardMojo.class.getResource(path);
            if (resource != null) {
                final ByteSource source = Resources.asByteSource(resource);
                final File target = new File(destinationDir, path);
                extractResource(source, target, true);
            }
        }

        // Extract/filter passed in files
        for (Resource resource : files) {
            final String path = String.format("/files/%s", resource.getTarget());
            final ByteSource source = resource.getSource();
            final File target = new File(destinationDir, path);
            extractResource(source, target, resource.isFilter());
        }
    }
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

   public static final long MiB = 1L << 20;
   public static final long GiB = 1L << 30;
   public static final long TiB = 1L << 40;

   public static Payload buildPayload(long size) {
      ByteSource data = buildData(size);
      Payload payload = new ByteSourcePayload(data);
      payload.getContentMetadata().setContentType(PLAIN_TEXT_UTF_8.toString());
      payload.getContentMetadata().setContentLength(size);
      return payload;
   }
View Full Code Here

    * @param in
    *           stream to always return
    */
   public static ByteSource asByteSource(final InputStream in) {
      checkNotNull(in, "in");
      return new ByteSource() {
         @Override
         public InputStream openStream() throws IOException {
            return in;
         }
      };
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.