Skip to content

Commit

Permalink
more ctors
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jun 22, 2017
1 parent 5d012b3 commit ae141b0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
24 changes: 22 additions & 2 deletions src/main/java/org/cactoos/io/FileAsInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.io.FileNotFoundException;
import java.io.InputStream;
import org.cactoos.Input;
import org.cactoos.Scalar;
import org.cactoos.func.UncheckedScalar;

/**
* File as Input.
Expand All @@ -43,19 +45,37 @@ public final class FileAsInput implements Input {
/**
* The file.
*/
private final File file;
private final UncheckedScalar<File> file;

/**
* Ctor.
* @param src The file
*/
public FileAsInput(final File src) {
this(() -> src);
}

/**
* Ctor.
* @param src The file
* @since 0.8
*/
public FileAsInput(final Scalar<File> src) {
this(new UncheckedScalar<>(src));
}

/**
* Ctor.
* @param src The file
* @since 0.8
*/
public FileAsInput(final UncheckedScalar<File> src) {
this.file = src;
}

@Override
public InputStream stream() throws FileNotFoundException {
return new FileInputStream(this.file);
return new FileInputStream(this.file.asValue());
}

}
24 changes: 22 additions & 2 deletions src/main/java/org/cactoos/io/FileAsOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.io.FileOutputStream;
import java.io.OutputStream;
import org.cactoos.Output;
import org.cactoos.Scalar;
import org.cactoos.func.UncheckedScalar;

/**
* File as Output.
Expand All @@ -43,19 +45,37 @@ public final class FileAsOutput implements Output {
/**
* The file.
*/
private final File file;
private final UncheckedScalar<File> file;

/**
* Ctor.
* @param src The file
*/
public FileAsOutput(final File src) {
this(() -> src);
}

/**
* Ctor.
* @param src The file
* @since 0.8
*/
public FileAsOutput(final Scalar<File> src) {
this(new UncheckedScalar<>(src));
}

/**
* Ctor.
* @param src The file
* @since 0.8
*/
public FileAsOutput(final UncheckedScalar<File> src) {
this.file = src;
}

@Override
public OutputStream stream() throws FileNotFoundException {
return new FileOutputStream(this.file);
return new FileOutputStream(this.file.asValue());
}

}

0 comments on commit ae141b0

Please sign in to comment.