ImageIO - javax.imageio.IIOException: Can't get input stream from URL
Hi,
I'm developing a program which accesses a given URL of an image and saves it to a file. However when I try this I get the following error:
javax.imageio.IIOException: Can't get input stream from URL!
at javax.imageio.ImageIO.read(Unknown Source)
at ImageSave.main(ImageSave.java:12)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
... 2 moreThe internet connection I am using uses a proxy server and I think this is where the problem lies. I'm using Eclipse version 3.3 and I've tried changing the network settings to use the proxy's hostname and port but this still isn't working. I've also tried using System.setProperty("http.proxyHost", "hostname") and System.setProperty("http.proxyPort", "port") but that hasn't worked for me either. Below is my class in full.
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
import java.net.*;
public class ImageSave
public static void main(String args[])
try {
URL url = new URL("http://www.example.com/image.jpg");
BufferedImage image = ImageIO.read(url);
ImageIO.write(image, "JPG", new File("image.jpg"));
catch (Exception e) {
e.printStackTrace();
}The error occurs with the line: BufferedImage image = ImageIO.read(url);
I have tried looking for a way to change how this specific method accesses the internet (e.g: a Proxy parameter with URLConnection) but there doesn't seem to be any.
Any help or suggestions would be greatly appreciated.
-Robert
Ah, that worked fine. I had thought of using that earlier but I was under the impression that the input stream would be HTML rather than an actual image. Not sure why.. Anyway, thanks very much for your help!
Here is the new code with your suggested revisions and a URLConnection to get the input stream:
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
import java.net.*;
public class ImageSave
public static void main(String args[])
try {
// This is where you'd define the proxy's host name and port.
SocketAddress address = new InetSocketAddress(hostName, port);
// Create an HTTP Proxy using the above SocketAddress.
Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
URL url = new URL("www.example.com/image.jpg");
// Open a connection to the URL using the proxy information.
URLConnection conn = url.openConnection(proxy);
InputStream inStream = conn.getInputStream();
// BufferedImage image = ImageIO.read(url);
// Use the InputStream flavor of ImageIO.read() instead.
BufferedImage image = ImageIO.read(inStream);
ImageIO.write(image, "JPG", new File("image.jpg"));
catch (Exception e) {
e.printStackTrace();
}Edited by: Ragnarob on Apr 21, 2009 2:49 AM
Similar Messages
-
HT201077 can't get photo stream from icloud to download to my pc
Can't get th photo stream from the icloud to download to my pc, using Windows 7 operation system. It was working for a while and now it just stopped. I checked the iphone and pc to make sure the settings are all correct. Turned both devices off and rebooted but no luck. Anyone had this problem?
Yes I have the same problem. I have posted a question on this site too. My calendar is copying via icloud OK but my contacts and photo stream aren't anymore
-
Javax.imageio.IIOException: Can't read input file!
That is the error I get every time I try to run the .jar file. Yet when I run it in the compiler it works just fine. I'm not sure what to make of this, here is the code any help you can provide will be appreciated.public void setGraphic(String image) {
String fileLoc = getClass().getResource("/com/siteName/Graphics/" + image).getPath();
try {
fileLoc = URLDecoder.decode(fileLoc,"UTF-8");
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
File file = new File(fileLoc);
try {
this.image = ImageIO.read(file);
} catch (IOException ex) {
ex.printStackTrace();
}Is your image in the jar? If so, use URL, not File:
URL url = getClass().getResource("/com/siteName/Graphics/" + image);
this.image = ImageIO.read(url ); -
IIOException: Can't read input file!
Hi all,
I have a incomprehensible problem. I have a java application wich manipulate images. This application works fine with a desktop environment but when I try to migrate it on production server (without X), a exception is catch...
javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1279)
at FaceplateBuilder.fillImageByClients(FaceplateBuilder.java:95)
at FaceplateBuilder.createPack(FaceplateBuilder.java:68)
at FaceplateBuilder.run(FaceplateBuilder.java:39) This is the following code...
File tmp = new File("/tmp/test.jpg");
BufferedImage in = ImageIO.read(tmp);The file /tmp/test.jpg exist.
Here are all tested solutions without success :
*I've tried to upgrade the java version (1.5.0_14 to 1.6.0_06). 1.6.0_06 is the desktop environment configuration.
* I read this page: [Using Headless Mode in the Java SE Platform|http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/] and I try to launch java with java.awt.headless=true variable.
* I have install the [X11 dev library|http://javatechniques.com/public/java/docs/hosting/headless-java-x11-libraries.html]. (apt-get install libice-dev libsm-dev libx11-dev libxp-dev libxt-dev libxtst-dev)
* I have changed the ImageIO code by following :
Image tmp = loadImageFile("/tmp/test.jpg");
BufferedImage in = toBufferedImage(tmp);
public static BufferedImage toBufferedImage(Image image) {
if (image instanceof BufferedImage) {
return ((BufferedImage) image);
} else {
BufferedImage bufferedImage = new BufferedImage(image
.getWidth(null), image.getHeight(null),
BufferedImage.TYPE_INT_RGB);
Graphics g = bufferedImage.createGraphics();
g.drawImage(image, 0, 0, Color.WHITE, null);
g.dispose();
return (bufferedImage);
public static Image loadImageFile(String imgFile) {
Image img = Toolkit.getDefaultToolkit().getImage(imgFile);
MediaTracker mediaTracker = new MediaTracker(new Container());
mediaTracker.addImage(img, 0);
try {
mediaTracker.waitForID(0);
} catch (InterruptedException e) {
e.printStackTrace();
System.out.println(e.getMessage());
return (img);
}This code catches a new error...
java.lang.IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999)
at java.awt.image.BufferedImage.<init>(BufferedImage.java:314)
at FaceplateBuilder.toBufferedImage(FaceplateBuilder.java:122)
at FaceplateBuilder.fillImageByClients(FaceplateBuilder.java:95)
at FaceplateBuilder.createPack(FaceplateBuilder.java:73)
at FaceplateBuilder.run(FaceplateBuilder.java:44)I think it's the same problem... The Image can't be loaded and I don't know why ! This problem make me crazy so I tried to post here.
Thanks in advance# la /tmp/test.jpg
-rw-r--r-- 1 root root 148K 2008-07-15 13:19 /tmp/test.jpg
# ps aux | grep java
root 19147 0.0 1.8 269716 23848 pts/1 Ssl+ 19:09 0:00 java FaceplateManager Everything seems good :) -
How can i get input from user in Workflows
Hello professionals,
I'm new to SAP B1 Workflow, i have created some workflows and they all worked fine.
But, I am wondering, How can i get input from user?. For example, i want to display list of options to choose between them and route the workflow based on the selected option. I don't want to use the exclusive gateway and check for some conditions, i want to get input from user.
How can i do that?
Thanks in advance,
Kareem NaguibHi,
Please refer SAP help file:
http://help.sap.com/saphelp_sbo900/helpdata/en/b8/1f9a1197214254b79bcf8f93f9fff9/content.htm?frameset=/en/44/c4c1cd7ca22…
Thanks & Regards,
Nagarajan -
How can i get all values from jtable with out selecting?
i have one input table and two output tables (name it as output1, output2). Selected rows from input table are displayed in output1 table. The data in output1 table is temporary(means the dat wont store in database just for display purpose).
Actually what i want is how can i get all values from output1 table to output2 table with out selecting the data in output1 table?
thanks in advance.
rajaYou could set the table's data model to be the same:
output2.setModel( output1.getModel() ); -
How to get file input stream from the client machine by JSF Fileupload API?
Dear Friends,
How to get the file input stream from the client machine by JSF HtmlFileupload or fileupload API. At present, if i execute the file upload code in the client machine, it is able to get the local path of the file and looking for the file in server machine. So i am getting FileNotFoundException.
E.g., If a file is located at client machine at following location means "C:\Test\Test.txt",
uploadClass.getFileuploadComponent().getFilename().toString() returns "C:\Test\Test.txt". But it is looking for that file in server and throwing FileNotFoundException.
Please post your replies soon.
Thanks,
JPDepends on which version of JSF you're using. If JSF 1.2, I wouldn't even bother trying to hack this into JSF itself unless you can use something like Seam 2 or richfaces.
http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/rich_fileUpload.html
http://docs.jboss.org/seam/2.2.1.CR3/reference/en-US/html/controls.html#d0e29259 (look for s:fileUpload)
But if I were you, a simple non-jsf form with a servlet works best for taking file uploads.
As for JSF 2.0, there are other ways of getting it done.
http://balusc.blogspot.com/2009/12/uploading-files-with-jsf-20-and-servlet.html -
Can't get definitions factory from context in struts tiles in weblogic 10
I have exception trace which only happens whenever i recompiling my java file while running my web application in weblogic 10
javax.servlet.ServletException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Can't get definitions factory from context.
* at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)*
* at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)*
* at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)*
* at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)*
* at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)*
Caused by: javax.servlet.jsp.JspException: Can't get definitions factory from context.
* at org.apache.struts.tiles.taglib.InsertTag.processDefinitionName(InsertTag.java:580)*
* at org.apache.struts.tiles.taglib.InsertTag.createTagHandler(InsertTag.java:479)*
* at org.apache.struts.tiles.taglib.InsertTag.doStartTag(InsertTag.java:441)*
Anybody has any idea how to fix this?
It seems the error happen because weblogic trying to reload the context after i recompiling java file
How do i turn off / workaround on this?
By the way i m using struts tiles
ThanksI have exception trace which only happens whenever i recompiling my java file while running my web application in weblogic 10
javax.servlet.ServletException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Can't get definitions factory from context.
* at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)*
* at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)*
* at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)*
* at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)*
* at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)*
Caused by: javax.servlet.jsp.JspException: Can't get definitions factory from context.
* at org.apache.struts.tiles.taglib.InsertTag.processDefinitionName(InsertTag.java:580)*
* at org.apache.struts.tiles.taglib.InsertTag.createTagHandler(InsertTag.java:479)*
* at org.apache.struts.tiles.taglib.InsertTag.doStartTag(InsertTag.java:441)*
Anybody has any idea how to fix this?
It seems the error happen because weblogic trying to reload the context after i recompiling java file
How do i turn off / workaround on this?
By the way i m using struts tiles
Thanks -
I believe I have Apple TV installed, but with no functionality. Was able to select a TV show but with voice from another show--couldn't ever get rid of that voice or do any volume changes. I have sharing set in itunes but can't get any music. Can't access any streaming from laptop, iPad, or desktop--all on same network.
In a roaming network, your "main" router is the device that would require port mapping/forwarding to be configured in order to access the IP camera from the Internet. This router is also the one that would be provide the private IP address for the camera which you will want to be a static one.
So as you described your network, the IP cameras should be getting an IP address or you assigned it a static one and this is the address that you would enter in the Private IP address (or equivalent depending on the router used) field when setting up port mapping.
If you are not able to access this camera from the local network, then this should be troubleshot first. -
How can i get thes songs from ipod nano to the itunes libary??
hi
i have ipod nano and i sync it with over 500 songs .....my bad i lose all that songs on my libary .... how can i get thes songs from ipod nano to the itunes libary??See this older post from another forum member Zevoneer on different ways to copy content from your iPod to your computer.
https://discussions.apple.com/thread/2452022?start=0&tstart=0
B-rock -
Can you get values back from a stored procedure via OUTPUT parameters?
Can you get values back from calling a stored procedure via OUTPUT parameters/variables? I call the SP via a SQL statement from a script either in a WF or DF.
I thought I read some reference that DI could not get the values from OUTPUT parameters but I could not find it again (don't know if it is in any of the documentation or referred to in a forum.
I did try a couple of tests but it did not reutrn any values via OUTPUT. But before I give up I thought I'd see if you could and maybe I needed to change something.This isn't exactly an answer to your question, but I'll point out that, given that you're resorting to a SQL script in the first place, there's no reason you can't also turn the output parameters into a regular result or record set. (The following uses T-SQL, although I think it's pretty generic.)
declare @param1 int, param2 varchar(100), @return int;
exec @return = proc @param1 = @param1 output, @param2 = @param2 output;
select @param1 as param1, @param2 as param2;
That is, to get from output parameters to a "regular" output from the SQL script isn't much of a leap...
Jeff Prenevost
BI Consultant
Ann Arbor, MI -
Can viewObject get a parameter from sessionScope to binding variable?
hello,
using Jdev11g ADF Fusion application
Can viewObject get a parameter from sessionScope and assign into binding variable ? without using executeWithParameter
Thanks
greenAppleA. Safwat,
As I said before, I was not trying to be offensive, but simply to explain some of the shortcomings of one solution over another. One of the reasons people give such short answers is that many questions (including this one) have been asked and answered many many many times before on the forum. As to my reasons:
1). Overkill - overkill because you are writing code to do what the framework already provides for you.
2). Not bind-variable friendly - you are gluing in literals into a SQL statement. That means that Oracle will have to hard parse the query for each new value of the filter clause, yielding to poor performance, particularly in a multiuser environment. It should ideally be done using bind variables.
3). Insecure (think about what happens if you put "'xyz' or 1=1" into the filterValue there) - not using bind variables is a security hole. Think through what happens if a filter criteria comes through like the one I mentioned.
4). Inflexible - because you are overriding executeQueryForCollection, this VO becomes inflexible and can only be used in this particular place. Using the declarative approach outlined by Timo is more flexible
5). Bad (ok, that's my opinion there) - OK, perhaps this was a bit offensive ;)
Please don't take a critique of a post as offensive, as I assure you it was not intended to be in that spirit. As I mentioned, I greatly appreciate when people point out issues/problems/etc with my ideas, as that is the best way for me to learn. I have in the past written applications that were not bind-variable friendly, and I learned the downsides the hard way (system was horribly non-performant) - I wish someone had reviewed my approach and told me "bad idea" before the application made it into production.
Respectfully,
John -
How can I get all photos from iPhoto to automatically back up to iCloud from my Mac OSX Version 10.6.8 operating system. Not enough memory to upgrade.
You can't. iCloud is not for general file backup from a Mac. It's for backup up and syncing data between mobile devices and and Macs and The following is from this Apple document: iCloud: Backup and restore overview.
iCloud automatically backs up the most important data on your (mobile) device using iOS 5 or later. Once you have enabled Backup on your iPhone, iPad, or iPod touch .....
What is backed up
You get unlimited free storage for:
Purchased music, movies, TV shows, apps, and books
Notes: Backup of purchased music is not available in all countries. Backups of purchased movies and TV shows are U.S. only. Previous purchases may not be restored if they are no longer in the iTunes Store, App Store, or iBookstore.
Some previously purchased movies may not be available in iTunes in the Cloud. These movies will indicate that they are not available in iTunes in the Cloud on their product details page in the iTunes Store. Previous purchases may be unavailable if they have been refunded or are no longer available in the iTunes Store, App Store, or iBookstore.
You get 5 GB of free iCloud storage for:
Photos and videos in the Camera Roll
Device settings (for example: Phone Favorites, Wallpaper, and Mail, Contacts, Calendar accounts)
App data
Home screen and app organization
Messages (iMessage, SMS, and MMS)
Ringtones
Visual Voicemails
But not from a Mac. If you want to backup your photos and other important files I suggest you get an external hard drive and use it with Time Machine.
OT -
How can I get all photos from the camera roll, and all new pictures taken, to get on the photostream so they can share between iphone and ipad?
When turning PhotoStream on with photos available in the Camera Roll, only photos captured by the iPhone or saved on the iPhone are placed in the PhotoStream.
For all photos that were in the Camera Roll prior to turning PhotoStream on, import the photos with your computer and add the photos to your PhotoStream on your computer. -
HT1454 why i can not get video out from my ipod touch after i did the upgrade
why i can not get video out from my ipod touch after i did the upgrade
why i can not get video out from my ipod touch after i did the upgrade
Maybe you are looking for
-
How can I delete a phone line from my account
I have two lines that recently passed the 2-year contract date. I now live overseas and have no use for them, but I can't find a way to delete them online and I can't get any kind of live help via Live Chat or by Calling Verizon via Skype (which is
-
My library consists of both itunes purchases and uploads from my CD's. My ipod was formatted on my Mac. I'm out of state and want to sync the ipod on a windows PC. Can it be don? Can it be done without losing the uploaded songs?
-
Drop-down Menu to Open URL for File Download
I am using Adobe Captivate 5.5 and was wondering if it is possible to create a drop-down menu that can be used to open different URLs for file downloads, kind of like the Attachments button Presenter has. Captivate seems to have a dropdown widget ava
-
InDesign to PDF Export Shrinkage
Using InDesign CS2,when I export to PDF the document does not stay the same size, it always shrinks (about 5% or so). So, printing business cards on a template, for instance, doesnt work. Also, colors change to different shades (dark blue to medium b
-
Hi! I want to test supersedence on one computer and have a question, I have application10, it will be superseeded by application10.1, Can I deploy application 10.1 to my test collection that contains 1 computer, to see if it replaces application 10