@Test public void testLoadSecretKey2() throws Exception { SecretKey secretKey = Encryption.generateNewKey(); File confDir = Files.createTempDir(); File secretKeyFile = new File(confDir, "secret"); byte[] encodedKey = secretKey.getEncoded(); Files.write(encodedKey, secretKeyFile); LazySecretKey lazySecretKey = new LazySecretKeyImpl(Arrays.asList(confDir)); assertThat(lazySecretKey.getExisting().getEncoded()).isEqualTo(encodedKey); secretKeyFile.delete(); confDir.delete(); }
@Override public @Nullable SecretKey getExisting() throws Exception { synchronized (lock) { if (secretKey == null) { File secretFile = getSecretFile(confDirs); if (secretFile != null) { secretKey = loadKey(secretFile); } } return secretKey; } }
LazySecretKeyImpl implements LazySecretKey { @Override public @Nullable SecretKey getExisting() throws Exception { synchronized (lock) { if (secretKey == null) { File secretFile = getSecretFile(confDirs); if (secretFile != null) { secretKey = loadKey(secretFile); } } return secretKey; } } }
LazySecretKeyImpl implements LazySecretKey { @Override public @Nullable SecretKey getExisting() throws Exception { synchronized (lock) { if (secretKey == null) { File secretFile = getSecretFile(confDirs); if (secretFile != null) { secretKey = loadKey(secretFile); } } return secretKey; } } LazySecretKeyImpl(List<File> confDirs); }
LazySecretKeyImpl implements LazySecretKey { @Override public @Nullable SecretKey getExisting() throws Exception { synchronized (lock) { if (secretKey == null) { File secretFile = getSecretFile(confDirs); if (secretFile != null) { secretKey = loadKey(secretFile); } } return secretKey; } } LazySecretKeyImpl(List<File> confDirs); @Override @Nullable SecretKey getExisting(); @Override SecretKey getOrCreate(); }
LazySecretKeyImpl implements LazySecretKey { @Override public @Nullable SecretKey getExisting() throws Exception { synchronized (lock) { if (secretKey == null) { File secretFile = getSecretFile(confDirs); if (secretFile != null) { secretKey = loadKey(secretFile); } } return secretKey; } } LazySecretKeyImpl(List<File> confDirs); @Override @Nullable SecretKey getExisting(); @Override SecretKey getOrCreate();  }