From fa73bde5fb84edce20a9b4853bfd0078a9f21a5b Mon Sep 17 00:00:00 2001 From: mehyil Date: Wed, 9 Aug 2017 20:26:15 +0300 Subject: [PATCH] Add test cases #397 --- src/main/java/org/cactoos/io/ReaderOf.java | 46 +++---------------- .../java/org/cactoos/io/TeeReaderTest.java | 23 ++++++++++ 2 files changed, 29 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/cactoos/io/ReaderOf.java b/src/main/java/org/cactoos/io/ReaderOf.java index fd27bb50f8..9eeedf95d5 100644 --- a/src/main/java/org/cactoos/io/ReaderOf.java +++ b/src/main/java/org/cactoos/io/ReaderOf.java @@ -33,7 +33,6 @@ import java.net.URL; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; -import java.nio.charset.CharsetEncoder; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import org.cactoos.Bytes; @@ -281,72 +280,39 @@ public ReaderOf(final InputStream stream, final CharsetDecoder decoder) { /** * Ctor. * @param input The input - * @param out The output + * @param output The output */ - public ReaderOf(final Input input, final Output out) { + public ReaderOf(final Input input, final Output output) { this( new TeeReader( input, StandardCharsets.UTF_8, - out, + output, StandardCharsets.UTF_8 ) ); } - // @checkstyle ParameterNumberCheck (8 line) - /** - * Ctor. - * @param input The input - * @param dec The input decoder - * @param out The output - * @param enc The output encoder - */ - public ReaderOf(final Input input, final CharsetDecoder dec, - final Output out, final CharsetEncoder enc) { - this(new TeeReader(input, dec.charset(), out, enc.charset())); - } - // @checkstyle ParameterNumberCheck (8 line) /** * Ctor. * @param input The input * @param inchar The input charset - * @param out The output + * @param output The output * @param outchar The output charset */ public ReaderOf(final Input input, final Charset inchar, - final Output out, final Charset outchar) { + final Output output, final Charset outchar) { this( new TeeReader( input, inchar, - out, + output, outchar ) ); } - // @checkstyle ParameterNumberCheck (8 line) - /** - * Ctor. - * @param input The input - * @param inchar The input charset - * @param out The output - * @param outchar The output charset - */ - public ReaderOf(final Input input, final String inchar, - final Output out, final String outchar) { - this( - new TeeReader( - input, - Charset.forName(inchar), - out, - Charset.forName(outchar) - ) - ); - } - /** * Ctor. * @param rdr The reader diff --git a/src/test/java/org/cactoos/io/TeeReaderTest.java b/src/test/java/org/cactoos/io/TeeReaderTest.java index 381497b39b..2f4bf94a1f 100644 --- a/src/test/java/org/cactoos/io/TeeReaderTest.java +++ b/src/test/java/org/cactoos/io/TeeReaderTest.java @@ -64,4 +64,27 @@ public void testTeeReader() throws IOException { ); } + @Test + public void testTeeReaderWithCharset() throws IOException { + final Path src = Files.createTempFile("cactoos-3", "txt-3"); + final Path dst = Files.createTempFile("cactoos-4", "txt-4"); + final String content = "Cactoos!"; + Files.write(src, content.getBytes(StandardCharsets.UTF_8)); + final Reader reader = new ReaderOf( + new InputOf(src), + StandardCharsets.UTF_8, + new OutputTo(dst), + StandardCharsets.ISO_8859_1 + ); + int done = 0; + while (done >= 0) { + done = reader.read(); + } + reader.close(); + MatcherAssert.assertThat( + new InputOf(new ReaderOf(dst)), + new InputHasContent(content) + ); + } + }