/** @deprecated since 0.7.0; use same method in {@link Os} */ @Deprecated public static File mkdirs(File dir) { return Os.mkdirs(dir); }
/** writes given contents to a temporary file which will be deleted on exit, located under the given directory */ public static File writeToTempFile(InputStream is, File tempDir, String prefix, String suffix) { Preconditions.checkNotNull(is, "Input stream required to create temp file for %s*%s", prefix, suffix); mkdirs(tempDir); File tempFile = newTempFile(prefix, suffix); OutputStream out = null; try { out = new FileOutputStream(tempFile); ByteStreams.copy(is, out); } catch (IOException e) { throw Throwables.propagate(e); } finally { Streams.closeQuietly(is); Streams.closeQuietly(out); } return tempFile; }
@BeforeClass public void createTmpDirAndFiles() throws IOException { parentDir = Os.newTempDir(getClass().getSimpleName()); Os.deleteOnExitRecursively(parentDir); tmpDir = new File(parentDir, Identifiers.makeRandomId(4)); Os.mkdirs(tmpDir); Files.write("abcdef", new File(tmpDir, "data01.txt"), Charsets.US_ASCII); Files.write("123456", new File(tmpDir, "data02.txt"), Charsets.US_ASCII); Files.write("qqqqqq", new File(tmpDir, "data03.txt"), Charsets.US_ASCII); tmpDir2 = new File(parentDir, Identifiers.makeRandomId(4)); Os.mkdirs(tmpDir2); Files.write("zzzzzz", new File(tmpDir2, "data04.txt"), Charsets.US_ASCII); }
@Test public void testFailureRebindingBecauseDirectoryCorrupt() throws Exception { RebindFailureMode danglingRefFailureMode = RebindManager.RebindFailureMode.CONTINUE; RebindFailureMode rebindFailureMode = RebindManager.RebindFailureMode.FAIL_AT_END; origManagementContext.getRebindManager().stopPersistence(); if (mementoDir != null) RebindTestUtils.deleteMementoDir(mementoDir); File entitiesDir = Os.mkdirs(new File(mementoDir, "entities")); Files.write("invalid text", new File(entitiesDir, "mycorruptfile"), Charsets.UTF_8); LocalManagementContext newManagementContext = LocalManagementContextForTests.newInstance(); RecordingRebindExceptionHandler exceptionHandler = new RecordingRebindExceptionHandler(danglingRefFailureMode, rebindFailureMode); try { newApp = rebind(RebindOptions.create().newManagementContext(newManagementContext).exceptionHandler(exceptionHandler)); fail(); } catch (Exception e) { assertFailureRebindingError(e); } // exception handler should have been told about failure assertFalse(exceptionHandler.loadMementoFailures.isEmpty(), "exceptions="+exceptionHandler.loadMementoFailures); }
Os.mkdirs(new File(localCertsDir)); certPath = Os.mergePaths(localCertsDir, getId() + "-cert.pem"); getMachine().copyFrom("client-cert.pem", certPath);