createFile function throws IOException.

This commit is contained in:
吴尚昆 2022-03-03 16:58:58 +08:00 committed by osborn
parent 37a4332a19
commit b75e42dac3

View File

@ -267,11 +267,9 @@ public class TextNode extends ViewNode<TextView> {
try { try {
String filePath; String filePath;
filePath = getContext().getCacheDir().getPath() + File.separator + "DoricTextFonts"; filePath = getContext().getCacheDir().getPath() + File.separator + "DoricTextFonts";
String fileName = URLEncoder.encode(type + identifier, "UTF-8"); String fileName = URLEncoder.encode(type + "_" + identifier, "UTF-8");
if (TextUtils.isEmpty(fileName)) { if (TextUtils.isEmpty(fileName)) {
fileName = (identifier == null) ? "tempFont.ttf" : identifier; fileName = (identifier == null) ? "tempFont.ttf" : identifier;
} else {
fileName = fileName + ".ttf";
} }
File file = createFile(fontData, filePath, fileName); File file = createFile(fontData, filePath, fileName);
if (file == null) { if (file == null) {
@ -461,8 +459,8 @@ public class TextNode extends ViewNode<TextView> {
private static File createFile(byte[] bfile, String filePath,String fileName) throws IOException { private static File createFile(byte[] bfile, String filePath,String fileName) throws IOException {
BufferedOutputStream bos = null; BufferedOutputStream bos = null;
FileOutputStream fos = null; FileOutputStream fos = null;
File file = null;
try { try {
File file = null;
File dir = new File(filePath); File dir = new File(filePath);
if(!dir.exists()){ if(!dir.exists()){
dir.mkdirs(); dir.mkdirs();
@ -475,6 +473,7 @@ public class TextNode extends ViewNode<TextView> {
fos = new FileOutputStream(file); fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos); bos = new BufferedOutputStream(fos);
bos.write(bfile); bos.write(bfile);
return file;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
@ -494,7 +493,6 @@ public class TextNode extends ViewNode<TextView> {
} }
} }
} }
return file;
} }
@Override @Override