2

I have a small Java Application running inside IBM Integration Bus, which is installed in an AIX Server with the character encoding set to ISO-8959-1.

My application is creating a ZIP File with the filenames received as a parameter. I have a file called "Websërvícès Guide.pdf" in the filesystem which I wanted to zip but I'm unable.

This is my code:

String zipFilePath = "/tmp/EventAttachments_2018.01.25.11.39.34.zip";

// Streams buffer
int BUFFER = 2048;

// Open I/O Buffered Streams
BufferedInputStream origin = null;
FileOutputStream dest = new FileOutputStream(zipFilePath);
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
byte data[] = new byte[BUFFER];

// Oprn File Stream to my file
Path currentFilePath = Paths.get("/tmp/Websërvícès Guide.pdf");
InputStream fi = Files.newInputStream(currentFilePath, StandardOpenOption.READ);

origin = new BufferedInputStream(fi, BUFFER);
ZipEntry entry = new ZipEntry("Websërvícès Guide.pdf");
out.putNextEntry(entry);
int count;
while ((count = origin.read(data, 0, BUFFER)) != -1) {
       out.write(data, 0, count);
}
origin.close();
out.close();

Which is throwing a "File Not Found" exception in the Files.newInputStream line. I have read that Java is not working properly when checking it files with special characters exists and so on. I'm not able to perform changes in the JVM Parameters as code is executed inside a IBM JVM.

Any idea on how to solve this issue and pack the file properly in the ZIP?

Thank you

JER
  • 21
  • 1

3 Answers3

0

Can you try to pass following flag to while running your java program

-Dsun.jnu.encoding=UTF-8
  • Hi, Thanks for your answer, unfortunately application runs inside IBM Integration Bus and I'm not able to specify flags. – JER Jan 25 '18 at 16:12
0

First: In your code, you are not taking care of any Exceptions that could be thrown. I would suggest to handle the exceptions of the method or make the method throw the exception and handle it on a higher level. But somewhere you need to handle the exception. Maybe that's already the problem. (see https://stackoverflow.com/a/155655/8896833)

Second: According to ISO-8959-1 all the characters used in your filename should be covered. Are you really sure about the path your program is working in at the moment you are trying to access the file?

  • Hi, thanks for your answer, exceptions are treated in a higher-level method that handles them. Regarding the codification, I know it supports that kind of characters, but i don't know why its unable to locate this file (it locates the rest of the files which live in the same directory, but their names contain normal characters). – JER Jan 25 '18 at 16:14
0

Try to use URLDecoder class method decode(String string, String encoding);.
For example:

String path = URLDecoder.decode("Websërvícès Guide.pdf", "UTF-8"));
Dumbo
  • 1,630
  • 18
  • 33
  • Hi, thanks for your answer, I tested it but the result is the same, NoSuchFileException. – JER Jan 25 '18 at 16:12