0

Hi Stackoverflow members,

for some time we switched in out GWT application, the GWT version from 2.4 to 2.6. So we also changed to the new super dev mode there. With this we needed to install an local jetty server and could not use the internal eclipse ?jetty? anymore. On the server side we are writing and saving images with the ImageIO package from sun itself. Till last week, there were no problems with this, but then we checked that our app is not anymore able to read from bytearrayinputstream in the case as it does on our deployment servers. For reliable development we need the possibility to code and test on a local platform. The problem is, that ImageIO.read static function does not work anymore, but it does not only don't work anymore, it exits the code WITHOUT to throw an exception! I will now show you the code part:

System.out.println("createImage..."+file+", "+response+", fib"+fileInBytes+" fibs:"+fileInBytes.length);
ETFile f = file;
boolean isImage = false;
BufferedImage image = null;

try {
    System.out.println("read1...");
    ByteArrayInputStream bais = new ByteArrayInputStream(fileInBytes);
    System.out.println("read2..."+bais);
    image = ImageIO.read(bais);

    //ByteArrayOutputStream baos = new ByteArrayOutputStream();
    //baos.write(fileInBytes);
    //saveStreamToFile(filename+"_bla.jpg", baos, data);
    //baos.close();

    bais.close();
    System.out.println("read2.5...");

    if (image != null) {
         System.out.println("read2.6...");
         isImage = true;
    }

    System.out.println("read3...");
} catch (/*IO*/Exception e) {
    System.out.println("read4...");
    System.out.println(e.getLocalizedMessage());
    e.printStackTrace();
} finally {
    System.out.println("read4.5...");
}

System.out.println("isimage:"+isImage);

I'm getting only the following output:

read1...
read2...java.io.ByteArrayInputStream@15bea4b

But no:

System.out.println("read2.5...");
System.out.println("read2.6...");
System.out.println("read3...");
System.out.println("read4...");
nor
System.out.println("read4.5...");

As you see, i can write the bytestream s file to filesystem, but can't read that bytestream with ImageIO.read to an image. And I don't know why. The bytestream is there, has a size and writing it to disk is also correct, but if I use ImageIO.read the server somehow exits the code without any exception.. Do someone know, was is going wrong here? Thank you.

Regards, Max

edit attached stack trace

thread:1323900765@qtp-433064372-0:java.lang.ClassLoader$NativeLibrary.load(Native Method)
thread:1323900765@qtp-433064372-0:java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1833)
thread:1323900765@qtp-433064372-0:java.lang.ClassLoader.loadLibrary(ClassLoader.java:1730)
thread:1323900765@qtp-433064372-0:java.lang.Runtime.loadLibrary0(Runtime.java:823)
thread:1323900765@qtp-433064372-0:java.lang.System.loadLibrary(System.java:1044)
thread:1323900765@qtp-433064372-0:sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50)
thread:1323900765@qtp-433064372-0:java.security.AccessController.doPrivileged(Native Method)
thread:1323900765@qtp-433064372-0:java.awt.Toolkit.loadLibraries(Toolkit.java:1605)
thread:1323900765@qtp-433064372-0:java.awt.Toolkit.<clinit>(Toolkit.java:1627)
thread:1323900765@qtp-433064372-0:sun.awt.AppContext$2.run(AppContext.java:240)
thread:1323900765@qtp-433064372-0:sun.awt.AppContext$2.run(AppContext.java:226)
thread:1323900765@qtp-433064372-0:java.security.AccessController.doPrivileged(Native Method)
thread:1323900765@qtp-433064372-0:sun.awt.AppContext.initMainAppContext(AppContext.java:226)
thread:1323900765@qtp-433064372-0:sun.awt.AppContext.access$200(AppContext.java:112)
thread:1323900765@qtp-433064372-0:sun.awt.AppContext$3.run(AppContext.java:306)
thread:1323900765@qtp-433064372-0:java.security.AccessController.doPrivileged(Native Method)
thread:1323900765@qtp-433064372-0:sun.awt.AppContext.getAppContext(AppContext.java:287)
thread:1323900765@qtp-433064372-0:javax.imageio.spi.IIORegistry.getDefaultInstance(IIORegistry.java:137)
thread:1323900765@qtp-433064372-0:javax.imageio.ImageIO.<clinit>(ImageIO.java:48)
thread:1323900765@qtp-433064372-0:com.et.eb.server.servlets.ETFileUploadServlet.createImage(ETFileUploadServlet.java:441)
thread:1323900765@qtp-433064372-0:com.et.eb.server.servlets.ETFileUploadServlet.writeImage(ETFileUploadServlet.java:285)
thread:1323900765@qtp-433064372-0:com.et.eb.server.servlets.ETFileUploadServlet.readFormData(ETFileUploadServlet.java:364)
thread:1323900765@qtp-433064372-0:com.et.eb.server.servlets.ETFileUploadServlet.doPost(ETFileUploadServlet.java:122)
thread:1323900765@qtp-433064372-0:javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
thread:1323900765@qtp-433064372-0:javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
thread:1323900765@qtp-433064372-0:org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
thread:1323900765@qtp-433064372-0:org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401)
thread:1323900765@qtp-433064372-0:org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
thread:1323900765@qtp-433064372-0:org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
thread:1323900765@qtp-433064372-0:org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
thread:1323900765@qtp-433064372-0:org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
thread:1323900765@qtp-433064372-0:org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
thread:1323900765@qtp-433064372-0:org.mortbay.jetty.Server.handle(Server.java:326)
thread:1323900765@qtp-433064372-0:org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
thread:1323900765@qtp-433064372-0:org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:945)
thread:1323900765@qtp-433064372-0:org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
thread:1323900765@qtp-433064372-0:org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
thread:1323900765@qtp-433064372-0:org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
thread:1323900765@qtp-433064372-0:org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
thread:1323900765@qtp-433064372-0:org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
The Guy with The Hat
  • 10,836
  • 8
  • 57
  • 75
  • 1
    `ImageIO.read` is defined to return `null` if it does not recognize the image file format. Are you sure the file is a valid image? – greg-449 Apr 30 '14 at 11:02
  • I'm doing nothing with the `image` variable before the `System.out.println("read2.5...");` code line, but I don't even come to that line... the code is leaved and also the exception printout is not displayed somehow – user3446699 Apr 30 '14 at 11:18
  • I think @greg-449 is onto the cause. Most probably, when you run Jetty from within Eclipse, you pick up some extra ImageIO plugins, that are not installed/available in your local Jetty instance. What format is the images you are trying to read? – Harald K Apr 30 '14 at 11:48
  • PS: Are you sure "read2.5...", "read3..." and "read4.5..." isn't printed? In that case, it looks more like your program hangs in `ImageIO.read()`... You can verify this by creating a stack dump. – Harald K Apr 30 '14 at 11:54
  • ok, I think you are right with the hangin in `ImageIO.read`. How you would create an stack dump when `ImageIO.read` is never leaved? The format the bytearray was generated from was jpeg format. – user3446699 Apr 30 '14 at 14:09
  • @user3446699: Either use a debugger attached to the process, or send a signal to the running process (platform dependent). – Harald K Apr 30 '14 at 14:45
  • ***edit: attached stacktrace (thorugh timed exception though all available threads) – user3446699 May 02 '14 at 17:21
  • does someone see something suspicious in the attached stack trace? – user3446699 May 05 '14 at 07:19
  • ok, found the error with luck in one case I wanted to create the BufferedImage from an external shell script... when I instantiated the BufferedImage and to set then the pixel data with setRGB. I saw that the code hangs then again, but now on instantiating, for which I give a google search try and then I found the answer on: https://groups.google.com/forum/#!topic/comp.lang.java.programmer/awg1D-VjsFc which has been: I had to add '-Djava.awt.headless=true' as in eclipse Jettys VM arguments list... nice try, son ;) – user3446699 May 05 '14 at 15:15
  • If you have found the answer to this question, please add it as an answer. Don't edit your question to include the answer. [Answering you own question](http://meta.stackoverflow.com/help/self-answer) is highly encouraged! – The Guy with The Hat May 05 '14 at 15:26

0 Answers0