APISonar


com.google.common.io.Files.newWriter

> com > google > common > io > Files > newWriter
com APIs google APIs common APIs io APIs Files APIs newWriter APIs

Example 1
public void store(Object storedObj) throws IOException {
        try (Writer writer = Files.newWriter(storedFile, Charset.forName("UTF-8"))) {
            gson.toJson(storedObj, writer);
        }
    }
Example 2
private static void writePropertiesFile(File propFile, List<String> newLines)
            throws FileNotFoundException {
        // properties files must be ISO_8859_1
        PrintWriter out = new PrintWriter(Files.newWriter(propFile, ISO_8859_1));
        try {
            for (String newLine : newLines) {
                out.println(newLine);
            }
        } finally {
            out.close();
        }
    }
Example 3
private void writeAllToFile() throws FileNotFoundException, IOException {
        BufferedWriter out = Files.newWriter(file, UTF_8);
        try {
            int lineCount = 0;
            for (Map.Entry<String, CacheValue> entry : cache.entrySet()) {
                writeLine(out, entry.getKey(), entry.getValue());
                lineCount++;
            }
            linesInFile = lineCount;
        } finally {
            out.close();
        }
    }
Example 4
private void writePropertiesFile(File parent, String name, Properties properties) throws IOException {
        File propertiesFile = new File(parent, name);
        try (Writer writer = Files.newWriter(propertiesFile, Charset.forName("UTF-8"))) {
            properties.store(writer, null);
        }
    }
Example 5
private static void writeDataToFile(String[] sData, Path path) throws IOException {
    BufferedWriter output = null;
    try {
      output = Files.newWriter(new File(path.toString()), Charsets.UTF_8);
      for (String line : sData) {
        output.write(line);
        output.write('\n');
      }
    } finally {
      Closeables.close(output, false);
    }
  
  }
Example 6
private java.io.File createBackupFile(Object backup) throws IOException {
    java.io.File backupFile = new java.io.File(TEST);
    BufferedWriter writer = Files.newWriter(backupFile, Charset.defaultCharset());
    writer.write(backup.toString());
    writer.flush();
    writer.close();
    return backupFile;
  }
Example 7
public void saveToLocal() {
        try {
            Files.createParentDirs(localCache);
            Writer writer = Files.newWriter(localCache, Charsets.UTF_8);
            gson.toJson(metas.withoutNull(), Metas.class, writer);
            writer.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
Example 8
public static void writeLines(File file, String[] lines)
    throws IOException {
    Writer writer = Files.newWriter(file, Charsets.UTF_8);
    try {
      for (String line : lines) {
        writer.write(line);
        writer.write('\n');
      }
    } finally {
      Closeables.close(writer, true);
    }
  }
Example 9
public static void writeToFile(String fileName, CodeReferenceMap map) throws IOException {
    File file = new File(fileName);
    try {
      BufferedWriter writer = Files.newWriter(file, Charset.defaultCharset());
      writeCodeReferenceMapInfo(writer, map);
      writer.close();
    } catch (IOException e) {
      ErrorUtil.error(e.getMessage());
    }
  }
Example 10
private void dumpMetadata(Map<String, String> metadata) {
    File file = new File(projectReactor.getRoot().getWorkDir(), METADATA_DUMP_FILENAME);
    try (Writer output = Files.newWriter(file, StandardCharsets.UTF_8)) {
      for (Map.Entry<String, String> entry : metadata.entrySet()) {
        output.write(entry.getKey());
        output.write("=");
        output.write(entry.getValue());
        output.write("\n");
      }

      LOG.debug("Report metadata written to {}", file);
    } catch (IOException e) {
      throw new IllegalStateException("Unable to dump " + file, e);
    }
  }
Example 11
private static void populateRollupTestData(File tmpFile) throws IOException
  {
    try (BufferedWriter writer = Files.newWriter(tmpFile, StandardCharsets.UTF_8)) {
      writer.write("2014-01-01T00:00:10Z,a,1\n");
      writer.write("2014-01-01T01:00:20Z,a,1\n");
      writer.write("2014-01-01T00:00:10Z,b,2\n");
      writer.write("2014-01-01T00:00:10Z,c,3\n");
      writer.write("2014-01-01T01:00:20Z,b,2\n");
      writer.write("2014-01-01T02:00:30Z,a,1\n");
      writer.write("2014-01-01T02:00:30Z,b,2\n");
      writer.write("2014-01-01T01:00:20Z,c,3\n");
      writer.write("2014-01-01T02:00:30Z,c,3\n");
    }
  }
Example 12
public void setUp() throws Exception {
    super.setUp();
    input = getTestTempDir("bayes/in");
    out = getTestTempDir("bayes/out");
    for (String word : WORDS) {
      File file = new File(input, word);
      Writer writer = Files.newWriter(file, Charsets.UTF_8);
      try {
      writer.write(word);
      } finally {
        Closeables.closeQuietly(writer);
      }
    }
  }
Example 13
public void test() throws IOException
  {
    File file = folder.newFile();
    try (BufferedWriter out = Files.newWriter(file, StandardCharsets.UTF_8)) {
      out.write("sessionToken=sessionTokenSample\nsecretKey=secretKeySample\naccessKey=accessKeySample\n");
    }

    FileSessionCredentialsProvider provider = new FileSessionCredentialsProvider(file.getAbsolutePath());
    AWSSessionCredentials sessionCredentials = (AWSSessionCredentials) provider.getCredentials();
    Assert.assertEquals("sessionTokenSample", sessionCredentials.getSessionToken());
    Assert.assertEquals("accessKeySample", sessionCredentials.getAWSAccessKeyId());
    Assert.assertEquals("secretKeySample", sessionCredentials.getAWSSecretKey());
  }
Example 14
public static void writeHelperFunction() throws IOException {
        File file = new File("addToPlot.m");
        BufferedWriter out = Files.newWriter(file, Charsets.UTF_8);

        out.write("function handle = addToPlot(numTerms, perDoc, color, linestyle, linewidth)\n" + "handle = line(numTerms, perDoc);\n"
                + "set(handle, 'color', color);\n" + "set(handle, 'linestyle',linestyle);\n" + "set(handle, 'LineWidth',linewidth);\n"
                + "end\n");
        out.close();
    }
Example 15
public static void collapse(String label, Analyzer analyzer, File inputDir,
                              Charset charset, File outputFile) throws IOException {
    Writer writer = Files.newWriter(outputFile, charset);
    try {
      inputDir.listFiles(new FileProcessor(label, analyzer, charset, writer));
      // listFiles() is called here as a way to recursively visit files,
      // actually
    } finally {
      Closeables.closeQuietly(writer);
    }
  }
Example 16
public void writeScene(Scene scene)
      throws IOException {
    File file = new File(scene.getSceneRoot(), scene.getName());
    File parent = file.getParentFile();
    if (!parent.exists() && !parent.mkdirs()) {
      throw new IllegalStateException("Failed to create new directory: " + parent);
    }
    BufferedWriter bufferedWriter = Files.newWriter(file, Charset.forName(SceneSerializationConstant.FILE_CHARSET));
    SceneSerializer sceneSerializer = new SceneSerializer();
    sceneSerializer.serialize(scene, bufferedWriter);
  }