From aa56cc23c0de360a44b71b1252f30d026eff7298 Mon Sep 17 00:00:00 2001 From: LoveIsGrief Date: Sat, 25 Jan 2020 15:20:38 +0100 Subject: [PATCH] Cache base 64 path hash Can't do it in constructor without an ugly try/catch therefore this is done on demand --- core/src/main/java/com/muwire/core/SharedFile.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/muwire/core/SharedFile.java b/core/src/main/java/com/muwire/core/SharedFile.java index c79ef9d5..5f238960 100644 --- a/core/src/main/java/com/muwire/core/SharedFile.java +++ b/core/src/main/java/com/muwire/core/SharedFile.java @@ -23,7 +23,8 @@ public class SharedFile { private final String cachedPath; private final long cachedLength; - + + private String b64PathHash; private final String b64EncodedFileName; private final String b64EncodedHashRoot; private final List b64EncodedHashList; @@ -40,7 +41,7 @@ public class SharedFile { this.cachedLength = file.length(); this.b64EncodedFileName = Base64.encode(DataUtil.encodei18nString(file.toString())); this.b64EncodedHashRoot = Base64.encode(infoHash.getRoot()); - + List b64List = new ArrayList(); byte[] tmp = new byte[32]; for (int i = 0; i < infoHash.getHashList().length / 32; i++) { @@ -61,7 +62,10 @@ public class SharedFile { } public String getB64PathHash() throws NoSuchAlgorithmException { - return Base64.encode(getPathHash()); + if(b64PathHash == null){ + b64PathHash = Base64.encode(getPathHash()); + } + return b64PathHash; } public InfoHash getInfoHash() {