图片生成失败, Can't create output stream!
2017-07-19 11:04
537 查看
遇到一个奇葩问题,分析报告的图片在测试环境上不显示,但在alicloud和本机上是正常的。
分析了下, 首先将 ChartUtilities.writeChartAsPNG()改为ChartUtilities.writeChartAsJEPG();把图片格式改为jepg,发现图片还是显示不了。
连上远程桌面,发现生成图片的时候后台报错: Can't
create output stream。
查找发现也有人遇到同样的问题,看完文档http://feitianbenyue.iteye.com/blog/1743281。
终于找到原因,生成图片的时候要用到io流,会读取变量java.io.tmpdir!如果没有自定义路径,默认读取路径是tomcat下的temp文件夹。
当temp文件夹不存在时,就会出现”Can't
create output stream”。图片生成失败,自然就无法正常显示。
以下是文档中附上的源码。
private static boolean hasCachePermission() {
Boolean hasPermission = getCacheInfo().getHasPermission();
if (hasPermission != null) {
return hasPermission.booleanValue();
} else {
try {
SecurityManager security = System.getSecurityManager();
if (security != null) {
File cachedir = getCacheDirectory();
String cachepath;
if (cachedir != null) {
cachepath = cachedir.getPath();
} else {
cachepath = getTempDir();
if (cachepath == null) {
getCacheInfo().setHasPermission(Boolean.FALSE);
return false;
}
}
security.checkWrite(cachepath);
}
} catch (SecurityException e) {
getCacheInfo().setHasPermission(Boolean.FALSE);
return false;
}
getCacheInfo().setHasPermission(Boolean.TRUE);
return true;
}
}
/**
* Returns the default temporary (cache) directory as defined by the
* java.io.tmpdir system property.
*/
private static String getTempDir() {
GetPropertyAction a = new GetPropertyAction("java.io.tmpdir");
return (String)AccessController.doPrivileged(a);
}
tomcat 启动的时候显示
Using CATALINA_BASE: /home/appuser/appservers/tomcat-feilong
Using CATALINA_HOME: /home/appuser/appservers/tomcat-feilong
Using CATALINA_TMPDIR: /home/appuser/appservers/tomcat-feilong/temp
Using JRE_HOME: /usr/lib/jvm/java-6-sun
Using CLASSPATH: /home/appuser/appservers/tomcat-feilong/bin/bootstrap.jar
分析了下, 首先将 ChartUtilities.writeChartAsPNG()改为ChartUtilities.writeChartAsJEPG();把图片格式改为jepg,发现图片还是显示不了。
连上远程桌面,发现生成图片的时候后台报错: Can't
create output stream。
查找发现也有人遇到同样的问题,看完文档http://feitianbenyue.iteye.com/blog/1743281。
终于找到原因,生成图片的时候要用到io流,会读取变量java.io.tmpdir!如果没有自定义路径,默认读取路径是tomcat下的temp文件夹。
当temp文件夹不存在时,就会出现”Can't
create output stream”。图片生成失败,自然就无法正常显示。
以下是文档中附上的源码。
private static boolean hasCachePermission() {
Boolean hasPermission = getCacheInfo().getHasPermission();
if (hasPermission != null) {
return hasPermission.booleanValue();
} else {
try {
SecurityManager security = System.getSecurityManager();
if (security != null) {
File cachedir = getCacheDirectory();
String cachepath;
if (cachedir != null) {
cachepath = cachedir.getPath();
} else {
cachepath = getTempDir();
if (cachepath == null) {
getCacheInfo().setHasPermission(Boolean.FALSE);
return false;
}
}
security.checkWrite(cachepath);
}
} catch (SecurityException e) {
getCacheInfo().setHasPermission(Boolean.FALSE);
return false;
}
getCacheInfo().setHasPermission(Boolean.TRUE);
return true;
}
}
/**
* Returns the default temporary (cache) directory as defined by the
* java.io.tmpdir system property.
*/
private static String getTempDir() {
GetPropertyAction a = new GetPropertyAction("java.io.tmpdir");
return (String)AccessController.doPrivileged(a);
}
tomcat 启动的时候显示
Using CATALINA_BASE: /home/appuser/appservers/tomcat-feilong
Using CATALINA_HOME: /home/appuser/appservers/tomcat-feilong
Using CATALINA_TMPDIR: /home/appuser/appservers/tomcat-feilong/temp
Using JRE_HOME: /usr/lib/jvm/java-6-sun
Using CLASSPATH: /home/appuser/appservers/tomcat-feilong/bin/bootstrap.jar
相关文章推荐
- javax.imageio.IIOException: Can't create output stream!tomcat 验证码,图片(原理)
- 使用javax.imageio.ImageIO生成验证码时报错javax.imageio.IIOException: Can't create output stream!
- javax.imageio.IIOException: Can't create output stream!tomcat 验证码,图片(原理)
- 获取验证码 HTTP Status 500 - Can't create output stream!解决方案
- JSP彩色验证码,javax.imageio.IIOException: Can't create output stream! 解决方法
- javax.imageio.IIOException: Can't create output stream解决方法
- javax.imageio.IIOException: Can't create output stream解决方法
- javax异常: javax.imageio.IIOException: Can't create output stream解决方法
- MYSQL建立外键失败几种情况记录Can't create table不能创建表
- 大图片生成缩略图 导致imagecreatefromjpeg 内存崩溃问题
- CI 生成随机图片失败的原因
- 利用gd库,生成一个图片 imagecreatetruecolor
- 【翻译自mos文章】当/var/tmp文件夹被remove掉之后,GI crash,并启动失败,原因是ohasd can not create named pipe
- 解决:Tomcat不能加载图片问题.javax.imageio.IIOException: Can't create cache file!
- 【翻译自mos文章】当/var/tmp目录被remove掉之后,GI crash,并启动失败,原因是ohasd can not create named pipe
- Android开发之使用createFromStream加载图片发现图片变小
- navicat 创建查询失败 can not create file
- 利用letsencrypte生成证书时,create virtual environment失败
- 图片上传根据stream生成image
- MYSQL建立外键失败几种情况记录Can’t create table...