private void writeCompressedObject(Path cacheFile, Object obj) throws IOException { assert cacheDir != null; Files.createDirectories(cacheDir); try (StagedWrite stage = StagedWrite.begin(cacheFile)) { try (OutputStream out = stage.openOutputStream(); OutputStream gzOut = new GZIPOutputStream(out); ObjectOutputStream objOut = new ObjectOutputStream(gzOut)) { objOut.writeObject(obj); } // now we commit, after closing the output files stage.commit(); } }
/** * Begin a staged file writing operation. * @param target The file to write. * @return A staged file */ public static StagedWrite begin(Path target) { UUID key = UUID.randomUUID(); String stageName = ".tmp." + key + "." + target.getFileName().toString(); Path stage = target.resolveSibling(stageName); return new StagedWrite(target, stage); }
/** * Begin a staged file writing operation. * @param target The file to write. * @return A staged file */ public static StagedWrite begin(File target) { return begin(target.toPath()); }
/** * Begin a staged file writing operation. * @param target The file to write. * @return A staged file */ public static StagedWrite begin(File target) { return begin(target.toPath()); }
private void writeCompressedObject(Path cacheFile, Object obj) throws IOException { assert cacheDir != null; Files.createDirectories(cacheDir); try (StagedWrite stage = StagedWrite.begin(cacheFile)) { try (OutputStream out = stage.openOutputStream(); OutputStream gzOut = new GZIPOutputStream(out); ObjectOutputStream objOut = new ObjectOutputStream(gzOut)) { objOut.writeObject(obj); } // now we commit, after closing the output files stage.commit(); } }
/** * Begin a staged file writing operation. * @param target The file to write. * @return A staged file */ public static StagedWrite begin(Path target) { UUID key = UUID.randomUUID(); String stageName = ".tmp." + key + "." + target.getFileName().toString(); Path stage = target.resolveSibling(stageName); return new StagedWrite(target, stage); }