嗨 Stackoverflow 成员,
有一段时间我们切换了 GWT 应用程序,GWT 版本从 2.4 到 2.6。所以我们在那里也改成了新的超级开发模式。有了这个,我们需要安装一个本地码头服务器,并且不能使用内部的 eclipse ?jetty? 了。在服务器端,我们使用 sun 本身的 ImageIO 包写入和保存图像。直到上周,这还没有问题,但是我们检查了我们的应用程序不再能够像在我们的部署服务器上那样从 bytearrayinputstream 读取。为了实现可靠的开发,我们需要能够在本地平台上进行编码和测试。问题是,ImageIO.read 静态函数不再起作用,但它不仅不再起作用,它退出代码而不抛出异常!我现在将向您展示代码部分:
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);
我只得到以下输出:
read1...
read2...java.io.ByteArrayInputStream@15bea4b
但不是:
System.out.println("read2.5...");
System.out.println("read2.6...");
System.out.println("read3...");
System.out.println("read4...");
nor
System.out.println("read4.5...");
如您所见,我可以将字节流的文件写入文件系统,但无法使用 ImageIO.read 将字节流读取到图像中。我不知道为什么。字节流在那里,有一个大小并将其写入磁盘也是正确的,但是如果我使用 ImageIO.read 服务器以某种方式退出代码,没有任何异常..有人知道,这里出了问题吗?谢谢你。
问候, 马克斯
编辑附加的堆栈跟踪
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)