/** * Writes a character sequence (such as a string) to a file using the given character set. * * @param from the character sequence to write * @param to the destination file * @param charset the charset used to encode the output stream; see {@link StandardCharsets} for * helpful predefined constants * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSink(to, charset).write(from)}. This method is scheduled to be * removed in January 2019. */ @Deprecated public static void write(CharSequence from, File to, Charset charset) throws IOException { asCharSink(to, charset).write(from); }
/** * Appends a character sequence (such as a string) to a file using the given character set. * * @param from the character sequence to append * @param to the destination file * @param charset the charset used to encode the output stream; see {@link StandardCharsets} for * helpful predefined constants * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSink(to, charset, FileWriteMode.APPEND).write(from)}. This * method is scheduled to be removed in January 2019. */ @Deprecated public static void append(CharSequence from, File to, Charset charset) throws IOException { asCharSink(to, charset, FileWriteMode.APPEND).write(from); }
/** * Appends a character sequence (such as a string) to a file using the given character set. * * @param from the character sequence to append * @param to the destination file * @param charset the charset used to encode the output stream; see {@link StandardCharsets} for * helpful predefined constants * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSink(to, charset, FileWriteMode.APPEND).write(from)}. This * method is scheduled to be removed in January 2019. */ @Deprecated public static void append(CharSequence from, File to, Charset charset) throws IOException { asCharSink(to, charset, FileWriteMode.APPEND).write(from); }
/** * Writes a character sequence (such as a string) to a file using the given character set. * * @param from the character sequence to write * @param to the destination file * @param charset the charset used to encode the output stream; see {@link StandardCharsets} for * helpful predefined constants * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSink(to, charset).write(from)}. This method is scheduled to be * removed in January 2019. */ @Deprecated public static void write(CharSequence from, File to, Charset charset) throws IOException { asCharSink(to, charset).write(from); }
@Implementation protected static void stopMethodTracing() { if (!tracingStarted) { throw new RuntimeException("Tracing is not started."); } try { Files.asCharSink(new File(tracingFilename), Charset.forName("UTF-8")).write("trace data"); } catch (IOException e) { throw new RuntimeException("Writing trace file failed", e); } tracingStarted = false; tracingFilename = null; }
/** * Appends a character sequence (such as a string) to a file using the given character set. * * @param from the character sequence to append * @param to the destination file * @param charset the charset used to encode the output stream; see {@link StandardCharsets} for * helpful predefined constants * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSink(to, charset, FileWriteMode.APPEND).write(from)}. This * method is scheduled to be removed in January 2019. */ @Deprecated public static void append(CharSequence from, File to, Charset charset) throws IOException { asCharSink(to, charset, FileWriteMode.APPEND).write(from); }
/** * Writes a character sequence (such as a string) to a file using the given character set. * * @param from the character sequence to write * @param to the destination file * @param charset the charset used to encode the output stream; see {@link StandardCharsets} for * helpful predefined constants * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSink(to, charset).write(from)}. This method is scheduled to be * removed in January 2019. */ @Deprecated public static void write(CharSequence from, File to, Charset charset) throws IOException { asCharSink(to, charset).write(from); }
@Override public CharSink createSink() throws IOException { File file = createFile(); if (initialString != null) { Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8); try { writer.write(initialString); } finally { writer.close(); } return Files.asCharSink(file, Charsets.UTF_8, FileWriteMode.APPEND); } return Files.asCharSink(file, Charsets.UTF_8); }
public static void main(String[] args) throws Exception { if (args.length != 2) { System.out.println("Usage: frameworkJarBuilder <framework resource path (e.g. android-25)> <output jar path>"); System.exit(-1); } String resPath = FRAMEWORK_ROOT + "/" + args[0]; System.out.println("Building framework cache from " + resPath); String cache = buildFrameworkCache(resPath); String cacheFileName = "src/main/resources/framework_classes.cfg"; Files.asCharSink(new File(cacheFileName), Charset.forName("UTF-8")).write(cache); System.out.println("Saved cache to " + cacheFileName + " (" + cache.getBytes().length + " bytes)"); String outPath = args[1]; System.out.println("Building framework JAR"); ClassManager classManager = new ClassManagerFactory().build(); ClassBuilder builder = new ClassBuilder(classManager); Set<String> classNames = buildJar(classManager, builder, outPath); System.out.println("Saved " + classNames.size() + " classes to " + outPath); }
private static File createAvroSchemaFile() throws Exception { File schemaFile = File.createTempFile("avro_single_column-", ".avsc"); String schema = "{\n" + " \"namespace\": \"com.facebook.test\",\n" + " \"name\": \"single_column\",\n" + " \"type\": \"record\",\n" + " \"fields\": [\n" + " { \"name\":\"string_col\", \"type\":\"string\" }\n" + "]}"; asCharSink(schemaFile, UTF_8).write(schema); return schemaFile; }
private AndroidManifest newConfigWith(String fileName, String usesSdkAttrs) throws IOException { String contents = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + " package=\"org.robolectric\">\n" + " <uses-sdk " + usesSdkAttrs + "/>\n" + "</manifest>\n"; File f = temporaryFolder.newFile(fileName); Files.asCharSink(f, Charsets.UTF_8).write(contents); return new AndroidManifest(f.toPath(), null, null); }
private AndroidManifest newConfigWith(String packageName, String contents) throws IOException { String fileContents = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + " package=\"" + packageName + "\">\n" + " " + contents + "\n" + "</manifest>\n"; File f = temporaryFolder.newFile("whatever.xml"); Files.asCharSink(f, Charsets.UTF_8).write(fileContents); return new AndroidManifest(f.toPath(), null, null); }
Files.asCharSink(dfile, StandardCharsets.UTF_8).write(sb); System.out.println("Diagnostic trace written to: "+dfile.getAbsolutePath()); } catch (Exception e1) {
@Test public void ioUtils() throws Exception { File file = temporaryFolder.newFile("test_file.txt"); Files.asCharSink(file, StandardCharsets.UTF_8).write("some contents"); String contents = IoUtils.readFileAsString(file.getAbsolutePath()); assertThat(contents).isEqualTo("some contents"); } }
@Test public void pass_multiple_res_dirs_in_file() throws Exception { String resDirectoriesFileName = "res-directories"; File resDirectoriesFile = tempFolder.newFile(resDirectoriesFileName); Files.asCharSink(resDirectoriesFile, Charsets.UTF_8).write("buck/res1\nbuck/res2"); System.setProperty( "buck.robolectric_res_directories", "@" + resDirectoriesFile.getAbsolutePath()); String assetDirectoriesFileName = "asset-directories"; File assetDirectoriesFile = tempFolder.newFile(assetDirectoriesFileName); Files.asCharSink(assetDirectoriesFile, Charsets.UTF_8).write("buck/assets1\nbuck/assets2"); System.setProperty( "buck.robolectric_assets_directories", "@" + assetDirectoriesFile.getAbsolutePath()); ManifestIdentifier manifestIdentifier = buckManifestFactory.identify(configBuilder.build()); AndroidManifest manifest = RobolectricTestRunner.createAndroidManifest(manifestIdentifier); assertThat(manifest.getResDirectory()).isEqualTo(Paths.get("buck/res2")); assertThat(manifest.getAssetsDirectory()).isEqualTo(Paths.get("buck/assets2")); List<ResourcePath> resourcePathList = manifest.getIncludedResourcePaths(); assertThat(resourcePathList.size()).isEqualTo(3); assertThat(resourcePathList) .containsExactly( new ResourcePath( manifest.getRClass(), Paths.get("buck/res2"), Paths.get("buck/assets2")), new ResourcePath(manifest.getRClass(), Paths.get("buck/res1"), null), new ResourcePath(manifest.getRClass(), null, Paths.get("buck/assets1"))); } }
private static void storeCacheVersionsFile(String json, File cacheFile) { //noinspection ResultOfMethodCallIgnored cacheFile.getParentFile().mkdirs(); try { CharSource.wrap(json).copyTo(Files.asCharSink(cacheFile, Charsets.UTF_8)); } catch (IOException e) { LOG.error("Cannot write Gradle version information cache file.", e); // do not throw an exception if cache file cannot be written to be more robust against file system problems } }
public static void writeLines(String fileName,List<String> list,Charset charset) throws IOException { CharSink cs = Files.asCharSink(new File(fileName), charset); list = PojoUtil.avoidEmptyList(list); cs.writeLines(list); }
public void writeResponseFilesInDirectory(Path directory) throws IOException { File urlFile = directory.resolve("url.txt").toFile(); Files.asCharSink(urlFile, StandardCharsets.UTF_8).write(url); String dataFilename = constructResponseDataFilename(); File dataFile = directory.resolve(dataFilename).toFile(); responseContent.copyTo(Files.asByteSink(dataFile)); }
private static void addToGitIndex(Git git, File gitWorkTree, String path, String content) throws IOException, GitAPIException { final File file = Paths.get(gitWorkTree.getAbsolutePath(), path.split("/")).toFile(); file.getParentFile().mkdirs(); Files.asCharSink(file, StandardCharsets.UTF_8).write(content); git.add().addFilepattern(path).call(); } }
@Before public void setUp() throws Exception { csvStringFile = tempFolder.newFile(); Files.asCharSink(csvStringFile, StandardCharsets.UTF_8).write(csvString); if (headerPresent) { dataList.remove(0); } }