List of usage examples for com.google.common.io Files write
public static void write(CharSequence from, File to, Charset charset) throws IOException
From source file:kungfu.concurrency.threaddump.ThreadUtil.java
public static String writeThreadDump(String prefix) throws IOException { DateFormat dateFormat = new SimpleDateFormat("YYYYMMDDHH24MMSS"); Joiner joiner = Joiner.on(CharPool.UNDERSCORE); Date now = new Date(); File dumpFile = File.createTempFile(joiner.join(prefix, "thread_dump", dateFormat.format(now)), null); String threadDump = threadDump(); Files.write(threadDump, dumpFile, Charset.defaultCharset()); return dumpFile.getAbsolutePath(); }
From source file:org.locationtech.geogig.api.plumbing.merge.SaveMergeCommitMessageOp.java
@Override protected Void _call() { URL envHome = new ResolveGeogigDir(platform()).call().get(); try {/*from w w w. j a v a2 s . c om*/ File file = new File(envHome.toURI()); file = new File(file, "MERGE_MSG"); Files.write(message, file, Charsets.UTF_8); } catch (Exception e) { throw Throwables.propagate(e); } return null; }
From source file:org.geogit.api.plumbing.merge.SaveMergeCommitMessageOp.java
@Override public Void call() { URL envHome = new ResolveGeogitDir(platform).call(); try {/*from www. j a v a2 s . c o m*/ File file = new File(envHome.toURI()); file = new File(file, "MERGE_MSG"); Files.write(message, file, Charsets.UTF_8); } catch (Exception e) { throw Throwables.propagate(e); } return null; }
From source file:com.android.builder.internal.aapt.AaptTestUtils.java
/** * Obtains a text file for testing.// w ww.j a v a 2 s . com * * @param temporaryFolder the temporary folder where temporary files should be placed * @return a test file in a {@code raw} folder */ @NonNull public static File getTestTxt(@NonNull TemporaryFolder temporaryFolder) throws Exception { File raw = new File(temporaryFolder.getRoot(), "raw"); FileUtils.mkdirs(raw); File txt = new File(raw, "abc.txt"); Files.write("text.txt", txt, Charsets.US_ASCII); return txt; }
From source file:org.jetbrains.kotlin.checkers.KotlinMultiFileTestWithWithJava.java
protected static boolean writeSourceFile(@NotNull String fileName, @NotNull String content, @NotNull File targetDir) { try {//from w w w . jav a 2 s.c o m File sourceFile = new File(targetDir, fileName); KotlinTestUtils.mkdirs(sourceFile.getParentFile()); Files.write(content, sourceFile, Charset.forName("utf-8")); return true; } catch (Exception e) { throw ExceptionUtilsKt.rethrow(e); } }
From source file:org.glowroot.testing.Util.java
static void updateLibVersion(String modulePath, String property, String version) throws IOException { File pomFile = new File(BASE_DIR + "/" + modulePath + "/pom.xml"); String pom = Files.toString(pomFile, UTF_8); pom = pom.replaceAll("<" + property + ">.*", "<" + property + ">" + version + "</" + property + ">"); Files.write(pom, pomFile, UTF_8); System.out.println(property + " : " + version); report.println(property + " : " + version); }
From source file:info.servertools.core.util.SaveThread.java
@Override public void run() { if (file != null) { try {/*from w w w . j a v a 2 s.c o m*/ Files.write(data, file, Reference.CHARSET); } catch (IOException e) { log.warn("Failed to save file to disk", e); } } }
From source file:com.facebook.presto.raptor.backup.AbstractTestBackupStore.java
@Test public void testBackupStore() throws Exception { // backup first file File file1 = new File(temporary, "file1"); Files.write("hello world", file1, UTF_8); UUID uuid1 = randomUUID();/*from w ww . j a va 2s . c o m*/ assertFalse(store.shardExists(uuid1)); store.backupShard(uuid1, file1); assertTrue(store.shardExists(uuid1)); // backup second file File file2 = new File(temporary, "file2"); Files.write("bye bye", file2, UTF_8); UUID uuid2 = randomUUID(); assertFalse(store.shardExists(uuid2)); store.backupShard(uuid2, file2); assertTrue(store.shardExists(uuid2)); // verify first file File restore1 = new File(temporary, "restore1"); store.restoreShard(uuid1, restore1); assertEquals(readAllBytes(file1.toPath()), readAllBytes(restore1.toPath())); // verify second file File restore2 = new File(temporary, "restore2"); store.restoreShard(uuid2, restore2); assertEquals(readAllBytes(file2.toPath()), readAllBytes(restore2.toPath())); // verify random UUID does not exist assertFalse(store.shardExists(randomUUID())); // delete first file assertTrue(store.shardExists(uuid1)); assertTrue(store.shardExists(uuid2)); store.deleteShard(uuid1); store.deleteShard(uuid1); assertFalse(store.shardExists(uuid1)); assertTrue(store.shardExists(uuid2)); // delete random UUID store.deleteShard(randomUUID()); }
From source file:org.geogit.osm.internal.log.WriteOSMFilterFile.java
@Override public Void call() { Preconditions.checkNotNull(entry);/*from w w w. j a v a2 s . com*/ Preconditions.checkNotNull(filter); URL url = command(ResolveOSMLogfile.class).call(); File logfile = new File(url.getFile()); File file = new File(logfile.getParentFile(), "filter" + entry.getId().toString()); try { Files.write(filter, file, Charsets.UTF_8); } catch (IOException e) { throw Throwables.propagate(e); } return null; }
From source file:de.ks.text.PersistentStoreBack.java
public synchronized void save(String text) { File file = new File(targetDirectory, id); if (file.exists()) { file.delete();//from ww w. ja v a 2 s .co m } try { Files.createParentDirs(file); Files.write(text, file, Charsets.UTF_8); } catch (IOException e) { log.error("Could not write storeback to {}", file, e); } }