Package com.google.common.io

Examples of com.google.common.io.ByteSource


    * @throws InterruptedException
    */
   private void uploadLargeObjectFromFile(File largeFile) throws InterruptedException, ExecutionException {
      System.out.format("Upload Large Object From File%n");

      ByteSource source = Files.asByteSource(largeFile);
      // create the payload and set the content length
      Payload payload = Payloads.newByteSourcePayload(source);
      payload.getContentMetadata().setContentLength(largeFile.length());

      Blob blob = blobStore.blobBuilder(largeFile.getName())
View Full Code Here


   private void generatePutTempURL() throws IOException {
      System.out.format("Generate PUT Temp URL%n");

      // Create the Payload
      String data = "This object will be public for 10 minutes.";
      ByteSource source = ByteSource.wrap(data.getBytes());
      Payload payload = Payloads.newByteSourcePayload(source);

      // Create the Blob
      Blob blob = blobStore.blobBuilder(FILENAME).payload(payload).contentType("text/plain").build();
      HttpRequest request = blobStoreContext.getSigner(REGION).signPutBlob(CONTAINER, blob, TEN_MINUTES);
View Full Code Here

         this.container = container;
         this.toBeUploadedBlobDetail = toBeUploadedBlobDetail;
      }

      public BlobDetail call() throws Exception {
         ByteSource byteSource = Files.asByteSource(toBeUploadedBlobDetail.getLocalFile());

         Blob blob = blobStore.blobBuilder(toBeUploadedBlobDetail.getRemoteBlobName())
               .payload(Payloads.newByteSourcePayload(byteSource))
               .contentType("") // allows Cloud Files to determine the content type
               .build();
View Full Code Here

      File tempFile = File.createTempFile(filename, suffix);

      try {
         Files.write("uploadObjectFromFile", tempFile, Charsets.UTF_8);

         ByteSource byteSource = Files.asByteSource(tempFile);
         Payload payload = Payloads.newByteSourcePayload(byteSource);

         cloudFiles.getObjectApiForRegionAndContainer(REGION, CONTAINER)
            .put(filename + suffix, payload);
View Full Code Here

   private void uploadObjectFromString() {
      System.out.format("Upload Object From String%n");

      String filename = "uploadObjectFromString.txt";

      ByteSource source = ByteSource.wrap("uploadObjectFromString".getBytes());
      Payload payload = Payloads.newByteSourcePayload(source);

      cloudFiles.getObjectApiForRegionAndContainer(REGION, CONTAINER).put(filename, payload);

      System.out.format("  %s%n", filename);
View Full Code Here

      String filename = "uploadObjectFromStringWithMetadata.txt";

      Map<String, String> userMetadata = new HashMap<String, String>();
      userMetadata.put("key1", "value1");

      ByteSource source = ByteSource.wrap("uploadObjectFromString".getBytes());

      Blob blob = blobStore.blobBuilder(filename)
            .payload(Payloads.newByteSourcePayload(source))
            .userMetadata(userMetadata)
            .build();
View Full Code Here

  private final ObjectMapper objectMapper = buildObjectMapper();

  @Override
  public <T extends Configuration> T build(Class<T> configurationClass, ConfigurationSource configurationSource) throws ConfigurationException {
    ObjectNode node;
    ByteSource byteSource = configurationSource.getByteSource();
    try {
      if (byteSource.isEmpty()) {
        node = JsonNodeFactory.instance.objectNode();
      } else {
        try (InputStream inputStream = configurationSource.getByteSource().openBufferedStream()) {
          YAMLParser yamlParser = yamlFactory.createParser(inputStream);
          node = objectMapper.readTree(yamlParser);
View Full Code Here

     * @param returnNull true to return null if the object could not be loaded
     * @param <V> the type of class
     * @return an object
     */
    public static <V> V load(File file, Class<V> cls, boolean returnNull) {
        ByteSource source = Files.asByteSource(file);
        ByteSink sink = new MkdirByteSink(Files.asByteSink(file), file.getParentFile());

        Scrambled scrambled = cls.getAnnotation(Scrambled.class);
        if (cls.getAnnotation(Scrambled.class) != null) {
            source = new ScramblingSourceFilter(source, scrambled.value());
View Full Code Here

    @Test
    public void whenReadUsingByteSource_thenRead() throws IOException {
        final String expectedValue = "Hello world";
        final File file = new File("src/test/resources/test1.in");

        final ByteSource source = Files.asByteSource(file);

        final byte[] result = source.read();
        assertEquals(expectedValue, new String(result));
    }
View Full Code Here

        final String expectedValue = "lo world";
        final File file = new File("src/test/resources/test1.in");

        final long offset = 3;
        final long length = 1000;
        final ByteSource source = Files.asByteSource(file).slice(offset, length);

        final byte[] result = source.read();
        assertEquals(expectedValue, new String(result));
    }
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.