Skip to content

Commit

Permalink
Merged BytesAsInput into InputOf
Browse files Browse the repository at this point in the history
  • Loading branch information
ixmanuel committed Jul 21, 2017
1 parent 2885eb9 commit 1a725ec
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 156 deletions.
1 change: 0 additions & 1 deletion src/main/java/org/cactoos/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
* @author Yegor Bugayenko (yegor256@gmail.com)
* @author Fabricio Cabral (fabriciofx@gmail.com)
* @version $Id$
* @see org.cactoos.io.BytesAsInput
* @see InputOf
* @see org.cactoos.io.PathAsInput
* @since 0.1
Expand Down
92 changes: 0 additions & 92 deletions src/main/java/org/cactoos/io/BytesAsInput.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/io/DeadInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class DeadInput implements Input {

@Override
public InputStream stream() throws IOException {
return new BytesAsInput(new EmptyBytes()).stream();
return new InputOf(new EmptyBytes()).stream();
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/io/InputAsProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public InputAsProperties(final Text text) {
* @since 0.9
*/
public InputAsProperties(final Bytes bytes) {
this(new BytesAsInput(bytes));
this(new InputOf(bytes));
}

/**
Expand Down
61 changes: 32 additions & 29 deletions src/main/java/org/cactoos/io/InputOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.cactoos.io;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -36,6 +37,8 @@
import org.cactoos.Text;
import org.cactoos.func.IoCheckedScalar;
import org.cactoos.func.UncheckedScalar;
import org.cactoos.text.ArrayAsBytes;
import org.cactoos.text.TextAsBytes;

/**
* InputOf
Expand All @@ -44,12 +47,12 @@
*
* @author Ix (ixmanuel@yahoo.com)
* @version $Id$
* @since 0.12
* @since 0.11.8
*/
public final class InputOf implements Input {

/**
* Input: BytesAsInput, InputStreamAsInput, PathAsInput.
* Input: PathAsInput.
*/
private final Input origin;

Expand Down Expand Up @@ -92,49 +95,36 @@ public InputOf(final Path path) {
/**
* Ctor.
*
* @param stream The stream
*/
public InputOf(final InputStream stream) {
this(new InputStreamAsInput(stream));
}

/**
* Ctor.
*
* @param string The URL
* @param uri The URL
*/
public InputOf(final String string) {
public InputOf(final URI uri) {
this(() -> {
return new IoCheckedScalar<URL>(
() -> new URL(string)
() -> uri.toURL()
).value().openStream();
});
}

/**
* Ctor.
*
* @param uri The URL
* @param url The url
*/
public InputOf(final URI uri) {
public InputOf(final URL url) {
this(() -> {
return new IoCheckedScalar<URL>(
() -> uri.toURL()
() -> url
).value().openStream();
});
}

/**
* Ctor.
*
* @param url The URL
* @param string The string
*/
public InputOf(final URL url) {
this(() -> {
return new IoCheckedScalar<URL>(
() -> url
).value().openStream();
});
public InputOf(final String string) {
this(new TextAsBytes(string));
}

/**
Expand All @@ -143,7 +133,7 @@ public InputOf(final URL url) {
* @param text The text
*/
public InputOf(final Text text) {
this(new BytesAsInput(text));
this(new TextAsBytes(text));
}

/**
Expand All @@ -152,16 +142,29 @@ public InputOf(final Text text) {
* @param bytes The bytes
*/
public InputOf(final byte[] bytes) {
this(new BytesAsInput(bytes));
this(new ArrayAsBytes(bytes));
}

/**
* Ctor.
*
* @param bytes The bytes
* @param src The bytes
*/
public InputOf(final Bytes src) {
this(() -> {
return new IoCheckedScalar<InputStream>(
() -> new ByteArrayInputStream(src.asBytes())
).value();
});
}

/**
* Ctor.
*
* @param stream The stream
*/
public InputOf(final Bytes bytes) {
this(new BytesAsInput(bytes));
public InputOf(final InputStream stream) {
this(new InputStreamAsInput(stream));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/io/ResourceAsInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public ResourceAsInput(final String res) {
* @param fbk Fallback
*/
public ResourceAsInput(final String res, final String fbk) {
this(res, input -> new BytesAsInput(new TextAsBytes(fbk)));
this(res, input -> new InputOf(new TextAsBytes(fbk)));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/cactoos/io/TeeInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public TeeInput(final File input, final Path output) {
* @since 0.5
*/
public TeeInput(final String input, final File file) {
this(new BytesAsInput(input), new FileAsOutput(file));
this(new InputOf(input), new FileAsOutput(file));
}

/**
Expand All @@ -108,7 +108,7 @@ public TeeInput(final String input, final File file) {
* @since 0.5
*/
public TeeInput(final String input, final Path file) {
this(new BytesAsInput(input), new PathAsOutput(file));
this(new InputOf(input), new PathAsOutput(file));
}

/**
Expand All @@ -118,7 +118,7 @@ public TeeInput(final String input, final Path file) {
* @since 0.5
*/
public TeeInput(final byte[] input, final Path file) {
this(new BytesAsInput(input), new PathAsOutput(file));
this(new InputOf(input), new PathAsOutput(file));
}

/**
Expand All @@ -128,7 +128,7 @@ public TeeInput(final byte[] input, final Path file) {
* @since 0.5
*/
public TeeInput(final String input, final Output output) {
this(new BytesAsInput(input), output);
this(new InputOf(input), output);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/cactoos/io/InputAsBytesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void readsLargeInMemoryContent() throws IOException {
MatcherAssert.assertThat(
"Can't read large content from in-memory Input",
new InputAsBytes(
new BytesAsInput(
new InputOf(
String.join(
"",
new LimitedIterable<>(
Expand Down Expand Up @@ -91,7 +91,7 @@ public void readsInputIntoBytes() throws IOException {
"Can't read bytes from Input",
new String(
new InputAsBytes(
new BytesAsInput(
new InputOf(
new TextAsBytes(
new StringAsText("Hello, друг!")
)
Expand All @@ -112,7 +112,7 @@ public void readsInputIntoBytesWithSmallBuffer() throws IOException {
"Can't read bytes from Input with a small reading buffer",
new String(
new InputAsBytes(
new BytesAsInput(
new InputOf(
new TextAsBytes(
new StringAsText("Hello, товарищ!")
)
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/cactoos/io/InputAsLSInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void readsSimpleInput() {
MatcherAssert.assertThat(
"Can't read simple input",
new InputAsLSInput(
new BytesAsInput("hello, world!")
new InputOf("hello, world!")
).getStringData(),
Matchers.endsWith("world!")
);
Expand Down
Loading

0 comments on commit 1a725ec

Please sign in to comment.