@Test public void testLoadSecretKey() throws Exception { SecretKey secretKey = Encryption.generateNewKey(); File secretKeyFile = File.createTempFile("glowroot-unit-test-", ""); byte[] encodedKey = secretKey.getEncoded(); Files.write(encodedKey, secretKeyFile); LazySecretKey lazySecretKey = new LazySecretKeyImpl(secretKeyFile); assertThat(lazySecretKey.getOrCreate().getEncoded()).isEqualTo(encodedKey); secretKeyFile.delete(); }
@Override public SecretKey getOrCreate() throws Exception { synchronized (secretFile) { if (secretKey == null) { if (secretFile.exists()) { secretKey = loadKey(secretFile); } else { secretKey = Encryption.generateNewKey(); Files.write(secretKey.getEncoded(), secretFile); } } return secretKey; } }
LazySecretKeyImpl implements LazySecretKey { @Override public SecretKey getOrCreate() throws Exception { synchronized (secretFile) { if (secretKey == null) { if (secretFile.exists()) { secretKey = loadKey(secretFile); } else { secretKey = Encryption.generateNewKey(); Files.write(secretKey.getEncoded(), secretFile); } } return secretKey; } } }
LazySecretKeyImpl implements LazySecretKey { @Override public SecretKey getOrCreate() throws Exception { synchronized (secretFile) { if (secretKey == null) { if (secretFile.exists()) { secretKey = loadKey(secretFile); } else { secretKey = Encryption.generateNewKey(); Files.write(secretKey.getEncoded(), secretFile); } } return secretKey; } } LazySecretKeyImpl(File secretFile); }
LazySecretKeyImpl implements LazySecretKey { @Override public SecretKey getOrCreate() throws Exception { synchronized (secretFile) { if (secretKey == null) { if (secretFile.exists()) { secretKey = loadKey(secretFile); } else { secretKey = Encryption.generateNewKey(); Files.write(secretKey.getEncoded(), secretFile); } } return secretKey; } } LazySecretKeyImpl(File secretFile); @Override @Nullable SecretKey getExisting(); @Override SecretKey getOrCreate(); }
LazySecretKeyImpl implements LazySecretKey { @Override public SecretKey getOrCreate() throws Exception { synchronized (secretFile) { if (secretKey == null) { if (secretFile.exists()) { secretKey = loadKey(secretFile); } else { secretKey = Encryption.generateNewKey(); Files.write(secretKey.getEncoded(), secretFile); } } return secretKey; } } LazySecretKeyImpl(File secretFile); @Override @Nullable SecretKey getExisting(); @Override SecretKey getOrCreate();  }