mirror of https://github.com/apache/jclouds.git
Prefer Files.copy to copy streams
This commit is contained in:
parent
4e35658940
commit
caccd9cf4c
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.swift.blobstore.integration;
|
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 com.google.common.io.InputSupplier;
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
@ -31,7 +31,9 @@ import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.DataProvider;
|
import org.testng.annotations.DataProvider;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,10 +94,7 @@ public class SwiftBlobIntegrationLiveTest extends BaseBlobIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipartChunkedFileStream() throws IOException, InterruptedException {
|
public void testMultipartChunkedFileStream() throws IOException, InterruptedException {
|
||||||
FileOutputStream fous = new FileOutputStream(new File("target/const.txt"));
|
Files.copy(oneHundredOneConstitutions, new File("target/const.txt"));
|
||||||
ByteStreams.copy(oneHundredOneConstitutions, fous);
|
|
||||||
fous.flush();
|
|
||||||
fous.close();
|
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -24,7 +24,6 @@ import static org.testng.Assert.assertNotNull;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -47,7 +46,6 @@ import org.jclouds.util.Strings2;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
import com.google.common.io.CharStreams;
|
import com.google.common.io.CharStreams;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import com.google.common.net.MediaType;
|
import com.google.common.net.MediaType;
|
||||||
|
@ -78,7 +76,6 @@ public class DataNonCDMIContentTypeApiLiveTest extends BaseCDMIApiLiveTest {
|
||||||
|
|
||||||
Payload payloadIn;
|
Payload payloadIn;
|
||||||
Payload payloadOut;
|
Payload payloadOut;
|
||||||
FileOutputStream fos;
|
|
||||||
|
|
||||||
CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder.metadata(pContainerMetaDataIn);
|
CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder.metadata(pContainerMetaDataIn);
|
||||||
ContainerApi containerApi = cdmiContext.getApi().getApi();
|
ContainerApi containerApi = cdmiContext.getApi().getApi();
|
||||||
|
@ -185,10 +182,7 @@ public class DataNonCDMIContentTypeApiLiveTest extends BaseCDMIApiLiveTest {
|
||||||
// assertEquals(Strings2.toString(payloadOut), value);
|
// assertEquals(Strings2.toString(payloadOut), value);
|
||||||
// byte[] _bytes = ByteStreams.toByteArray(payloadOut);
|
// byte[] _bytes = ByteStreams.toByteArray(payloadOut);
|
||||||
tmpFileOut = new File(Files.createTempDir(), "temp.txt");
|
tmpFileOut = new File(Files.createTempDir(), "temp.txt");
|
||||||
fos = new FileOutputStream(tmpFileOut);
|
Files.copy(payloadOut, tmpFileOut);
|
||||||
ByteStreams.copy(payloadOut, fos);
|
|
||||||
fos.flush();
|
|
||||||
fos.close();
|
|
||||||
assertEquals(Files.equal(tmpFileOut, tmpFileIn), true);
|
assertEquals(Files.equal(tmpFileOut, tmpFileIn), true);
|
||||||
tmpFileOut.delete();
|
tmpFileOut.delete();
|
||||||
|
|
||||||
|
@ -236,10 +230,7 @@ public class DataNonCDMIContentTypeApiLiveTest extends BaseCDMIApiLiveTest {
|
||||||
payloadOut = dataNonCDMIContentTypeApi.getValue(inFile.getName());
|
payloadOut = dataNonCDMIContentTypeApi.getValue(inFile.getName());
|
||||||
assertNotNull(payloadOut);
|
assertNotNull(payloadOut);
|
||||||
tmpFileOut = new File(Files.createTempDir(), "temp.jpg");
|
tmpFileOut = new File(Files.createTempDir(), "temp.jpg");
|
||||||
fos = new FileOutputStream(tmpFileOut);
|
Files.copy(payloadOut, tmpFileOut);
|
||||||
ByteStreams.copy(payloadOut, fos);
|
|
||||||
fos.flush();
|
|
||||||
fos.close();
|
|
||||||
assertEquals(Files.equal(tmpFileOut, inFile), true);
|
assertEquals(Files.equal(tmpFileOut, inFile), true);
|
||||||
tmpFileOut.delete();
|
tmpFileOut.delete();
|
||||||
|
|
||||||
|
@ -288,10 +279,7 @@ public class DataNonCDMIContentTypeApiLiveTest extends BaseCDMIApiLiveTest {
|
||||||
payloadOut = dataNonCDMIContentTypeApi.getValue(inFile.getName());
|
payloadOut = dataNonCDMIContentTypeApi.getValue(inFile.getName());
|
||||||
assertNotNull(payloadOut);
|
assertNotNull(payloadOut);
|
||||||
tmpFileOut = new File(Files.createTempDir(), "temp.jpg");
|
tmpFileOut = new File(Files.createTempDir(), "temp.jpg");
|
||||||
fos = new FileOutputStream(tmpFileOut);
|
Files.copy(payloadOut, tmpFileOut);
|
||||||
ByteStreams.copy(payloadOut, fos);
|
|
||||||
fos.flush();
|
|
||||||
fos.close();
|
|
||||||
assertEquals(Files.equal(tmpFileOut, inFile), true);
|
assertEquals(Files.equal(tmpFileOut, inFile), true);
|
||||||
tmpFileOut.delete();
|
tmpFileOut.delete();
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ import static org.testng.Assert.fail;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.zip.GZIPInputStream;
|
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.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
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 com.google.common.io.InputSupplier;
|
||||||
|
|
||||||
import org.testng.ITestContext;
|
import org.testng.ITestContext;
|
||||||
|
@ -152,17 +151,14 @@ public class AWSS3ClientLiveTest extends S3ClientLiveTest {
|
||||||
|
|
||||||
public void testMultipartChunkedFileStream() throws IOException, InterruptedException {
|
public void testMultipartChunkedFileStream() throws IOException, InterruptedException {
|
||||||
|
|
||||||
FileOutputStream fous = new FileOutputStream(new File("target/const.txt"));
|
File file = new File("target/const.txt");
|
||||||
ByteStreams.copy(oneHundredOneConstitutions, fous);
|
Files.copy(oneHundredOneConstitutions, file);
|
||||||
fous.flush();
|
|
||||||
fous.close();
|
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BlobStore blobStore = view.getBlobStore();
|
BlobStore blobStore = view.getBlobStore();
|
||||||
blobStore.createContainerInLocation(null, containerName);
|
blobStore.createContainerInLocation(null, containerName);
|
||||||
Blob blob = blobStore.blobBuilder("const.txt")
|
Blob blob = blobStore.blobBuilder("const.txt").payload(file).build();
|
||||||
.payload(new File("target/const.txt")).build();
|
|
||||||
blobStore.putBlob(containerName, blob, PutOptions.Builder.multipart());
|
blobStore.putBlob(containerName, blob, PutOptions.Builder.multipart());
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in New Issue