异常信息

load font error:{}
java.io.IOException: Problem reading font data.at java.awt.Font.createFont0(Font.java:1000)at java.awt.Font.createFont(Font.java:877)at com.anji.captcha.service.impl.ClickWordCaptchaServiceImpl.init(ClickWordCaptchaServiceImpl.java:49)at com.anji.captcha.service.impl.DefaultCaptchaServiceImpl.init(DefaultCaptchaServiceImpl.java:33)at com.anji.captcha.service.impl.CaptchaServiceFactory.getInstance(CaptchaServiceFactory.java:36)at com.gtb.common.config.CaptchaConfig.captchaService(CaptchaConfig.java:57)at com.gtb.common.config.CaptchaConfig$$EnhancerBySpringCGLIB$$17f42947.CGLIB$captchaService$0(<generated>)at com.gtb.common.config.CaptchaConfig$$EnhancerBySpringCGLIB$$17f42947$$FastClassBySpringCGLIB$$8f11612a.invoke(<generated>)

异常原因

由于该项目是从其他服务器上迁移过来的,迁移过程中没有对logs和temp目录进行打包。而 java.awt.Font.createFont0在加载自定义字体时需要创建临时文件,源码如下:

private static Font createFont0(int fontFormat, InputStream fontStream,CreatedFontTracker tracker)throws java.awt.FontFormatException, java.io.IOException {if (fontFormat != Font.TRUETYPE_FONT &&fontFormat != Font.TYPE1_FONT) {throw new IllegalArgumentException ("font format not recognized");}boolean copiedFontData = false;try {//加载字体时在这个位置开始创建临时文件,文件以+~JF开头,.tmp结尾final File tFile = AccessController.doPrivileged(new PrivilegedExceptionAction<File>() {public File run() throws IOException {return Files.createTempFile("+~JF", ".tmp").toFile();}});if (tracker != null) {tracker.add(tFile);}int totalSize = 0;try {final OutputStream outStream =AccessController.doPrivileged(new PrivilegedExceptionAction<OutputStream>() {public OutputStream run() throws IOException {return new FileOutputStream(tFile);}});if (tracker != null) {tracker.set(tFile, outStream);}try {byte[] buf = new byte[8192];for (;;) {int bytesRead = fontStream.read(buf);if (bytesRead < 0) {break;}if (tracker != null) {if (totalSize+bytesRead > CreatedFontTracker.MAX_FILE_SIZE) {throw new IOException("File too big.");}if (totalSize+tracker.getNumBytes() >CreatedFontTracker.MAX_TOTAL_BYTES){throw new IOException("Total files too big.");}totalSize += bytesRead;tracker.addBytes(bytesRead);}outStream.write(buf, 0, bytesRead);}/* don't close the input stream */} finally {outStream.close();}/* After all references to a Font2D are dropped, the file* will be removed. To support long-lived AppContexts,* we need to then decrement the byte count by the size* of the file.* If the data isn't a valid font, the implementation will* delete the tmp file and decrement the byte count* in the tracker object before returning from the* constructor, so we can set 'copiedFontData' to true here* without waiting for the results of that constructor.*/copiedFontData = true;Font font = new Font(tFile, fontFormat, true, tracker);return font;} finally {if (tracker != null) {tracker.remove(tFile);}if (!copiedFontData) {if (tracker != null) {tracker.subBytes(totalSize);}AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {public Void run() {tFile.delete();return null;}});}}} catch (Throwable t) {if (t instanceof FontFormatException) {throw (FontFormatException)t;}if (t instanceof IOException) {throw (IOException)t;}Throwable cause = t.getCause();if (cause instanceof FontFormatException) {throw (FontFormatException)cause;}throw new IOException("Problem reading font data.");}}

开始以为是字体库问题:运行命令

fc-list

yum install fontconfig

后并没有解决这个问题。然后不断的翻源码,怀疑是临时文件的问题。查看Tomcat下bin/catalina.sh 文件找到java 的JVM临时目录java.io.tmpdir的配置是CATALINA_TMPDIR=“$CATALINA_BASE”/temp
CATALINA_BASE指向的是Tomcat安装目录,由于是迁移过来的没有对temp目录做打包。在新建temp目录后启动正常

mkdir temp

在此记录一下这问题。

java加载自定义字体java.io.IOException: Problem reading font data.相关推荐

  1. java加载字体文件_Java的加载自定义字体文件(.TTF)

    我在下面这段代码中使用,并将其与该堆栈跟踪出现:Java的加载自定义字体文件(.TTF) java.io.FileNotFoundException: font.ttf (No such file o ...

  2. 前端加载自定义字体及速度优化

    今天是2.14情人节,也是另一个重要的日子,那就是我的第一个全栈项目上线啦~~~ www.daren.com 这个是公司的官网,采用Python+Django做后端,前端也用了gulp自动化工作流,使 ...

  3. html自定义字体缓存,PixiJS:加载自定义字体

    Environement: Xampp,Firefox,Pixijs,HTML,CSS 现在我尝试加载自定义字体. 我第一次加载我的Pixijs项目应运行的页面时,字体没有显示,控制台显示一些错误消息 ...

  4. Flutter 动态加载自定义字体

    Flutter中使用自定义字体 场景1, 加载特定字体,在开发前字体文件就已确定,可以使用 参考 flutter开发文档Use a custom font | Flutter,这里就不再描述. 场景2 ...

  5. Android加载自定义字体出错,Android设置自定义字体的解决方案

    找了很多解决方案,但是都会报错,只好边借鉴着前辈们的思路,边自己尝试改代码了QWQ 前面准备:要先把使用的字体文件放入到工具中 新建一个名叫assets的文件夹,然后把字体文件复制到里面,如图 成功放 ...

  6. 在 Umi 中打包与加载自定义字体

    使用 Webpack 打包字体文件的时候需要使用 file-loader 来处理打包文件,在 UmiJS 3 中可通过配置文件中的 chainWebpack 函数来自定义 Webpack 的配置. 首 ...

  7. java加载publickey,比较java中的PublicKey对象

    I have two PublicKey object.I want to compare both for equality or to check which is latest object u ...

  8. C# 从TTF文件加载自定义字体

    原文地址:http://www.cnblogs.com/twzy/p/4922962.html

  9. java类如何加载_简述Java类加载方式及流程

    在学习反射那一章节时想到自己之前学过的知识,故整理一番,希望能提供一点帮助,水平有限,如若有误欢迎指正. Java提供了两种类的装载方式.一是预先加载,二是按需加载.因为可以对类进行按需加载,所以程序 ...

最新文章

  1. 洛谷P2327 [SCOI2005] 扫雷
  2. 计算机组成原理:中央处理器
  3. Android——APK 在32bit/64bit平台 动态库问题
  4. CTFshow 反序列化 web269
  5. 让“学生看得明白” 复旦数学教授在无人教室录课程板书
  6. 选择排序(直接选择、堆)
  7. 今晚直播丨用高效的Oracle性能诊断工具,让运维工作轻松起来!
  8. python测试嵌入式_用Python测试嵌入式系统的测试框架
  9. Python3读取kafka消息写入HBASE
  10. PyCharm错误解决办法:ModuleNotFoundError: No module named 'matplotlib'
  11. 计算机毕业论文任务书模板,平面设计毕业论文任务书范文
  12. 扩展Redux——Store Enhancer
  13. 目标群体是什么意思_什么是目标客户群体?求解
  14. 【线性代数】A为方阵,当存在B使得 AB=E ,证明BA=E
  15. strictmath_Java StrictMath cbrt()方法与示例
  16. DIY 简单又好吃的香果魔芋
  17. 多臂赌博机问题代码实践
  18. npm和yarn清除缓存
  19. 【Router】PC连接到路由LAN,但是无法获取到IP地址问题分析及解决方案
  20. rman-20207

热门文章

  1. 对数线性模型(Logistic回归算法)
  2. Final Cut Pro x(FCPX)调色笔记
  3. 让你提前认识软件开发(51):VC++集成开发环境中Linux下Pclint工程的配置方法及常见错误修改
  4. go和python哪个好_Go和Python比较的话,哪个比较好?
  5. 回头客会员管理系统软件安装说明
  6. pages 元素(ASP.NET 设置架构)web.config 详解
  7. Vue 绑定Class增加容器的高度
  8. PUMA彪马用未成年人做代言人被罚10万元,已经是“二进宫”
  9. 3D建模行业工资待遇怎么样?游戏建模和影视建模哪个发展更好
  10. python 虾米停服了...用python爬取虾米最近播放的1000首歌