Skip to content

Commit

Permalink
Replace prefix Safe by CloseShield #1449
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier B. OURA committed Mar 14, 2021
1 parent 791a552 commit 457e647
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
* @since 1.0.0
*/
public final class SafeInput implements Input {
public final class CloseShieldInput implements Input {

/**
* Origin.
Expand All @@ -45,13 +45,13 @@ public final class SafeInput implements Input {
* Ctor.
* @param origin Origin
*/
public SafeInput(final Input origin) {
public CloseShieldInput(final Input origin) {
this.origin = origin;
}

@Override
public InputStream stream() throws Exception {
return new SafeInputStream(this.origin.stream());
return new CloseShieldInputStream(this.origin.stream());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*
* @since 1.0.0
*/
public final class SafeInputStream extends InputStream {
public final class CloseShieldInputStream extends InputStream {

/**
* Inner {@link InputStream}.
Expand All @@ -46,7 +46,7 @@ public final class SafeInputStream extends InputStream {
* Ctor.
* @param origin Origin
*/
public SafeInputStream(final InputStream origin) {
public CloseShieldInputStream(final InputStream origin) {
super();
this.inner = new AtomicReference<>(origin);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
* @since 1.0.0
*/
public final class SafeOutput implements Output {
public final class CloseShieldOutput implements Output {

/**
* Output to preserve.
Expand All @@ -45,12 +45,12 @@ public final class SafeOutput implements Output {
* Ctor.
* @param origin Output to preserve.
*/
public SafeOutput(final Output origin) {
public CloseShieldOutput(final Output origin) {
this.origin = origin;
}

@Override
public OutputStream stream() throws Exception {
return new SafeOutputStream(this.origin.stream());
return new CloseShieldOutputStream(this.origin.stream());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*
* @since 1.0.0
*/
public final class SafeOutputStream extends OutputStream {
public final class CloseShieldOutputStream extends OutputStream {

/**
* Inner {@link OutputStream}.
Expand All @@ -46,7 +46,7 @@ public final class SafeOutputStream extends OutputStream {
* Ctor.
* @param origin Origin
*/
public SafeOutputStream(final OutputStream origin) {
public CloseShieldOutputStream(final OutputStream origin) {
super();
this.inner = new AtomicReference<>(origin);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/io/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @todo #1449:30min We must find all the classes that closes stream of
* {@link org.cactoos.Input} or {@link org.cactoos.Output} that have been passed
* to them and document them about this behaviour and refer them to the existence
* of {@link org.cactoos.io.SafeInput} and {@link org.cactoos.io.SafeOutput}
* of {@link org.cactoos.io.CloseShieldInput} and {@link org.cactoos.io.CloseShieldOutput}
* and how to use them.
*/
package org.cactoos.io;
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
import org.llorllale.cactoos.matchers.Verifies;

/**
* Test case for {@link SafeInputStream}.
* Test case for {@link CloseShieldInputStream}.
* @since 1.0.0
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
final class SafeInputStreamTest {
final class CloseShieldInputStreamTest {

@Test
@SuppressWarnings("try")
void preventsOriginalStreamToBeClosed() throws Exception {
try (FakeInputStream origin = new FakeInputStream()) {
// @checkstyle EmptyBlockCheck (2 lines)
try (InputStream stream = new SafeInputStream(origin)) {
try (InputStream stream = new CloseShieldInputStream(origin)) {
}
new Assertion<>(
"Must not close origin stream",
Expand All @@ -60,7 +60,7 @@ void readsContent() throws Exception {
try (InputStream in = new InputStreamOf(content)) {
new Assertion<>(
"Must read from text",
new TextOf(new SafeInputStream(in)),
new TextOf(new CloseShieldInputStream(in)),
new IsText(content)
).affirm();
}
Expand All @@ -72,7 +72,7 @@ void makesDataAvailable() throws IOException {
try (InputStream in = new InputStreamOf(content)) {
new Assertion<>(
"Must show that data is available",
new SafeInputStream(in).available(),
new CloseShieldInputStream(in).available(),
new Verifies<>(l -> l > 0)
).affirm();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
import org.llorllale.cactoos.matchers.IsText;

/**
* Test case for {@link SafeInput}.
* Test case for {@link CloseShieldInput}.
* @since 1.0.0
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
final class SafeInputTest {
final class CloseShieldInputTest {

@Test
@SuppressWarnings("try")
Expand All @@ -44,7 +44,7 @@ void preventsOriginalStreamToBeClosed() throws Exception {
// @checkstyle EmptyBlockCheck (5 lines)
try (
InputStream stream =
new SafeInput(new InputOf(origin)).stream()
new CloseShieldInput(new InputOf(origin)).stream()
) {
}
new Assertion<>(
Expand All @@ -63,7 +63,7 @@ void readsContent() throws Exception {
) {
new Assertion<>(
"Must read text",
new TextOf(new SafeInput(new InputOf(in))),
new TextOf(new CloseShieldInput(new InputOf(in))),
new IsText(content)
).affirm();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
import org.llorllale.cactoos.matchers.IsText;

/**
* Test case for {@link SafeOutputStream}.
* Test case for {@link CloseShieldOutputStream}.
* @since 1.0.0
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
final class SafeOutputStreamTest {
final class CloseShieldOutputStreamTest {

@Test
void writesContentToFile(@TempDir final Path tempdir) throws IOException {
Expand All @@ -53,7 +53,7 @@ void writesContentToFile(@TempDir final Path tempdir) throws IOException {
new Sticky(
new TeeInput(
new ResourceOf("org/cactoos/small-text.txt"),
new OutputTo(new SafeOutputStream(out))
new OutputTo(new CloseShieldOutputStream(out))
)
)
),
Expand All @@ -69,7 +69,7 @@ void writesContentToFile(@TempDir final Path tempdir) throws IOException {
void preventsOriginalStreamToBeClosed() throws Exception {
try (FakeOutputStream origin = new FakeOutputStream()) {
// @checkstyle EmptyBlockCheck (2 lines)
try (OutputStream stream = new SafeOutputStream(origin)) {
try (OutputStream stream = new CloseShieldOutputStream(origin)) {
}
new Assertion<>(
"Must not close origin stream",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@
import org.llorllale.cactoos.matchers.Assertion;

/**
* Test case for {@link SafeOutput}.
* Test case for {@link CloseShieldOutput}.
* @since 1.0.0
*/
final class SafeOutputTest {
final class CloseShieldOutputTest {

@Test
@SuppressWarnings("try")
void preventsOriginalStreamToBeClosed() throws Exception {
try (FakeOutputStream origin = new FakeOutputStream()) {
// @checkstyle EmptyBlockCheck (5 lines)
try (
OutputStream stream = new SafeOutput(() -> origin).stream()
OutputStream stream = new CloseShieldOutput(() -> origin).stream()
) {
}
new Assertion<>(
Expand Down

0 comments on commit 457e647

Please sign in to comment.