diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-09-09 16:48:49 +0200 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-09-14 17:29:40 +0200 |
commit | 069f75fe8558dbea2c7194465f84c5b025bdd672 (patch) | |
tree | f6a6e1b293276a9f04836e3bf539190798f17d04 /sonar-home | |
parent | 29d4206d4d69d5c36e8153bf1f0f52d47418799c (diff) | |
download | sonarqube-069f75fe8558dbea2c7194465f84c5b025bdd672.tar.gz sonarqube-069f75fe8558dbea2c7194465f84c5b025bdd672.zip |
improve batch logging and performance
Diffstat (limited to 'sonar-home')
-rw-r--r-- | sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java b/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java index 2b32c65b7f9..3122d9a6fd0 100644 --- a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java +++ b/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java @@ -44,7 +44,7 @@ import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; import static java.nio.file.StandardOpenOption.WRITE; public class PersistentCache { - + private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); private static final Charset ENCODING = StandardCharsets.UTF_8; private static final String DIGEST_ALGO = "MD5"; private static final String LOCK_FNAME = ".lock"; @@ -133,7 +133,7 @@ public class PersistentCache { return null; } - + public synchronized void put(@Nonnull String obj, @Nonnull InputStream stream) throws IOException { String key = getKey(obj); try { @@ -293,10 +293,10 @@ public class PersistentCache { Path cachePath = getCacheEntryPath(key); Files.write(cachePath, value, CREATE, WRITE, TRUNCATE_EXISTING); } - + private void putCache(String key, InputStream stream) throws IOException { Path cachePath = getCacheEntryPath(key); - Files.copy(stream, cachePath, StandardCopyOption.REPLACE_EXISTING); + Files.copy(stream, cachePath, StandardCopyOption.REPLACE_EXISTING); } private byte[] getCache(String key) throws IOException { @@ -377,11 +377,13 @@ public class PersistentCache { return baseDir.resolve(key); } - private static String byteArrayToHex(byte[] a) { - StringBuilder sb = new StringBuilder(a.length * 2); - for (byte b : a) { - sb.append(String.format("%02x", b & 0xff)); + public static String byteArrayToHex(byte[] bytes) { + char[] hexChars = new char[bytes.length * 2]; + for (int j = 0; j < bytes.length; j++) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; } - return sb.toString(); + return new String(hexChars); } } |