Skip to content

Commit

Permalink
#18: Close the IO resource(s) explicitly in order to prevent open str…
Browse files Browse the repository at this point in the history
…eam leaks.

Fixed #18.
  • Loading branch information
dgroup committed Oct 27, 2018
1 parent b20343d commit c802869
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/com/github/dgroup/velocity/rs/RsEnvelope.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.github.dgroup.velocity.Arg;
import com.github.dgroup.velocity.Resource;
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;
import org.apache.velocity.Template;
Expand Down Expand Up @@ -53,19 +54,20 @@ public class RsEnvelope implements Resource<String> {

/**
* Ctor.
* @param src The Velocity template as {@link org.cactoos.Input}.
* @param tname The name of Velocity template.
* @param src The Velocity template as {@link org.cactoos.Input}.
* The input stream will be closed automatically by {@link RsEnvelope}.
*/
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public RsEnvelope(final Scalar<String> tname, final Scalar<Input> src) {
this(
ctx -> {
// @checkstyle IllegalCatchCheck (20 lines)
try {
try (InputStream inp = src.value().stream()) {
final RuntimeServices rsrv = RuntimeSingleton
.getRuntimeServices();
final StringReader srdr = new StringReader(
new TextOf(src.value()).asString()
new TextOf(inp).asString()
);
final Template template = new Template();
template.setRuntimeServices(rsrv);
Expand Down

0 comments on commit c802869

Please sign in to comment.