use of com.yahoo.io.reader.NamedReader in project vespa by vespa-engine.
the class Xml method allElemsFromPath.
/**
* @return The root element of each xml file under pathFromAppRoot/ in the app package
*/
@NonNull
public static List<Element> allElemsFromPath(ApplicationPackage app, String pathFromAppRoot) {
List<Element> ret = new ArrayList<>();
List<NamedReader> files = null;
try {
files = app.getFiles(Path.fromString(pathFromAppRoot), ".xml", true);
for (NamedReader reader : files) ret.add(getElement(reader));
} finally {
NamedReader.closeAll(files);
}
return ret;
}
use of com.yahoo.io.reader.NamedReader in project vespa by vespa-engine.
the class MockApplicationPackage method getSearchDefinitions.
@Override
public List<NamedReader> getSearchDefinitions() {
ArrayList<NamedReader> readers = new ArrayList<>();
SearchBuilder searchBuilder = new SearchBuilder(this, new RankProfileRegistry(), queryProfileRegistry);
for (String sd : searchDefinitions) {
try {
String name = searchBuilder.importString(sd);
readers.add(new NamedReader(name + ApplicationPackage.SD_NAME_SUFFIX, new StringReader(sd)));
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
return readers;
}
use of com.yahoo.io.reader.NamedReader in project vespa by vespa-engine.
the class ZKLiveApp method getAllDataFromDirectory.
/**
* As above, except
*
* @param namePrefix the prefix to prepend to the returned reader names
*/
private List<NamedReader> getAllDataFromDirectory(String path, String namePrefix, String fileNameSuffix, boolean recursive) {
String fullPath = getFullPath(path);
List<NamedReader> result = new ArrayList<>();
List<String> children = getChildren(path);
try {
for (String child : children) {
if (fileNameSuffix == null || child.endsWith(fileNameSuffix)) {
result.add(new NamedReader(namePrefix + child, reader(zk.getData(fullPath, child))));
if (log.isLoggable(Level.FINER))
log.finer("ZKApplicationPackage: Added '" + child + "' (matched suffix " + fileNameSuffix + ")");
} else {
if (log.isLoggable(Level.FINER))
log.finer("ZKApplicationPackage: Skipped '" + child + "' (did not match suffix " + fileNameSuffix + ")");
}
if (recursive)
result.addAll(getAllDataFromDirectory(path + "/" + child, namePrefix + child + "/", fileNameSuffix, recursive));
}
if (log.isLoggable(Level.FINE))
log.fine("ZKApplicationPackage: Found '" + result.size() + "' files in " + fullPath);
return result;
} catch (Exception e) {
throw new RuntimeException("Could not retrieve all data from '" + fullPath + "' in zookeeper", e);
}
}
use of com.yahoo.io.reader.NamedReader in project vespa by vespa-engine.
the class NamedReaderTestCase method testAllDelegators.
public void testAllDelegators() throws IOException {
MarkerReader m = new MarkerReader();
NamedReader r = new NamedReader("nalle", m);
r.read(CharBuffer.allocate(5000));
assertEquals(MarkerReader.READ_CHAR_BUFFER, m.lastMethodHit);
r.read();
assertEquals(MarkerReader.READ, m.lastMethodHit);
r.read(new char[5]);
assertEquals(MarkerReader.READ_CHAR, m.lastMethodHit);
r.read(new char[5], 0, 5);
assertEquals(MarkerReader.READ_CHAR_INT_INT, m.lastMethodHit);
r.skip(5L);
assertEquals(MarkerReader.SKIP_LONG, m.lastMethodHit);
r.ready();
assertEquals(MarkerReader.READY, m.lastMethodHit);
r.markSupported();
assertEquals(MarkerReader.MARK_SUPPORTED, m.lastMethodHit);
r.mark(5);
assertEquals(MarkerReader.MARK_INT, m.lastMethodHit);
r.reset();
assertEquals(MarkerReader.RESET, m.lastMethodHit);
r.close();
assertEquals(MarkerReader.CLOSE, m.lastMethodHit);
}
use of com.yahoo.io.reader.NamedReader in project vespa by vespa-engine.
the class NamedReaderTestCase method testIt.
public void testIt() {
StringReader stringReader = new StringReader("hello world");
NamedReader r = new NamedReader("test1", stringReader);
assertEquals("test1", r.getName());
assertEquals("test1", r.toString());
assertEquals(stringReader, r.getReader());
NamedReader.closeAll(Collections.singletonList(r));
// noop, nor exception
NamedReader.closeAll(null);
}
Aggregations