APISonar


com.google.common.io.Files.asCharSink

> com > google > common > io > Files > asCharSink
com APIs google APIs common APIs io APIs Files APIs asCharSink APIs

Example 1
private File createTmpFile(String content) throws IOException {
    File f = File.createTempFile("webdriver", "tmp");
    f.deleteOnExit();
    Files.asCharSink(f, StandardCharsets.UTF_8).write(content);
    return f;
  }
Example 2
private void createFileWithContents(File dir, String fileName, String fileContents)
      throws IOException {
    File txtFile = new File(dir, fileName);
    Files.asCharSink(txtFile, StandardCharsets.UTF_8).write(fileContents);
  }
Example 3
private void writeToFile(String filePath, List<String> lines) {
    CharSink outputSink = Files.asCharSink(new File(filePath), StandardCharsets.UTF_8);
    try {
      outputSink.writeLines(lines);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
Example 4
private static File writeTestFile(int limit) throws IOException {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < limit; i++) {
      if (sb.length() > 0) {
        sb.append('\n');
      }
      sb.append(i);
    }
    File file = File.createTempFile("test", ".txt");
    Files.asCharSink(file, StandardCharsets.ISO_8859_1).write(sb);
    return file;
  }
Example 5
private File touch(File baseDir, String stem) throws IOException {
    File tempFile = File.createTempFile(stem, ".txt", baseDir);
    tempFile.deleteOnExit();
    Files.asCharSink(tempFile, UTF_8).write("I like cheese");
    return tempFile;
  }
Example 6
private File addFile(String fileName, String source) throws IOException {
    File file = new File(tempDir, fileName);
    file.getParentFile().mkdirs();
    Files.asCharSink(file, Charset.defaultCharset()).write(source);
    return file;
  }
Example 7
public void init() throws IOException {
    File reservedTermsFile = tmpDir.newFile("xn--q9jyb4c_common-reserved.txt");
    File invalidReservedTermsFile = tmpDir.newFile("reserved-terms-wontparse.csv");
    String reservedTermsCsv =
        loadFile(CreateOrUpdateReservedListCommandTestCase.class, "example_reserved_terms.csv");
    Files.asCharSink(reservedTermsFile, UTF_8).write(reservedTermsCsv);
    Files.asCharSink(invalidReservedTermsFile, UTF_8)
        .write("sdfgagmsdgs,sdfgsd\nasdf234tafgs,asdfaw\n\n");
    reservedTermsPath = reservedTermsFile.getPath();
    invalidReservedTermsPath = invalidReservedTermsFile.getPath();
  }
Example 8
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");
  }
Example 9
private File getUtf8VocFile() throws IOException {
    File tmp = File.createTempFile("utf8_voc_test", "foo");
    tmp.deleteOnExit();
    Files.asCharSink(tmp, Charsets.UTF_8).write(String.format("Hello%n%n      %n\t%nWorld"));
    return tmp;
  }
Example 10
public void testSuccess_domainNames() throws Exception {
    createTld("tld");
    File domainNamesFile = tmpDir.newFile("domain_names.txt");
    Files.asCharSink(domainNamesFile, UTF_8).write("foo1.tld\nboo2.tld\nbaz9.tld\n");
    runCommand("--domain_names_file", domainNamesFile.getPath());
    assertAllocationTokens(
        createToken("123456789ABCDEFG", null, "foo1.tld"),
        createToken("HJKLMNPQRSTUVWXY", null, "boo2.tld"),
        createToken("Zabcdefghijkmnop", null, "baz9.tld"));
    assertInStdout(
        "foo1.tld,123456789ABCDEFG\nboo2.tld,HJKLMNPQRSTUVWXY\nbaz9.tld,Zabcdefghijkmnop");
  }
Example 11
public static void writePerformanceReport(final PerformanceData results, final File outputFile)
      throws IOException
  {
    String chartData = buildChartData(results);

    final String reportTemplate = loadReportTemplate();

    String reportHtml = reportTemplate.replace("/*ROW-DATA*/", chartData);
    reportHtml = reportHtml.replace("<!-- SYSTEM-INFO -->", buildSystemInfo());

    log.info("Writing performance chart to {}", outputFile);
    Files.asCharSink(outputFile, StandardCharsets.UTF_8).write(reportHtml);
  }
Example 12
public void write(final String content) {
        try {
            Files.asCharSink(file, charset, FileWriteMode.APPEND).write(content);
        } catch (Exception e) {
            throw new MocoException(e);
        }
    }
Example 13
public void parse_error() throws Exception {
    SensorContextTester spy = spy(context);
    File file = temp.newFile().getAbsoluteFile();
    Files.asCharSink(file, StandardCharsets.UTF_8).write("ParseError");
    scan(TestUtils.inputFile(file));
    verify(spy, never()).newHighlighting();
  }
Example 14
private InputFile generateTestFile(String sourceFile) throws IOException {
    File source = new File(sourceFile);
    File target = new File(temp.newFolder(), source.getName()).getAbsoluteFile();
    String content = Files.asCharSource(source, StandardCharsets.UTF_8)
      .read()
      .replaceAll("\\r\\n", "\n")
      .replaceAll("\\r", "\n")
      .replaceAll("\\n", eol);
    Files.asCharSink(target, StandardCharsets.UTF_8).write(content);
    return TestUtils.inputFile(target);
  }
Example 15
BatchFileAppender(final File file, final int capacity) {
        this.sink = Files.asCharSink(file, Charsets.UTF_8, FileWriteMode.APPEND);
        this.pendingWrite = new ArrayBlockingQueue<>(capacity);
        this.batchWriteThread = new Thread(new Runnable() {
            @Override
            public void run() {
                batchWriteLoop();
            }
        });
        this.stop = false;
        this.batchWriteThread.start();
    }
Example 16
public void run() throws Exception {
    ClaimsListShard cl = checkNotNull(ClaimsListShard.get(), "Couldn't load ClaimsList");
    String csv = Joiner.on('\n').withKeyValueSeparator(",").join(cl.getLabelsToKeys()) + "\n";
    Files.asCharSink(output.toFile(), UTF_8).write(csv);
  }
Example 17
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);
  }
Example 18
private InputFile addFile(String code, SensorContextTester context) throws IOException {
    File file = temp.newFile("test.java").getAbsoluteFile();
    Files.asCharSink(file, StandardCharsets.UTF_8).write(code);
    InputFile defaultFile = TestUtils.inputFile(context.fileSystem().baseDir().getAbsolutePath(), file);
    context.fileSystem().add(defaultFile);
    return defaultFile;
  }
Example 19
public void whenWriteMultipleLinesUsingCharSink_thenWritten() throws IOException {
        final List<String> names = Lists.newArrayList("John", "Jane", "Adam", "Tom");
        final File file = new File("src/test/resources/test.out");
        final CharSink sink = Files.asCharSink(file, Charsets.UTF_8);

        sink.writeLines(names, " ");

        final String result = Files.toString(file, Charsets.UTF_8);
        final String expectedValue = Joiner.on(" ").join(names);
        assertEquals(expectedValue, result.trim());

    }
Example 20
public void testRuleHasCustomRequirements() throws IOException {
    File file = Paths.get(tmp.getPath(), FILENAME).toFile();
    Assert.assertTrue(file.createNewFile());
    Files.asCharSink(file, Charsets.UTF_8, FileWriteMode.APPEND)
        .write(
            "{\"other_rule\": {\"workerSize\": \"SMALL\"}, \""
                + SHORT_NAME
                + "\": {\"workerSize\": \"LARGE\"}}");

    WorkerRequirementsProvider provider = new WorkerRequirementsProvider(FILENAME, true, 1000);
    WorkerRequirements workerRequirements = provider.resolveRequirements(buildTarget);
    Assert.assertNotNull(workerRequirements);
    Assert.assertEquals(WorkerSize.LARGE, workerRequirements.getWorkerSize());
  }
Example 21
public void execute() throws MojoExecutionException, MojoFailureException {
    Singleton.etcd = EtcdClusterFactory.buildCluster("maven", 1, false, false,
            additionalArguments != null ? additionalArguments : EMPTY);
    Singleton.etcd.start();

    URI endpoint = Singleton.etcd.getClientEndpoints().get(0);
    try {
      endpointFile.getParentFile().mkdirs();
      Files.asCharSink(endpointFile, US_ASCII).write(endpoint.toString());
      LOG.info("{} = {}", endpointFile, endpoint);
    } catch (IOException e) {
      throw new MojoFailureException("writing file failed", e);
    }
  }
Example 22
public void shouldUpdateTheFilterList() throws IOException {
		File file = File.createTempFile("infinitest", "shouldUpdateTheFilterList");

		FileBasedInfinitestConfigurationSource configSource = FileBasedInfinitestConfigurationSource.createFromFile(file);
		TestFilter list = new RegexFileFilter(configSource);
		assertFalse(list.match(javaClass("com.foo.Bar")));

		Files.asCharSink(file, Charsets.UTF_8, FileWriteMode.APPEND).write("exclude com.foo.Bar");
		
		list.updateFilterList();
		assertTrue(list.match(javaClass("com.foo.Bar")));
	}