use of com.yahoo.io.reader.NamedReader in project vespa by vespa-engine.
the class FilesApplicationPackage method searchDefinitionContents.
@Override
public Collection<NamedReader> searchDefinitionContents() {
Map<String, NamedReader> ret = new LinkedHashMap<>();
Set<String> fileSds = new LinkedHashSet<>();
Set<String> bundleSds = new LinkedHashSet<>();
try {
for (File f : getSearchDefinitionFiles()) {
fileSds.add(f.getName());
ret.put(f.getName(), new NamedReader(f.getName(), new FileReader(f)));
}
for (Map.Entry<String, String> e : allSdsFromDocprocBundlesAndClasspath(appDir).entrySet()) {
bundleSds.add(e.getKey());
ret.put(e.getKey(), new NamedReader(e.getKey(), new StringReader(e.getValue())));
}
} catch (Exception e) {
throw new IllegalArgumentException("Couldn't get search definition contents.", e);
}
verifySdsDisjoint(fileSds, bundleSds);
return ret.values();
}
use of com.yahoo.io.reader.NamedReader in project vespa by vespa-engine.
the class FilesApplicationPackage method getFiles.
private List<NamedReader> getFiles(Path relativePath, String namePrefix, String suffix, boolean recurse) {
try {
List<NamedReader> readers = new ArrayList<>();
File dir = new File(appDir, relativePath.getRelative());
if (!dir.isDirectory())
return readers;
File[] files = dir.listFiles();
if (files != null) {
for (File file : files) {
if (file.isDirectory()) {
if (recurse)
readers.addAll(getFiles(relativePath.append(file.getName()), namePrefix + "/" + file.getName(), suffix, recurse));
} else {
if (suffix == null || file.getName().endsWith(suffix))
readers.add(new NamedReader(file.getName(), new FileReader(file)));
}
}
}
return readers;
} catch (IOException e) {
throw new RuntimeException("Could not open (all) files in '" + relativePath + "'", e);
}
}
use of com.yahoo.io.reader.NamedReader in project vespa by vespa-engine.
the class PageTemplates method validate.
/**
* The number of pages in this, for reporting
*/
// private int pages=0;
/**
* Validates page templates in an application package. The passed readers will be closed.
*/
public static void validate(ApplicationPackage applicationPackage) {
List<NamedReader> pageTemplateFiles = null;
try {
pageTemplateFiles = applicationPackage.getPageTemplateFiles();
// Parse XML for validation only
new PageTemplateXMLReader().read(pageTemplateFiles, true);
} finally {
NamedReader.closeAll(pageTemplateFiles);
}
}
use of com.yahoo.io.reader.NamedReader in project vespa by vespa-engine.
the class ZooKeeperClient method writeSearchDefinitions.
private void writeSearchDefinitions(ApplicationPackage app) throws IOException {
Collection<NamedReader> sds = app.getSearchDefinitions();
if (sds.isEmpty()) {
return;
}
Path zkPath = getZooKeeperAppPath(ConfigCurator.USERAPP_ZK_SUBPATH).append(ApplicationPackage.SEARCH_DEFINITIONS_DIR);
configCurator.createNode(zkPath.getAbsolute());
// Ensures that ranking expressions and other files are also fed.
writeDir(app.getFile(ApplicationPackage.SEARCH_DEFINITIONS_DIR), zkPath, false);
for (NamedReader sd : sds) {
String name = sd.getName();
Reader reader = sd.getReader();
String data = com.yahoo.io.IOUtils.readAll(reader);
reader.close();
configCurator.putData(zkPath.getAbsolute(), name, data);
}
}
use of com.yahoo.io.reader.NamedReader in project vespa by vespa-engine.
the class QueryProfileXMLReader method read.
/**
* Reads all query profile xml files in a given directory,
* and all type xml files from the immediate subdirectory "types/" (if any)
*
* @throws RuntimeException if <code>directory</code> is not a readable directory, or if there is some error in the XML
*/
public QueryProfileRegistry read(String directory) {
List<NamedReader> queryProfileReaders = new ArrayList<>();
List<NamedReader> queryProfileTypeReaders = new ArrayList<>();
try {
File dir = new File(directory);
if (!dir.isDirectory())
throw new IllegalArgumentException("Could not read query profiles: '" + directory + "' is not a valid directory.");
for (File file : sortFiles(dir)) {
if (!file.getName().endsWith(".xml"))
continue;
queryProfileReaders.add(new NamedReader(file.getName(), new FileReader(file)));
}
File typeDir = new File(dir, "types");
if (typeDir.isDirectory()) {
for (File file : sortFiles(typeDir)) {
if (!file.getName().endsWith(".xml"))
continue;
queryProfileTypeReaders.add(new NamedReader(file.getName(), new FileReader(file)));
}
}
return read(queryProfileTypeReaders, queryProfileReaders);
} catch (IOException e) {
throw new IllegalArgumentException("Could not read query profiles from '" + directory + "'", e);
} finally {
closeAll(queryProfileReaders);
closeAll(queryProfileTypeReaders);
}
}
Aggregations