From b9018d371429e6a9e23b32dcae3d24cb5b1b60f8 Mon Sep 17 00:00:00 2001 From: ToDou Date: Mon, 5 Sep 2016 17:38:58 +0800 Subject: [PATCH] add file black list --- .../loopeer/codereader/ui/fragment/CodeReadFragment.java | 8 +++++++- .../main/java/com/loopeer/codereader/utils/BrushMap.java | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/loopeer/codereader/ui/fragment/CodeReadFragment.java b/app/src/main/java/com/loopeer/codereader/ui/fragment/CodeReadFragment.java index cc09a75..270e588 100644 --- a/app/src/main/java/com/loopeer/codereader/ui/fragment/CodeReadFragment.java +++ b/app/src/main/java/com/loopeer/codereader/ui/fragment/CodeReadFragment.java @@ -189,7 +189,13 @@ public void call(Subscriber subscriber) { } final InputStream finalStream = stream; String[] names = mNode.name.split("\\."); - String jsFile = BrushMap.getJsFileForExtension(names[names.length - 1]); + String fileTypeName = names[names.length - 1]; + if (BrushMap.isBlackFile(fileTypeName)) { + subscriber.onError(new Throwable("Can not open this file!")); + subscriber.onCompleted(); + return; + } + String jsFile = BrushMap.getJsFileForExtension(fileTypeName); if (jsFile == null) { jsFile = "Txt"; } diff --git a/app/src/main/java/com/loopeer/codereader/utils/BrushMap.java b/app/src/main/java/com/loopeer/codereader/utils/BrushMap.java index 604f8fa..5359ca2 100644 --- a/app/src/main/java/com/loopeer/codereader/utils/BrushMap.java +++ b/app/src/main/java/com/loopeer/codereader/utils/BrushMap.java @@ -1,6 +1,7 @@ package com.loopeer.codereader.utils; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -20,6 +21,13 @@ public BrushMap() { } } + public static final String[] FILE_BLACKLIST = new String[]{"hprof", "apk", "jar"}; + + public static boolean isBlackFile(String name) { + if (name != null) return Arrays.asList(FILE_BLACKLIST).contains(name.toLowerCase()); + return false; + } + public static void init() { List list = new ArrayList(); list.add("actionscript3");