/** * Writes the string to the output file using default charset. */ public static void writeString(File file, String string) { writeString(file, string, Charsets.defaultCharset()); }
public static void writeString(File file,String string, Charset encoding){ FileOutputStream out = null; try{ out = new FileOutputStream(file); writeString(out,string,encoding); }catch(IOException e){ throw Exceptions.wrap(e); }finally{ close(out); } }
private void renderAndWriteFile(Mustache template, Map data, String filepath) { File file = folder.resolve(filepath).toFile(); if(filepath.indexOf('/') > 0) { Try.throwUnchecked(() -> Files.createDirectories(file.getParentFile().toPath())); } log.debug("Render template '{}' and write to '{}'", template.getName(), filepath); IO.writeString(file, template.render(data)); }
protected String writeKeyContent(File file){ /* #base64 rsa private key# ... #base64 rsa public key# ... */ RsaKeyPair kp = RSA.generateKeyPair(); StringBuilder content = new StringBuilder(); content.append("#base64 rsa private key#\n") .append(kp.getBase64PrivateKey()) .append("\n\n") .append("#base64 rsa public key#\n") .append(kp.getBase64PublicKey()); IO.writeString(file, content.toString(), Charsets.UTF_8); return content.toString(); }
Try.throwUnchecked(() -> Files.createDirectories(path.getParent())); log.info("Create gitbook file : {}", path.normalize()); IO.writeString(path.toFile(), r.getContent());
protected String loadOrGenerateSecret() { FileResource userDir = Resources.createFileResource(System.getProperty("user.dir")); FileResource targetDir = userDir.createRelative("./target"); File secretFile = targetDir.exists() ? targetDir.createRelative("./.secret").getFile() : userDir.createRelative("./.secret").getFile(); if(secretFile.exists()) { String secret = Strings.trim(IO.readString(secretFile, Charsets.UTF_8)); if(!Strings.isEmpty(secret)) { return secret; } } String secret = Randoms.nextString(32); if(getBooleanProperty("app.config.save-generated-secret", true)) { IO.writeString(secretFile, secret, Charsets.UTF_8); } return secret; }