/** Read an input stream completely into a string */ public static String readAll(InputStream stream, Charset charset) throws IOException { return readAll(new InputStreamReader(stream, charset)); }
private String readConfigDefinition(File defPath) { try (Reader reader = retrieveConfigDefReader(defPath)) { return IOUtils.readAll(reader); } catch (IOException e) { throw new RuntimeException("Error reading config definition '" + defPath + "'", e); } }
@Override public ApplicationFile writeFile(Reader input) { try { IOUtils.writeFile(file, IOUtils.readAll(input), false); return this; } catch (IOException e) { throw new UncheckedIOException(e); } }
public DeploymentSpec read(Reader reader) { try { return read(IOUtils.readAll(reader)); } catch (IOException e) { throw new IllegalArgumentException("Could not read deployment spec", e); } }
/** * Reads and parses the search definition string provided by the given reader. Once all search definitions have been * imported, call {@link #build()}. * * @param reader The reader whose content to import. * @param searchDefDir The path to use when resolving file references. * @return The name of the imported object. * @throws ParseException Thrown if the file does not contain a valid search definition. */ public String importReader(NamedReader reader, String searchDefDir, DeployLogger deployLogger) throws IOException, ParseException { return importString(IOUtils.readAll(reader), searchDefDir, deployLogger); }
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); }
/** * Returns a ValidationOverrides instance with the content of the given Reader. * * @param reader the reader containing a validation-overrides XML structure * @return a ValidationOverrides from the argument * @throws IllegalArgumentException if the validation-allows.xml file exists but is invalid */ public static ValidationOverrides fromXml(Reader reader) { try { return fromXml(IOUtils.readAll(reader)); } catch (IOException e) { throw new IllegalArgumentException("Could not read deployment spec", e); } }
/** * Returns the name-payload pairs of any sd files under path/searchdefinitions/ in the given jar bundle * @param bundle The jar file, which will be closed afterwards by this method. * @param path For example 'complex/' * @return map of the SD payloads * @throws IOException if it is reading sd files fails */ static Map<String, String> getBundleSdFiles(String path, JarFile bundle) throws IOException { Map<String,String> ret = new LinkedHashMap<>(); for (Enumeration<JarEntry> e = bundle.entries(); e.hasMoreElements();) { JarEntry je=e.nextElement(); if (je.getName().startsWith(path+SEARCH_DEFINITIONS_DIR+"/") && je.getName().endsWith(SD_NAME_SUFFIX)) { String contents = IOUtils.readAll(new InputStreamReader(bundle.getInputStream(je))); ret.put(getFileName(je), contents); } } bundle.close(); return ret; }
private static ApplicationMetaData readMetaData(File appDir) { ApplicationMetaData defaultMetaData = new ApplicationMetaData(appDir, "n/a", "n/a", 0l, false, "", 0l, 0l); File metaFile = new File(appDir, META_FILE_NAME); if (!metaFile.exists()) { return defaultMetaData; } try (FileReader reader = new FileReader(metaFile)) { return ApplicationMetaData.fromJsonString(IOUtils.readAll(reader)); } catch (Exception e) { // Not a big deal, return default return defaultMetaData; } }
@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; }
/** * See #{@link #importReader} * * Convenience, should only be used for testing as logs will be swallowed. */ public String importReader(NamedReader reader, String searchDefDir) throws IOException, ParseException { return importString(IOUtils.readAll(reader), searchDefDir, new BaseDeployLogger()); }
private SemanticRules.RuleBase toRuleBaseConfigView(NamedReader reader) { try { String ruleBaseString = IOUtils.readAll(reader.getReader()); boolean isDefault = ruleBaseString.contains("@default"); return new SemanticRules.RuleBase(toName(reader.getName()), isDefault, ruleBaseString); } catch (IOException e) { throw new IllegalArgumentException("Could not load rules bases", e); } }
String contents = IOUtils.readAll(new FileReader(sdFile)); ret.put(sdFile.getName(), contents);
/** * Reads the information about all the large (aka ranking) constants stored in the application package * (the constant value itself is replicated with file distribution). */ List<RankingConstant> readLargeConstants() { try { List<RankingConstant> constants = new ArrayList<>(); for (ApplicationFile constantFile : application.getFile(modelFiles.largeConstantsInfoPath()).listFiles()) { String[] parts = IOUtils.readAll(constantFile.createReader()).split(":"); constants.add(new RankingConstant(parts[0], TensorType.fromSpec(parts[1]), parts[2])); } return constants; } catch (IOException e) { throw new UncheckedIOException(e); } }
public MetaData getMetaData() { File metaDir = getMetaDir(); File metaFile = new File(metaDir + "/" + getPath().getName()); log.log(LogLevel.DEBUG, "Getting metadata for " + metaFile); if (metaFile.exists()) { try { return mapper.readValue(metaFile, MetaData.class); } catch (IOException e) { System.out.println("whot:" + Exceptions.toMessageString(e)); // return below } } try { if (file.isDirectory()) { return new MetaData(ApplicationFile.ContentStatusNew, ""); } else { return new MetaData(ApplicationFile.ContentStatusNew, ConfigUtils.getMd5(IOUtils.readAll(createReader()))); } } catch (IOException | IllegalArgumentException e) { return null; } }