• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Strange I/O exception with URL passed

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, guys,

I have a servlet endpoint, where I've passed the following:

http://localhost/mytestapp/dispatch?image1_url=http%3A//4.bp.blogspot.com/_V7lJdZi_T9A/TAxBjmRjECI/AAAAAAAASco/gFOEujSDGzk/s1600/rihanna+red+hair+4.jpg

As you can see, the url, passed as a parameter is UTF-8 encoded. In the 'dispatch' servlet, I do the following:



or



which both result in the following URL:

http://4.bp.blogspot.com/_V7lJdZi_T9A/TAxBjmRjECI/AAAAAAAASco/gFOEujSDGzk/s1600/rihanna red hair 4.jpg - with pluses removed and spaces instead.

When I pass it to ImageIO.read(URL), I get 'Can't get input stream for the URL; Server returned response code 400', which is strange, since ImageIO uses the very same java.net package.

Would you please assist me on how to work this around and have valid URLs when building a URL?

Thanks a lot in advance!

Martin
 
Ranch Hand
Posts: 56
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Martin,

I think the problem is not connected to utf-8. Depending on the operating system you use plus signs are not valid inside a file name. The pluses are replaced by spaces but there is not file with spaces in the name so the input stream gets no data.

Is there a way to replace the plus signs with for instance underscores?

Best,
Ramon
 
Martin Asenov
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a small snippet, which reproduces the error:


And the exception is:


Of course, I can always do the following:

but I don't consider this the proper way to fix this. Also there might be other symbols that cause the same, of which I'm not aware right now...

Thanks
 
Martin Asenov
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ramon Anger wrote:Hi Martin,

I think the problem is not connected to utf-8. Depending on the operating system you use plus signs are not valid inside a file name. The pluses are replaced by spaces but there is not file with spaces in the name so the input stream gets no data.

Is there a way to replace the plus signs with for instance underscores?

Best,
Ramon



Hi, Ramon,

Well I can't change URLs, since I've not created them Any random image URL could be passed to my app.

Best,
Martin
 
Martin Asenov
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here it is again - I regularly test my app with random images, but I can't even bring this image for reading. These spaces just freak me out. Here is the link:

http://www.sas.usace.army.mil/lakes/thurmond/images/camping%20at%20clark%202.jpg

This code always fails, no matter what I try:

Please assist me, any help will be greatly appreciated! What I need is to be able to read any image URL passed...

Best regards,
Martin
 
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic