Skip to content

Commit

Permalink
[yegor256#1889] Close streams to resources
Browse files Browse the repository at this point in the history
  • Loading branch information
pnatashap committed Feb 20, 2024
1 parent 9d0ece2 commit 4b60150
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/main/java/com/rultor/agents/daemons/Script.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.logging.Level;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.io.input.AutoCloseInputStream;

/**
* Script to run.
Expand Down Expand Up @@ -77,7 +78,10 @@ public int exec(final XML xml) throws IOException {
"cd %s && cat > %s && chmod a+x %1$s/%2$s",
Ssh.escape(dir), Ssh.escape(this.name)
),
this.getClass().getResourceAsStream(this.name),
AutoCloseInputStream.builder()
.setInputStream(
this.getClass().getResourceAsStream(this.name)
).get(),
Logger.stream(Level.INFO, this),
Logger.stream(Level.WARNING, this)
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rultor/agents/daemons/StartsDaemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private InputStream ring(final String name) throws IOException {
return new ByteArrayInputStream(
Base64.decodeBase64(
IOUtils.toByteArray(
this.getClass().getResourceAsStream(
this.getClass().getResource(
String.format("%s.base64", name)
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rultor/agents/github/qtn/QnStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public final class QnStatus implements Question {
* XSL to generate report.
*/
private static final XSL REPORT = XSLDocument.make(
QnStatus.class.getResourceAsStream("status.xsl")
QnStatus.class.getResource("status.xsl")
);

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rultor/spi/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public interface Profile {
* Schema.
*/
XSD SCHEMA = XSDDocument.make(
Talk.class.getResourceAsStream("profile.xsd")
Talk.class.getResource("profile.xsd")
);

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/rultor/spi/Talk.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public interface Talk {
* Schema.
*/
XSD SCHEMA = XSDDocument.make(
Talk.class.getResourceAsStream("talk.xsd")
Talk.class.getResource("talk.xsd")
);

/**
Expand All @@ -79,12 +79,12 @@ public interface Talk {
XSL UPGRADE = new XSLChain(
Arrays.asList(
XSLDocument.make(
Talk.class.getResourceAsStream(
Talk.class.getResource(
"upgrade/001-talks.xsl"
)
),
XSLDocument.make(
Talk.class.getResourceAsStream(
Talk.class.getResource(
"upgrade/002-public-attribute.xsl"
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rultor/web/TkButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Response act(final RqRegex req) throws IOException {
return new RsWithType(
new RsWithHeaders(
new RsWithBody(
this.getClass().getResourceAsStream(
this.getClass().getResource(
String.format("button-%s.svg", suffix)
)
),
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/rultor/web/TkDaemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.Collections;
import java.util.logging.Level;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.AutoCloseInputStream;
import org.apache.commons.io.input.ProxyReader;
import org.apache.commons.io.input.ReaderInputStream;
import org.apache.commons.text.StringEscapeUtils;
Expand Down Expand Up @@ -147,7 +148,10 @@ private InputStream html(final long number, final String hash)
StandardCharsets.UTF_8
),
TkDaemon.escape(new Tail(talk.read(), hash).read()),
this.getClass().getResourceAsStream("daemon/tail.html")
AutoCloseInputStream.builder()
.setInputStream(
this.getClass().getResourceAsStream("daemon/tail.html")
).get()
)
)
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rultor/web/TkTicks.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ final class TkTicks implements Take {
* XSLT for pulse render.
*/
private static final XSL PULSE = XSLDocument.make(
TkTicks.class.getResourceAsStream("pulse.xsl")
TkTicks.class.getResource("pulse.xsl")
);

/**
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/rultor/web/TkAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ final class TkAppTest {
@BeforeEach
void resourcesAvailable() {
Assumptions.assumeFalse(
TkAppTest.class.getResourceAsStream("/xsl/home.xsl") == null
TkAppTest.class.getResource("/xsl/home.xsl") == null
);
}

Expand Down

0 comments on commit 4b60150

Please sign in to comment.