BAEL-8497 Update "File to InputStream" article

- Added new tests for data input stream and sequence input stream in JavaXToInputStreamUnitTest
- Added new test resource anothersample.txt
This commit is contained in:
Dhawal Kapil 2018-08-27 14:07:09 +05:30
parent 17cf6fcb36
commit 3ff20c353e
2 changed files with 25 additions and 0 deletions

View File

@ -1,10 +1,12 @@
package org.baeldung.java.io;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
@ -74,6 +76,28 @@ public class JavaXToInputStreamUnitTest {
IOUtils.closeQuietly(targetStream);
}
@Test
public final void givenUsingPlainJava_whenConvertingFileToDataInputStream_thenCorrect() throws IOException {
final File initialFile = new File("src/test/resources/sample.txt");
final InputStream targetStream = new DataInputStream(new FileInputStream(initialFile));
IOUtils.closeQuietly(targetStream);
}
@Test
public final void givenUsingPlainJava_whenConvertingFileToSequenceInputStream_thenCorrect() throws IOException {
final File initialFile = new File("src/test/resources/sample.txt");
final File anotherFile = new File("src/test/resources/anothersample.txt");
final InputStream targetStream = new FileInputStream(initialFile);
final InputStream anotherTargetStream = new FileInputStream(anotherFile);
InputStream sequenceTargetStream = new SequenceInputStream(targetStream, anotherTargetStream);
IOUtils.closeQuietly(targetStream);
IOUtils.closeQuietly(anotherTargetStream);
IOUtils.closeQuietly(sequenceTargetStream);
}
@Test
public final void givenUsingGuava_whenConvertingFileToInputStream_thenCorrect() throws IOException {
final File initialFile = new File("src/test/resources/sample.txt");

View File

@ -0,0 +1 @@
...Continues