Prefer Files.copy to copy streams

This commit is contained in:
Andrew Gaul 2012-10-24 17:41:30 -07:00
parent 4e35658940
commit caccd9cf4c
3 changed files with 12 additions and 29 deletions

View File

@ -18,7 +18,7 @@
*/
package org.jclouds.openstack.swift.blobstore.integration;
import com.google.common.io.ByteStreams;
import com.google.common.io.Files;
import com.google.common.io.InputSupplier;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.domain.Blob;
@ -31,7 +31,9 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.*;
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.util.Properties;
/**
@ -92,10 +94,7 @@ public class SwiftBlobIntegrationLiveTest extends BaseBlobIntegrationTest {
}
public void testMultipartChunkedFileStream() throws IOException, InterruptedException {
FileOutputStream fous = new FileOutputStream(new File("target/const.txt"));
ByteStreams.copy(oneHundredOneConstitutions, fous);
fous.flush();
fous.close();
Files.copy(oneHundredOneConstitutions, new File("target/const.txt"));
String containerName = getContainerName();
try {

View File

@ -24,7 +24,6 @@ import static org.testng.Assert.assertNotNull;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
@ -47,7 +46,6 @@ import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
import com.google.common.base.Charsets;
import com.google.common.io.ByteStreams;
import com.google.common.io.CharStreams;
import com.google.common.io.Files;
import com.google.common.net.MediaType;
@ -78,7 +76,6 @@ public class DataNonCDMIContentTypeApiLiveTest extends BaseCDMIApiLiveTest {
Payload payloadIn;
Payload payloadOut;
FileOutputStream fos;
CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder.metadata(pContainerMetaDataIn);
ContainerApi containerApi = cdmiContext.getApi().getApi();
@ -185,10 +182,7 @@ public class DataNonCDMIContentTypeApiLiveTest extends BaseCDMIApiLiveTest {
// assertEquals(Strings2.toString(payloadOut), value);
// byte[] _bytes = ByteStreams.toByteArray(payloadOut);
tmpFileOut = new File(Files.createTempDir(), "temp.txt");
fos = new FileOutputStream(tmpFileOut);
ByteStreams.copy(payloadOut, fos);
fos.flush();
fos.close();
Files.copy(payloadOut, tmpFileOut);
assertEquals(Files.equal(tmpFileOut, tmpFileIn), true);
tmpFileOut.delete();
@ -236,10 +230,7 @@ public class DataNonCDMIContentTypeApiLiveTest extends BaseCDMIApiLiveTest {
payloadOut = dataNonCDMIContentTypeApi.getValue(inFile.getName());
assertNotNull(payloadOut);
tmpFileOut = new File(Files.createTempDir(), "temp.jpg");
fos = new FileOutputStream(tmpFileOut);
ByteStreams.copy(payloadOut, fos);
fos.flush();
fos.close();
Files.copy(payloadOut, tmpFileOut);
assertEquals(Files.equal(tmpFileOut, inFile), true);
tmpFileOut.delete();
@ -288,10 +279,7 @@ public class DataNonCDMIContentTypeApiLiveTest extends BaseCDMIApiLiveTest {
payloadOut = dataNonCDMIContentTypeApi.getValue(inFile.getName());
assertNotNull(payloadOut);
tmpFileOut = new File(Files.createTempDir(), "temp.jpg");
fos = new FileOutputStream(tmpFileOut);
ByteStreams.copy(payloadOut, fos);
fos.flush();
fos.close();
Files.copy(payloadOut, tmpFileOut);
assertEquals(Files.equal(tmpFileOut, inFile), true);
tmpFileOut.delete();

View File

@ -31,7 +31,6 @@ import static org.testng.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;
@ -57,7 +56,7 @@ import org.jclouds.s3.domain.S3Object;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.ByteStreams;
import com.google.common.io.Files;
import com.google.common.io.InputSupplier;
import org.testng.ITestContext;
@ -152,17 +151,14 @@ public class AWSS3ClientLiveTest extends S3ClientLiveTest {
public void testMultipartChunkedFileStream() throws IOException, InterruptedException {
FileOutputStream fous = new FileOutputStream(new File("target/const.txt"));
ByteStreams.copy(oneHundredOneConstitutions, fous);
fous.flush();
fous.close();
File file = new File("target/const.txt");
Files.copy(oneHundredOneConstitutions, file);
String containerName = getContainerName();
try {
BlobStore blobStore = view.getBlobStore();
blobStore.createContainerInLocation(null, containerName);
Blob blob = blobStore.blobBuilder("const.txt")
.payload(new File("target/const.txt")).build();
Blob blob = blobStore.blobBuilder("const.txt").payload(file).build();
blobStore.putBlob(containerName, blob, PutOptions.Builder.multipart());
} finally {