Skip to content

Commit

Permalink
Implementing Input output #397
Browse files Browse the repository at this point in the history
  • Loading branch information
mehyil committed Aug 9, 2017
1 parent 386b74b commit 6738be9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 31 deletions.
34 changes: 17 additions & 17 deletions src/main/java/org/cactoos/io/ReaderOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.URI;
Expand All @@ -39,6 +38,7 @@
import java.nio.file.Path;
import org.cactoos.Bytes;
import org.cactoos.Input;
import org.cactoos.Output;
import org.cactoos.Scalar;
import org.cactoos.Text;
import org.cactoos.scalar.StickyScalar;
Expand Down Expand Up @@ -280,13 +280,13 @@ public ReaderOf(final InputStream stream, final CharsetDecoder decoder) {

/**
* Ctor.
* @param input The input stream
* @param out The output stream
* @param input The input
* @param out The output
*/
public ReaderOf(final InputStream input, final OutputStream out) {
public ReaderOf(final Input input, final Output out) {
this(
new TeeReader(
input,
input,
StandardCharsets.UTF_8,
out,
StandardCharsets.UTF_8
Expand All @@ -297,26 +297,26 @@ public ReaderOf(final InputStream input, final OutputStream out) {
// @checkstyle ParameterNumberCheck (8 line)
/**
* Ctor.
* @param input The input stream
* @param input The input
* @param dec The input decoder
* @param out The output stream
* @param out The output
* @param enc The output encoder
*/
public ReaderOf(final InputStream input, final CharsetDecoder dec,
final OutputStream out, final CharsetEncoder enc) {
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 stream
* @param input The input
* @param inchar The input charset
* @param out The output stream
* @param out The output
* @param outchar The output charset
*/
public ReaderOf(final InputStream input, final Charset inchar,
final OutputStream out, final Charset outchar) {
public ReaderOf(final Input input, final Charset inchar,
final Output out, final Charset outchar) {
this(
new TeeReader(
input,
Expand All @@ -330,13 +330,13 @@ public ReaderOf(final InputStream input, final Charset inchar,
// @checkstyle ParameterNumberCheck (8 line)
/**
* Ctor.
* @param input The input stream
* @param input The input
* @param inchar The input charset
* @param out The output stream
* @param out The output
* @param outchar The output charset
*/
public ReaderOf(final InputStream input, final String inchar,
final OutputStream out, final String outchar) {
public ReaderOf(final Input input, final String inchar,
final Output out, final String outchar) {
this(
new TeeReader(
input,
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/org/cactoos/io/TeeReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
package org.cactoos.io;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
import org.cactoos.Input;
import org.cactoos.Output;

/**
* Input to Output copying reader.
Expand All @@ -44,12 +43,12 @@ public final class TeeReader extends Reader {
/**
* The source.
*/
private final InputStreamReader reader;
private final Reader reader;

/**
* The destination.
*/
private final OutputStreamWriter writer;
private final Writer writer;

// @checkstyle ParameterNumberCheck (8 line)
/**
Expand All @@ -59,11 +58,11 @@ public final class TeeReader extends Reader {
* @param out The destination
* @param outcharset The destination charset
*/
TeeReader(final InputStream input, final Charset incharset,
final OutputStream out, final Charset outcharset) {
TeeReader(final Input input, final Charset incharset,
final Output out, final Charset outcharset) {
super();
this.reader = new InputStreamReader(input, incharset);
this.writer = new OutputStreamWriter(out, outcharset);
this.reader = new ReaderOf(input, incharset);
this.writer = new WriterTo(out, outcharset);
}

@Override
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/org/cactoos/io/TeeReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
*/
package org.cactoos.io;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
Expand All @@ -51,8 +49,8 @@ public void testTeeReader() throws IOException {
final String content = "Hello, товарищ!";
Files.write(src, content.getBytes(StandardCharsets.UTF_8));
final Reader reader = new ReaderOf(
new FileInputStream(src.toFile()),
new FileOutputStream(dst.toFile())
new InputOf(src),
new OutputTo(dst)
);
int done = 0;
while (done >= 0) {
Expand Down

0 comments on commit 6738be9

Please sign in to comment.