From 09b4b8e582a0c2de0af550a1ceef95cee0a8e0d5 Mon Sep 17 00:00:00 2001 From: Anton Malinskiy Date: Sat, 11 Jun 2016 16:38:50 +0700 Subject: [PATCH] Fixed #4 NPE in Utils --- .../java/com/malinskiy/materialicons/Utils.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/android-material-icons/src/main/java/com/malinskiy/materialicons/Utils.java b/android-material-icons/src/main/java/com/malinskiy/materialicons/Utils.java index 14501a7..f88ab4e 100644 --- a/android-material-icons/src/main/java/com/malinskiy/materialicons/Utils.java +++ b/android-material-icons/src/main/java/com/malinskiy/materialicons/Utils.java @@ -4,16 +4,22 @@ import android.content.Context; import android.util.Log; -import java.io.*; +import java.io.BufferedOutputStream; +import java.io.Closeable; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; import static android.util.TypedValue.COMPLEX_UNIT_DIP; import static android.util.TypedValue.applyDimension; import static com.malinskiy.materialicons.Iconify.IconValue; +import static com.malinskiy.materialicons.Iconify.TAG; class Utils { public static final String ICON_FONT_FOLDER = "icon_tmp"; - public static final String NAME_PREFIX = "{zmdi"; + public static final String NAME_PREFIX = "{zmdi"; private Utils() { // Prevents instantiation @@ -49,6 +55,11 @@ static File resourceToFile(Context context, String resourceName) throws IOExcept InputStream inputStream = null; try { inputStream = Iconify.class.getClassLoader().getResourceAsStream(resourceName); + if (inputStream == null) { + Log.e(TAG, "Font loading failed, getResourceAsStream returned null"); + return null; + } + byte[] buffer = new byte[inputStream.available()]; bos = new BufferedOutputStream(new FileOutputStream(outPath)); int l = 0;