• Post Reply Bookmark Topic Watch Topic
  • New Topic

Slashes being removed when getting URL streams  RSS feed

 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy all. Having an issue converting a file path to a stream for an XML DocumentBuilder to parse an XML file as a stream. Here's our code:



Upon doing this, we're getting FileNotFoundExceptions, and the error shows the file location to be "\\server_nameshare_name\..." with the slash between the server and share removed. It doesn't matter how we write the slash(es), it always removes them from that one spot and no other.

What is going on here, and how can we remedy it?

Thanks for the help!
Jason
 
Stephan van Hulst
Saloon Keeper
Posts: 6980
110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jason. Your String literal doesn't seem valid in the first place.

Backslashes in Java are used to escape special characters. In order to get a backslash in the resulting Java String, you have to escape the backslash with another backslash. Your filename would become such:

"\\\\server_name\\share_name\\..."
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried that, but still gives the same error. The weird thing is it only removes the slashes after the server_name, nowhere else in the string will it do that.

And to throw another gotcha in there, this works in the version of software we have that runs Java 1.4.2. It's not working in our Java 6 version. We're also running on different versions of OS's. Our Java 1.4.2 is on Win2k, Java 6 is on Windows 7.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the various things you tried and the resulting URLs? So far we've only seen the first half of that.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure thing. The rest of the string are directory locations and because of work rules, I'm just filling in with fluff here. Always throws a FileNotFoundException. One other thing I forgot to mention, and may play a part, is on the old version we're running in Weblogic 8.1, new version is Jboss 6.

String going into the URL -> Result in the exception thrown

\\server_name\share_name\dirA\sc\data\distrib\filename.xml -> \\server_nameshare_name\dirA\sc\data\distrib\filename.xml
\\\\server_name\\share_name\\dirA\\sc\\data\\distrib\\filename.xml -> \\server_nameshare_name\dirA\sc\data\distrib\filename.xml
//server_name/share_name/dirA/sc/data/distrib/filename.xml -> \\server_nameshare_name\dirA\sc\data\distrib\filename.xml
server_name\share_name\dirA\sc\data\disrib\filename.xml -> E:\jboss6\bin\server_name\share_name\dirA\sc\data\distrib\filename.xml (the only result that doesn't remove the slash between server and share, but of course it's pointing to a bad location)
\\server_name\\\\share_name\dirA\sc\data\distrib\filename.xml -> \\server_nameshare_name\dirA\sc\data\distrib\filename.xml (we've stuck up to 6 slashes in between server and share and it always removes them all)

So basically any time we do a \\server_name\share_name, no matter if we escape the \'s or not, it always removes just the slash(es) between the server and share. Everything else remains untouched (though if we escape the \'s it will return them as singles in the rest of the string).

The only time it doesn't remove a slash is if the string is a local file system. But then, our files don't reside locally so that doesn't do us much good.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That wasn't at all what I expected to see. Shouldn't a URL representing a file start with "file:/"?
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is correct, I was posting the strings we use. The part of the code prepends file:// to the strings. Sorry if I made that confusing.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you doing all of that? Why doesn't your code look like this:
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I suggested that we look at a different way of doing it. It's been awhile since I've looked at the api. We'll try that way, thanks :-)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!