Skip to content

Commit

Permalink
gebruik geen cast naar FileInputStream om class cast exception te voo…
Browse files Browse the repository at this point in the history
…rkomen

java.lang.ClassCastException: class sun.nio.ch.ChannelInputStream cannot be cast to class java.io.FileInputStream (sun.nio.ch.ChannelInputStream and java.io.FileInputStream are in module java.base of loader 'bootstrap')
  • Loading branch information
mprins committed Jan 20, 2025
1 parent 1def1e2 commit d60b064
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static org.apache.commons.io.FileUtils.byteCountToDisplaySize;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URI;
import java.nio.file.Files;
Expand Down Expand Up @@ -398,7 +397,7 @@ public void loadZip(
}

public void loadXml(File file, BGTObjectTableWriter writer) throws Exception {
try (FileInputStream in = (FileInputStream) Files.newInputStream(file.toPath())) {
try (InputStream in = Files.newInputStream(file.toPath())) {
loadInputStream(file.getName(), in, file.length(), writer);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package nl.b3p.brmo.service.stripes;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -94,16 +94,14 @@ public Resolution check() {
LOG.info("Afgiftelijst gecontroleerd met bestand: " + file.getFileName());
brmo.closeBrmoFramework();

final FileInputStream fis = (FileInputStream) Files.newInputStream(response.toPath());
try {
try (InputStream fis = Files.newInputStream(response.toPath())) {
StreamingResolution res =
new StreamingResolution(
MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(response)) {
@Override
public void stream(HttpServletResponse response) throws Exception {
OutputStream out = response.getOutputStream();
IOUtils.copy(fis, out);
fis.close();
}
};
String extension = "pdf";
Expand Down
6 changes: 3 additions & 3 deletions brmo-taglib/src/main/java/nl/b3p/web/jsp/DownloadTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package nl.b3p.web.jsp;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.zip.GZIPOutputStream;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -103,8 +104,7 @@ private boolean streamFile(Path file, OutputStream outputStream) {
byte[] bytes = new byte[4096];
boolean success = true;

try (FileInputStream fileInputStream =
(FileInputStream) java.nio.file.Files.newInputStream(file)) {
try (InputStream fileInputStream = Files.newInputStream(file)) {
int length;
while ((length = fileInputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, length);
Expand Down

0 comments on commit d60b064

Please sign in to comment.