Search in sources :

Example 1 with NamedReader

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;
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NamedReader(com.yahoo.io.reader.NamedReader) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 2 with NamedReader

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;
}
Also used : StringReader(java.io.StringReader) NamedReader(com.yahoo.io.reader.NamedReader) ParseException(com.yahoo.searchdefinition.parser.ParseException)

Example 3 with NamedReader

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);
    }
}
Also used : ArrayList(java.util.ArrayList) NamedReader(com.yahoo.io.reader.NamedReader)

Example 4 with NamedReader

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);
}
Also used : NamedReader(com.yahoo.io.reader.NamedReader)

Example 5 with NamedReader

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);
}
Also used : StringReader(java.io.StringReader) NamedReader(com.yahoo.io.reader.NamedReader)

Aggregations

NamedReader (com.yahoo.io.reader.NamedReader)16 ArrayList (java.util.ArrayList)7 Element (org.w3c.dom.Element)4 ComponentId (com.yahoo.component.ComponentId)3 File (java.io.File)3 StringReader (java.io.StringReader)3 ApplicationFile (com.yahoo.config.application.api.ApplicationFile)2 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 JarFile (java.util.jar.JarFile)2 Path (com.yahoo.path.Path)1 PageTemplate (com.yahoo.search.pagetemplates.PageTemplate)1 PageTemplateXMLReader (com.yahoo.search.pagetemplates.config.PageTemplateXMLReader)1 QueryProfile (com.yahoo.search.query.profile.QueryProfile)1 ParseException (com.yahoo.searchdefinition.parser.ParseException)1 PageTemplates (com.yahoo.vespa.model.container.search.PageTemplates)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 Reader (java.io.Reader)1 URISyntaxException (java.net.URISyntaxException)1