FileManager implements Serializable { public synchronized File createFile(Key key, InputStream stream) throws IOException { File file = resolve(key); if (!file.getParentFile().exists()) { ensureDirectoryExists(file.getParentFile()); } try (InputStream is = stream; OutputStream to = Files.newOutputStream(file.toPath())) { IOUtils.copy(is, to); } if (file.length() == 0) { file.delete(); file = null; } if (file != null && !file.exists()) { throw new IOException(String.format("Failed to create File '%s' for Key: %s", file.getName(), key)); } return file; } FileManager(final File baseDirectory); File getBaseDirectory(); synchronized File createFile(Key key, InputStream stream); synchronized File moveFile(File fromFile, Key to); synchronized void clear(); synchronized void remove(Key key); synchronized void clear(URI uri); synchronized void ensureDirectoryExists(File directory); synchronized File resolve(Key key); synchronized File resolve(URI uri);  }
@Test public void testResolveToFile() throws IOException { File file = fileManager.createFile(Key.create(URI.create("foo"), new Vary()), new NullInputStream(1)); assertNotNull("File was null", file); assertEquals(1, file.length()); }
@Test public void testResolveToEmptyFile() throws IOException { File file = fileManager.createFile(Key.create(URI.create("foo"), new Vary()), new NullInputStream(0)); assertNull("File was not null", file); }