Skip to content

Commit

Permalink
fix modernizer waarcshuwingen in brmo-taglib module
Browse files Browse the repository at this point in the history
  • Loading branch information
mprins committed Jan 20, 2025
1 parent c5f67c3 commit 19f5217
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
21 changes: 12 additions & 9 deletions brmo-taglib/src/main/java/nl/b3p/web/jsp/DownloadTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Path;
import java.util.zip.GZIPOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -43,13 +44,14 @@ public int doEndTag() throws JspException {
if (this.file == null) {
this.file = LogfileUtil.getLogfile();
}
File f = new File(this.file);
f =
f.isAbsolute()
? f
: new File(this.pageContext.getServletContext().getRealPath("/"), this.file);
Path p = Path.of(this.file);
p =
p.isAbsolute()
? p
: Path.of(this.pageContext.getServletContext().getRealPath("/"), this.file);

sendFile(
f,
p.toFile(),
(HttpServletResponse) this.pageContext.getResponse(),
(HttpServletRequest) this.pageContext.getRequest());
return EVAL_PAGE;
Expand Down Expand Up @@ -85,7 +87,7 @@ private void sendFile(File f, HttpServletResponse response, HttpServletRequest r
throw new JspException(e.getLocalizedMessage());
}

if (!this.streamFile(f, outputStream)) {
if (!this.streamFile(f.toPath(), outputStream)) {
throw new JspException("Bestand kon niet worden geladen");
} else {
try {
Expand All @@ -97,11 +99,12 @@ private void sendFile(File f, HttpServletResponse response, HttpServletRequest r
}
}

private boolean streamFile(File file, OutputStream outputStream) {
private boolean streamFile(Path file, OutputStream outputStream) {
byte[] bytes = new byte[4096];
boolean success = true;

try (FileInputStream fileInputStream = new FileInputStream(file)) {
try (FileInputStream fileInputStream =
(FileInputStream) java.nio.file.Files.newInputStream(file)) {
int length;
while ((length = fileInputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, length);
Expand Down
8 changes: 3 additions & 5 deletions brmo-taglib/src/main/java/nl/b3p/web/jsp/LogfileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
Expand Down Expand Up @@ -56,8 +55,7 @@ public static String getLogfile() {
break;
}
}
File f = new File(file);
return f.getAbsolutePath();
return Path.of(file).toAbsolutePath().toString();
}

/**
Expand All @@ -69,14 +67,14 @@ public static String getLogfile() {
public static List<String> getLogfileList() {
List<String> files = new ArrayList<>();
// opzoeken van brmo log files, de logger heeft de naam 'file' in de log4j properties
final File f = new File(getLogfile());
File f = Path.of(getLogfile()).toFile();

// filter op basename van actuele logfile zodat geroteerde files ook in de lijst komen
DirectoryStream.Filter<Path> filter =
(Path p) -> (p.getFileName().toString().startsWith(FilenameUtils.getBaseName(f.getName())));

try (DirectoryStream<Path> directoryStream =
Files.newDirectoryStream(Paths.get(f.getParent()), filter)) {
Files.newDirectoryStream(Path.of(f.getParent()), filter)) {
for (Path path : directoryStream) {
files.add(path.toString());
}
Expand Down
17 changes: 8 additions & 9 deletions brmo-taglib/src/main/java/nl/b3p/web/jsp/TailTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package nl.b3p.web.jsp;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -58,13 +58,12 @@ public int doStartTag() throws JspException {
this.file = LogfileUtil.getLogfile();
}

File f = new File(this.file);
f =
f.isAbsolute()
? f
: new File(this.pageContext.getServletContext().getRealPath("/"), this.file);

try (InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(f))) {
Path p = Path.of(this.file);
p =
p.isAbsolute()
? p
: Path.of(this.pageContext.getServletContext().getRealPath("/"), this.file);
try (InputStreamReader inputStreamReader = new InputStreamReader(Files.newInputStream(p))) {
String line;
for (BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
(line = bufferedReader.readLine()) != null;
Expand Down

0 comments on commit 19f5217

Please sign in to comment.