2

This issue is for Linux/Mac; I don't even think the files could exist with slashes if they were unzipped onto a Windows box.

Hi, I have a requirement to open log files which were output by the popular BRO IDS system. The files are read only and I need to process their contents without changing the filenames.

For some reason the Bro filenames are in this format: "conn.19/00/00-22/00/00.log". (also .gz versions of this, with slashes) I tried running the latest instance of Bro on my Mac with default settings and it produced log files with the same forward slash pattern, so this was a conscious decision someone else made, which I will have to work around.

In loading a file as a Java unit test, either through

File("conn.19/00/00-22/00/00.log")

or by URL

getClass().getClassLoader().getResource("conn.19/00/00-22/00/00.log")

I get the expected problem of the forward slash being interpreted as a non-existing directory.

**I've found a bunch of other downvoted questions about slashes in filenames, mostly by people that wanted to create such problems. I'm looking for a solution to deal with these bad filenames, within Java.

If I can get the file data to an InputStream, I'll be golden.

Update 1: This works better as an update than as a comment, since it changes the nature of the problem.

I discovered that in MacOS, and possibly Linux, the Finder GUI application shows the filenames with forward slashes, like this:

Bro Log File in MacOS Finder

However in the terminal I see this:

Bro Log File in terminal

Finally, the File.list() command also interprets it this way:

enter image description here

So the solution is to use the colon ':' character when reading in the file. Turns out this is one heck of a rabbit hole which may involve encoding the ':' to "%3a" or double encoding to "%253a". Neither of those have worked yet in my permutations.

See: JDK-7037120 : Identity violation in java.net.URI

Accessing an archive file with a colon in its file name throws a NullPointerException or an AssertionError

David Hoelzer
  • 15,862
  • 4
  • 48
  • 67
PHY6
  • 391
  • 3
  • 12
  • `conn.19\/00\/00-22\/00\/00.log` – ares Jan 27 '17 at 17:52
  • That's a very strange format, I was convinced you can't have `/` in filename on Unix/Linux under any circumstances because filesystem won't allow it – Luke Jan 27 '17 at 17:55
  • 1
    I agree with @Luke - the `/` is supposed to be reserved for a directory separator. Are you *sure* the character is an actual ASCII `/` and not something else? – Andrew Henle Jan 27 '17 at 19:28
  • Andrew you're correct, MacOS Finder was showing the colons as forward slashes in the GUI. Having colons seems to present its own problems. – PHY6 Jan 27 '17 at 19:36
  • They're in that format because it is a valid format and is the default for the tool. – David Hoelzer Jan 20 '20 at 23:22

0 Answers0