Skip to content
Permalink
Browse files
Prefer Files.asCharSink over FileWriter
  • Loading branch information
gaul committed May 22, 2014
1 parent ff4ddd6 commit 64f7069ec0648fd52ec84faf1e67c39ac0578e2b
Showing 2 changed files with 4 additions and 10 deletions.
@@ -24,10 +24,8 @@
import static org.jclouds.examples.rackspace.cloudfiles.Constants.REGION;
import static org.jclouds.examples.rackspace.cloudfiles.Constants.SUFFIX;

import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URI;

@@ -39,6 +37,7 @@
import org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi;
import org.jclouds.rackspace.cloudfiles.v1.features.CDNApi;

import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.ByteSource;
import com.google.common.io.Closeables;
@@ -99,9 +98,7 @@ private void createObjectFromFile() throws IOException {
File tempFile = File.createTempFile(FILENAME, SUFFIX);
tempFile.deleteOnExit();

BufferedWriter out = new BufferedWriter(new FileWriter(tempFile));
out.write("Hello Cloud Files");
out.close();
Files.asCharSink(tempFile, Charsets.UTF_8).write("Hello Cloud Files");

ObjectApi objectApi = cloudFiles.objectApiInRegionForContainer(REGION, CONTAINER_PUBLISH);

@@ -22,10 +22,8 @@
import static org.jclouds.examples.rackspace.cloudfiles.Constants.PROVIDER;
import static org.jclouds.examples.rackspace.cloudfiles.Constants.REGION;

import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -38,6 +36,7 @@
import org.jclouds.openstack.swift.v1.blobstore.RegionScopedBlobStoreContext;
import org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi;

import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.ByteSource;
import com.google.common.io.Closeables;
@@ -94,9 +93,7 @@ private void uploadObjectFromFile() throws IOException {
File tempFile = File.createTempFile(filename, suffix);
tempFile.deleteOnExit();

BufferedWriter out = new BufferedWriter(new FileWriter(tempFile));
out.write("uploadObjectFromFile");
out.close();
Files.asCharSink(tempFile, Charsets.UTF_8).write("uploadObjectFromFile");

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

0 comments on commit 64f7069

Please sign in to comment.