From a41399d8a1aec1a7475764ee6314b62c936cc74d Mon Sep 17 00:00:00 2001 From: Eric Goebelbecker Date: Sat, 14 Apr 2018 11:50:07 -0400 Subject: [PATCH] BAEL-1595 - JetS3t (#3994) * BAEL-1595 - JetS3t for S3 storage. * BAEL-1595 - use ArrayList for streams * BAEL-1595 - use ArrayList for streams --- .../com/baeldung/jets3t/JetS3tLiveTest.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/libraries/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java b/libraries/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java index 3b0cc9b4c1..cf0b203e10 100644 --- a/libraries/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java +++ b/libraries/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java @@ -15,6 +15,7 @@ import org.junit.Test; import java.io.*; import java.nio.file.Files; +import java.util.ArrayList; import java.util.Arrays; import java.util.stream.Collectors; @@ -191,14 +192,25 @@ public class JetS3tLiveTest { S3Bucket bucket = createBucket(); assertNotNull(bucket); - // Create a stream - ByteArrayInputStream testStream = new ByteArrayInputStream("test stream".getBytes()); + ArrayList numbers = new ArrayList<>(); + numbers.add(2); + numbers.add(3); + numbers.add(5); + numbers.add(7); + + // Serialize ArrayList + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + ObjectOutputStream objectOutputStream = new ObjectOutputStream(bytes); + objectOutputStream.writeObject(numbers); + + // Wrap bytes + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes.toByteArray()); // Create and populate object S3Object streamObject = new S3Object("stream"); - streamObject.setDataInputStream(testStream); - streamObject.setContentLength(testStream.available()); - streamObject.setContentType("text/plain"); + streamObject.setDataInputStream(byteArrayInputStream); + streamObject.setContentLength(byteArrayInputStream.available()); + streamObject.setContentType("binary/octet-stream"); // Put it s3Service.putObject(BucketName, streamObject); @@ -206,11 +218,14 @@ public class JetS3tLiveTest { // Get it S3Object newStreamObject = s3Service.getObject(BucketName, "stream"); - // Convert back to string - String testString = new BufferedReader(new InputStreamReader(newStreamObject.getDataInputStream())) - .lines().collect(Collectors.joining("\n")); + // Convert back to ArrayList + ObjectInputStream objectInputStream = new ObjectInputStream(newStreamObject.getDataInputStream()); + ArrayList newNumbers = (ArrayList)objectInputStream.readObject(); - assertTrue("test stream".equals(testString)); + assertEquals(2, (int)newNumbers.get(0)); + assertEquals(3, (int)newNumbers.get(1)); + assertEquals(5, (int)newNumbers.get(2)); + assertEquals(7, (int)newNumbers.get(3)); // Clean up deleteObject("stream");