Java Code Examples for org.osgl.util.IO#readLines()

The following examples show how to use org.osgl.util.IO#readLines() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Book.java    From act-doc with Apache License 2.0 6 votes vote down vote up
public void process() {
    List<String> lines = new ArrayList<>();
    for (String chapter : processor.chapters()) {
        File src = new File(base, chapter);
        List<String> fileLines = IO.readLines(src);
        C.List<String> processedFileLines = C.newList();
        for (String line : fileLines) {
            if ("[返回目录](index.md)".equals(line.trim())) {
                continue;
            }
            line = processor.processTag(line);
            processedFileLines.add(line);
        }
        if (!lines.isEmpty()) {
            processedFileLines.add("\\newpage");
        }
        lines.addAll(processedFileLines);
    }
    File target = new File(processor.workspace(), "act_doc-" + lang + ".md");
    IO.write(S.join(lines).by("\n").get()).to(target);
}
 
Example 2
Source File: Zen.java    From actframework with Apache License 2.0 6 votes vote down vote up
private static List<String> loadWords() {
    URL url = Act.getResource("act_zen.txt");
    List<String> words = C.newList(defaultWords());
    if (null != url) {
        try {
            List<String> myWords = IO.readLines(url.openStream());
            if (!myWords.isEmpty()) {
                words = myWords;
            }
        } catch (Exception e) {
            // ignore it
        }
    }
    List<String> retVal = new ArrayList<>(words.size());
    for (String s : words) {
        if (s.contains("\n")) {
            s = s.replaceAll("\n", "\n          ");
        } else if (s.contains("\\n")) {
            s = s.replaceAll("\\\\n", "\n          ");
        }
        retVal.add(s);
    }
    return retVal;
}
 
Example 3
Source File: ContentLinesResolver.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> resolve(String value) {
    try {
        ISObject sobj = SObjectResolver.INSTANCE.resolve(value);
        return null == sobj ? fallBack(value) : IO.readLines(sobj.asInputStream());
    } catch (Exception e) {
        return fallBack(value);
    }
}
 
Example 4
Source File: ContentLinesBinder.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> resolve(List<String> bean, String model, ParamValueProvider params) {
    try {
        ISObject sobj = SObjectBinder.INSTANCE.resolve(null, model, params);
        return null == sobj ? fallBack(model, params) : IO.readLines(sobj.asInputStream());
    } catch (Exception e) {
        return fallBack(model, params);
    }
}
 
Example 5
Source File: View.java    From actframework with Apache License 2.0 3 votes vote down vote up
/**
 * Load template content.
 * <p>
 * This method is used by error reporting feature when app running in dev mode
 *
 * @param template the template path
 * @return the template content in lines
 */
public List<String> loadContent(String template) {
    File file = new File(templateRootDir(), template);
    if (file.exists() && file.canRead()) {
        return IO.readLines(file);
    }
    return C.list();
}