APISonar


com.google.common.io.Files.write

> com > google > common > io > Files > write
com APIs google APIs common APIs io APIs Files APIs write APIs

Example 1
public void write(File target) throws IOException
    {
        Files.write(GSON.toJson(this), target, StandardCharsets.UTF_8);
    }
Example 2
protected void createFile(String key, byte[] contents) throws Exception
    {
        Files.write(contents, getFile(key));
    }
Example 3
private void writeTextFileAndTranslateExceptions(String contents, File toFile) {
        try {
            Files.write(contents, toFile, UTF_8);
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }
Example 4
private void createMasterPwdFile(String masterPwd) throws IOException {
    Assert.assertTrue(this.masterPwdFile.createNewFile());

    Files.write(masterPwd, this.masterPwdFile, Charset.defaultCharset());
  }
Example 5
String writeToNamedTmpFile(String filename, byte[] data) throws IOException {
    File tmpFile = tmpDir.newFile(filename);
    Files.write(data, tmpFile);
    return tmpFile.getPath();
  }
Example 6
private static void makePropertiesFileWithProject(File path, String projectId)
      throws IOException {
    String properties = String.format("[core]%n"
        + "account = test-account@google.com%n"
        + "project = %s%n"
        + "%n"
        + "[dataflow]%n"
        + "magic = true%n", projectId);
    Files.write(properties, path, StandardCharsets.UTF_8);
  }
Example 7
private void writeBigBadUtf8Sequence(File file) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    generateUtf8Latin1Sequence(out);
    generateUtf8OverlyLongSequence(out);
    generateUtf8NonUnicodeSequence(out);
    Files.write(out.toByteArray(), file);
  }
Example 8
private File getMasterPwdFile(String masterPwd) throws IOException {
    File masterPwdFile = File.createTempFile("masterPassword", null);
    Files.write(masterPwd, masterPwdFile, Charset.defaultCharset());
    return masterPwdFile;
  }
Example 9
public void testReadFirstLineWithEmptyFile() throws IOException {
    File emptyFile = tmp.newFile("foo.txt");
    Files.write(new byte[0], emptyFile);
    assertTrue(emptyFile.isFile());
    assertEquals(Optional.absent(), filesystem.readFirstLine("foo.txt"));
  }
Example 10
public static File createTempFile(byte[] data) throws IOException {
    File tmpFile = File.createTempFile("ode", null, tempRoot);
    Files.write(data, tmpFile);
    return tmpFile;
  }
Example 11
private void resolveSentinelConf() throws IOException {
        if (redisConfigBuilder == null) {
            addDefaultReplicationGroup();
        }
        setting(String.format(PORT_LINE, port));
        final String configString = redisConfigBuilder.toString();

        File redisConfigFile = File.createTempFile(resolveConfigName(), ".conf");
        redisConfigFile.deleteOnExit();
        Files.write(configString, redisConfigFile, Charset.forName("UTF-8"));
        sentinelConf = redisConfigFile.getAbsolutePath();
    }
Example 12
public void shouldRunQueryFromFile()
            throws IOException, InterruptedException
    {
        File temporayFile = File.createTempFile("test-sql", null);
        temporayFile.deleteOnExit();
        Files.write("select * from hive.default.nation;\n", temporayFile, UTF_8);

        launchPrestoCliWithServerArgument("--file", temporayFile.getAbsolutePath());
        assertThat(trimLines(presto.readRemainingOutputLines())).containsAll(nationTableBatchLines);
    }
Example 13
private void saveFile(Path path, Supplier<byte[]> dataSupplier) {
    File dir = path.getParent().toFile();
    if (!dir.isDirectory()) {
      checkState(dir.mkdirs(), "Couldn't create directory %s", dir);
    }
    try {
      Files.write(dataSupplier.get(), path.toFile());
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  }
Example 14
private static String singleLineFileInit(File file, Charset charset)
      throws IOException {
    String output = "This is gonna be great!\n";
    Files.write(output.getBytes(charset), file);
    return output;
  }
Example 15
public void testRun_rydeSignature() throws Exception {
    assumeTrue(hasCommand("gpg --version"));
    action.run();

    File rydeTmp = new File(gpg.getCwd(), "ryde");
    File sigTmp = new File(gpg.getCwd(), "ryde.sig");
    Files.write(readGcsFile(gcsService, RYDE_FILE), rydeTmp);
    Files.write(readGcsFile(gcsService, SIG_FILE), sigTmp);

    Process pid = gpg.exec("gpg", "--verify", sigTmp.toString(), rydeTmp.toString());
    String stderr = slurp(pid.getErrorStream());
    assertWithMessage(stderr).that(pid.waitFor()).isEqualTo(0);
    assertThat(stderr).contains("Good signature");
    assertThat(stderr).contains("rde-unittest@registry.test");
  }
Example 16
private File createTmpFile(String content) throws IOException {
    File f = File.createTempFile("webdriver", "tmp");
    f.deleteOnExit();
    Files.write(content, f, Charsets.UTF_8);
    return f;
  }
Example 17
public void testSuccess() throws Exception {
    File outDir = tmpDir.newFolder();
    File depositFile = tmpDir.newFile("deposit.xml");
    Files.write(depositXml.read(), depositFile);
    runCommand(
        "--tld=lol",
        "--input=" + depositFile.getPath(),
        "--outdir=" + outDir.getPath());
    assertThat(outDir.list()).asList().containsExactly(
        "lol_2010-10-17_full_S1_R0.ryde",
        "lol_2010-10-17_full_S1_R0.sig",
        "lol.pub");
  }
Example 18
public void testMatcherThatVerifiesMultipleFiles() throws IOException {
    File tmpFile1 = tmpFolder.newFile("result-000-of-002");
    File tmpFile2 = tmpFolder.newFile("result-001-of-002");
    File tmpFile3 = tmpFolder.newFile("tmp");
    Files.write("To be or not to be, ", tmpFile1, StandardCharsets.UTF_8);
    Files.write("it is not a question.", tmpFile2, StandardCharsets.UTF_8);
    Files.write("tmp", tmpFile3, StandardCharsets.UTF_8);

    FileChecksumMatcher matcher =
        new FileChecksumMatcher(
            "90552392c28396935fe4f123bd0b5c2d0f6260c8",
            tmpFolder.getRoot().toPath().resolve("result-*").toString());

    assertThat(pResult, matcher);
  }
Example 19
private File makeFileWithContents(String name, String contents) throws Exception {
    File tmpFile = tmpFolder.newFile(name);
    Files.write(contents, tmpFile, StandardCharsets.UTF_8);
    tmpFile.setLastModified(0);  // required for determinism with directories
    return tmpFile;
  }
Example 20
public void get_deletesFileIfItIsInvalidSnapshot() throws Exception {
        File folder = new File(mContext.getFilesDir(), SNAPSHOT_DIRECTORY);
        folder.mkdirs();
        File file = new File(folder, SNAPSHOT_FILE_PATH);
        byte[] fileContents = "<keyChainSnapshot></keyChainSnapshot>".getBytes(
                StandardCharsets.UTF_8);
        Files.write(fileContents, file);
        assertTrue(file.exists());

        assertNull(mRecoverySnapshotStorage.get(TEST_UID));

        assertFalse(file.exists());
    }
Example 21
private void addSourceFile(String fileName, String source) throws IOException {
    File file = new File(tempDir, fileName);
    file.getParentFile().mkdirs();
    Files.write(source, file, Charset.defaultCharset());
    inputFiles.add(file.getAbsolutePath());
  }
Example 22
public void crossMountMove() throws Exception {
    File file = mFolder.newFile();
    Files.write("hello".getBytes(), file);
    run("mount", "/cross", mFolder.getRoot().getAbsolutePath());
    run("ls", "-f", "/cross");
    run("distributedMv", PathUtils.concatPath("/cross", file.getName()), "/moved");
    mOutput.reset();
    run("cat", "/moved");
    assertEquals("hello", mOutput.toString());
  }
Example 23
public void reorderFieldsSameTypeNoForget() throws Exception {
    setupAndRun(
        (String tableName, File f1, File folder, TestBuilder testBuilder) -> {
          // replace file
          f1.delete();
          File f2 = new File(folder, "file2.json");
          Files.write("{b:2, a:3}", f2, StandardCharsets.UTF_8);

          testBuilder.baselineColumns("a", "b")
            .baselineValues(3L, 2L)
            .go();

        });
  }
Example 24
private void saveConvertedSource(String filename, String content) {
    try {
      File outputFile = new File(Options.getOutputDirectory(), filename);
      outputFile.getParentFile().mkdirs();
      Files.write(content, outputFile, Charset.defaultCharset());
    } catch (IOException e) {
      error(e.getMessage());
    }
  }
Example 25
public void testReadCustomTemplate() throws Exception {
    String contents1 = "To be or not to be, ", contents2 = "it is not a question.";

    // Customized template: resultSSS-totalNNN
    File tmpFile1 = tmpFolder.newFile("result0-total2");
    File tmpFile2 = tmpFolder.newFile("result1-total2");
    Files.write(contents1, tmpFile1, StandardCharsets.UTF_8);
    Files.write(contents2, tmpFile2, StandardCharsets.UTF_8);

    Pattern customizedTemplate =
        Pattern.compile("(?x) result (?<shardnum>\\d+) - total (?<numshards>\\d+)");
    NumberedShardedFile shardedFile = new NumberedShardedFile(filePattern, customizedTemplate);

    assertThat(shardedFile.readFilesWithRetries(), containsInAnyOrder(contents1, contents2));
  }