@Override public ApplicationFile appendFile(String value) { try { IOUtils.writeFile(file, value, true); return this; } catch (IOException e) { throw new UncheckedIOException(e); } }
/** * Writes the given string to the file */ public static void writeFile(String file, String text, boolean append) throws IOException { writeFile(new File(file), text, append); }
@Override public void writeMetaData() throws IOException { File metaFile = new File(appDir, META_FILE_NAME); IOUtils.writeFile(metaFile, metaData.asJsonString(), false); }
private static void writeContentsToFile(File outDir, String outFile, InputStream inputStream) throws IOException { String contents = IOUtils.readAll(new InputStreamReader(inputStream)); File out = new File(outDir, outFile); IOUtils.writeFile(out, contents, false); }
@Override public ApplicationFile writeFile(Reader input) { try { IOUtils.writeFile(file, IOUtils.readAll(input), false); return this; } catch (IOException e) { throw new UncheckedIOException(e); } }
@Override public ApplicationFile appendFile(String value) { if (file.getParentFile() != null) { file.getParentFile().mkdirs(); } try { String status = file.exists() ? ApplicationFile.ContentStatusChanged : ApplicationFile.ContentStatusNew; IOUtils.writeFile(file, value, true); writeMetaFile(value, status); } catch (IOException e) { throw new RuntimeException(e); } return this; }
@Override public ApplicationFile writeFile(Reader input) { if (file.getParentFile() != null) { file.getParentFile().mkdirs(); } try { String status = file.exists() ? ApplicationFile.ContentStatusChanged : ApplicationFile.ContentStatusNew; String data = com.yahoo.io.IOUtils.readAll(input); IOUtils.writeFile(file, data, false); writeMetaFile(data, status); } catch (IOException e) { throw new RuntimeException(e); } return this; }
private static void writeConfig(String dir, String configName, ConfigInstance config) throws IOException { IOUtils.writeFile(dir + configName, StringUtilities.implodeMultiline(ConfigInstance.serialize(config)), false); }
/** * Adds this constant to the application package as a file, * such that it can be distributed using file distribution. * * @return the path to the stored constant, relative to the application package root */ Path writeLargeConstant(String name, Tensor constant) { Path constantsPath = modelFiles.largeConstantsContentPath(); // "tbf" ending for "typed binary format" - recognized by the nodes receiving the file: Path constantPath = constantsPath.append(name + ".tbf"); // Remember the constant in a file we replicate in ZooKeeper application.getFile(modelFiles.largeConstantsInfoPath().append(name + ".constant")) .writeFile(new StringReader(name + ":" + constant.type() + ":" + correct(constantPath))); // Write content explicitly as a file on the file system as this is distributed using file distribution // - but only if this is a global model to avoid writing the same constants for each rank profile // where they are used if (modelFiles.modelName.isGlobal()) { createIfNeeded(constantsPath); IOUtils.writeFile(application.getFileReference(constantPath), TypedBinaryFormat.encode(constant)); } return correct(constantPath); }