Skip to content

Commit

Permalink
Fixed ctors. for StringBuilder and StringBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
ixmanuel committed Jul 21, 2017
1 parent 13c51a6 commit aa188d0
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/main/java/org/cactoos/io/InputOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.net.URI;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import org.cactoos.Bytes;
import org.cactoos.Input;
Expand Down Expand Up @@ -156,7 +157,29 @@ public InputOf(final Reader rdr, final Charset cset, final int max) {
* @param builder The string's builder
*/
public InputOf(final StringBuilder builder) {
this(builder.toString());
this(() -> {
return new IoCheckedScalar<InputStream>(
() -> new ByteArrayInputStream(
builder.toString().getBytes(StandardCharsets.UTF_8)
)
).value();
});
}

/**
* Ctor.
*
* @param builder The string's builder
* @param cset The charset
*/
public InputOf(final StringBuilder builder, final Charset cset) {
this(() -> {
return new IoCheckedScalar<InputStream>(
() -> new ByteArrayInputStream(
builder.toString().getBytes(cset)
)
).value();
});
}

/**
Expand All @@ -165,7 +188,11 @@ public InputOf(final StringBuilder builder) {
* @param buffer The string's buffer
*/
public InputOf(final StringBuffer buffer) {
this(buffer.toString());
this(() -> {
return new IoCheckedScalar<InputStream>(
() -> new ByteArrayInputStream(buffer.toString().getBytes())
).value();
});
}

/**
Expand Down

0 comments on commit aa188d0

Please sign in to comment.