JAVA-8365: Split or move core-java-io-conversions module

This commit is contained in:
sampadawagde
2021-11-14 13:20:22 +05:30
parent 41c8af76d2
commit ee6ea3d612
4 changed files with 55 additions and 32 deletions

View File

@@ -4,6 +4,7 @@ This module contains articles about core Java input/output(IO) conversions.
### Relevant Articles:
- [Java InputStream to String](https://www.baeldung.com/convert-input-stream-to-string)
- [Java String to InputStream](https://www.baeldung.com/convert-string-to-input-stream)
- [Java Write an InputStream to a File](https://www.baeldung.com/convert-input-stream-to-a-file)
- [Converting a BufferedReader to a JSONObject](https://www.baeldung.com/java-bufferedreader-to-jsonobject)
- [Reading a CSV File into an Array](https://www.baeldung.com/java-csv-file-array)

View File

@@ -0,0 +1,44 @@
package com.baeldung.stringtoinputstream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.io.CharSource;
public class JavaXToInputStreamUnitTest {
protected final Logger logger = LoggerFactory.getLogger(getClass());
// tests - String - InputStream
@Test
public final void givenUsingPlainJava_whenConvertingStringToInputStream_thenCorrect() throws IOException {
final String initialString = "text";
final InputStream targetStream = new ByteArrayInputStream(initialString.getBytes());
IOUtils.closeQuietly(targetStream);
}
@Test
public final void givenUsingGuava_whenConvertingStringToInputStream_thenCorrect() throws IOException {
final String initialString = "text";
final InputStream targetStream = CharSource.wrap(initialString).asByteSource(StandardCharsets.UTF_8).openStream();
IOUtils.closeQuietly(targetStream);
}
@Test
public final void givenUsingCommonsIO_whenConvertingStringToInputStream_thenCorrect() throws IOException {
final String initialString = "text";
final InputStream targetStream = IOUtils.toInputStream(initialString);
IOUtils.closeQuietly(targetStream);
}
}