Search in sources :

Example 81 with Reader

use of java.io.Reader in project es6draft by anba.

the class IntlDataTools method oldStyleLanguageTags.

/**
     * {@link IntlAbstractOperations#oldStyleLanguageTags}
     * 
     * @param cldrMainDir
     *            the CLDR main directory
     * @throws IOException
     *             if an I/O error occurs
     */
static void oldStyleLanguageTags(Path cldrMainDir) throws IOException {
    try (DirectoryStream<Path> newDirectoryStream = Files.newDirectoryStream(cldrMainDir)) {
        Map<String, String> names = new LinkedHashMap<>();
        Map<String, String> aliased = new LinkedHashMap<>();
        for (Path path : newDirectoryStream) {
            try (Reader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
                Document xml = xml(reader);
                Element identity = getElementByTagName(xml.getDocumentElement(), "identity");
                assert identity != null;
                Element language = getElementByTagName(xml.getDocumentElement(), "language");
                Element script = getElementByTagName(xml.getDocumentElement(), "script");
                Element territory = getElementByTagName(xml.getDocumentElement(), "territory");
                String tag = language.getAttribute("type");
                if (script != null) {
                    tag += "-" + script.getAttribute("type");
                }
                if (territory != null) {
                    tag += "-" + territory.getAttribute("type");
                }
                String filename = Objects.requireNonNull(path.getFileName()).toString();
                filename = filename.substring(0, filename.lastIndexOf('.'));
                names.put(filename, tag);
                Element alias = getElementByTagName(xml.getDocumentElement(), "alias");
                if (alias != null && script == null && territory != null) {
                    aliased.put(tag, alias.getAttribute("source"));
                }
            }
        }
        Map<String, String> result = new LinkedHashMap<>();
        for (Map.Entry<String, String> entry : aliased.entrySet()) {
            String from = entry.getKey();
            String to = names.get(entry.getValue());
            String value = result.get(to);
            if (value == null) {
                value = "";
            } else {
                value += ", ";
            }
            value += "\"" + from + "\"";
            result.put(to, value);
        }
        for (Map.Entry<String, String> entry : result.entrySet()) {
            System.out.printf("map.put(\"%s\", new String[]{%s});%n", entry.getKey(), entry.getValue());
        }
    }
}
Also used : Path(java.nio.file.Path) Element(org.w3c.dom.Element) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) Document(org.w3c.dom.Document)

Example 82 with Reader

use of java.io.Reader in project es6draft by anba.

the class ChakraTest method readSettings.

private static Map<String, TestSetting> readSettings(Path dir) {
    Path settingsFile = dir.resolve("rlexe.xml");
    if (Files.isRegularFile(settingsFile)) {
        try (Reader reader = bomReader(Files.newInputStream(settingsFile))) {
            Document doc = Resources.xml(reader);
            NodeList elements = doc.getElementsByTagName("default");
            HashMap<String, TestSetting> settingMap = new HashMap<>();
            for (int i = 0, length = elements.getLength(); i < length; ++i) {
                Element element = (Element) elements.item(i);
                String files = element.getElementsByTagName("files").item(0).getTextContent();
                TestSetting setting = new TestSetting();
                NodeList baseline = element.getElementsByTagName("baseline");
                if (baseline.getLength() > 0) {
                    setting.baseline = baseline.item(0).getTextContent();
                }
                NodeList compileFlags = element.getElementsByTagName("compile-flags");
                if (compileFlags.getLength() > 0) {
                    String flags = compileFlags.item(0).getTextContent();
                    setting.disabled = flags.contains("-verbose") || flags.contains("-dump:") || flags.contains("-trace:") || flags.contains("-testtrace:") || flags.contains("-testTrace:");
                }
                settingMap.putIfAbsent(files, setting);
            }
            return settingMap;
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
    return Collections.emptyMap();
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) Document(org.w3c.dom.Document)

Example 83 with Reader

use of java.io.Reader in project es6draft by anba.

the class Resources method readExcludeXML.

/**
     * Load the exclusion xml-list for invalid test cases from {@link InputStream}
     */
private static Set<String> readExcludeXML(InputStream is) throws IOException {
    Set<String> exclude = new HashSet<>();
    Reader reader = new InputStreamReader(new BOMInputStream(is), StandardCharsets.UTF_8);
    NodeList ns = xml(reader).getDocumentElement().getElementsByTagName("test");
    for (int i = 0, len = ns.getLength(); i < len; ++i) {
        exclude.add(((Element) ns.item(i)).getAttribute("id"));
    }
    return exclude;
}
Also used : BOMInputStream(org.apache.commons.io.input.BOMInputStream) InputStreamReader(java.io.InputStreamReader) NodeList(org.w3c.dom.NodeList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader)

Example 84 with Reader

use of java.io.Reader in project groovy by apache.

the class IOGroovyMethods method withReader.

/**
     * Allows this reader to be used within the closure, ensuring that it
     * is closed before this method returns.
     *
     * @param reader  the reader which is used and then closed
     * @param closure the closure that the writer is passed into
     * @return the value returned by the closure
     * @throws IOException if an IOException occurs.
     * @since 1.5.2
     */
public static <T> T withReader(Reader reader, @ClosureParams(FirstParam.class) Closure<T> closure) throws IOException {
    try {
        T result = closure.call(reader);
        Reader temp = reader;
        reader = null;
        temp.close();
        return result;
    } finally {
        closeWithWarning(reader);
    }
}
Also used : Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader)

Example 85 with Reader

use of java.io.Reader in project groovy by apache.

the class InvokerHelper method write.

/**
     * Writes an object to a Writer using Groovy's default representation for the object.
     */
public static void write(Writer out, Object object) throws IOException {
    if (object instanceof String) {
        out.write((String) object);
    } else if (object instanceof Object[]) {
        out.write(toArrayString((Object[]) object));
    } else if (object instanceof Map) {
        out.write(toMapString((Map) object));
    } else if (object instanceof Collection) {
        out.write(toListString((Collection) object));
    } else if (object instanceof Writable) {
        Writable writable = (Writable) object;
        writable.writeTo(out);
    } else if (object instanceof InputStream || object instanceof Reader) {
        // Copy stream to stream
        Reader reader;
        if (object instanceof InputStream) {
            reader = new InputStreamReader((InputStream) object);
        } else {
            reader = (Reader) object;
        }
        char[] chars = new char[8192];
        int i;
        while ((i = reader.read(chars)) != -1) {
            out.write(chars, 0, i);
        }
        reader.close();
    } else {
        out.write(toString(object));
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Collection(java.util.Collection) Writable(groovy.lang.Writable) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) GroovyObject(groovy.lang.GroovyObject) GString(groovy.lang.GString) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) SpreadMap(groovy.lang.SpreadMap)

Aggregations

Reader (java.io.Reader)1734 InputStreamReader (java.io.InputStreamReader)627 StringReader (java.io.StringReader)565 IOException (java.io.IOException)482 BufferedReader (java.io.BufferedReader)293 Test (org.junit.Test)253 InputStream (java.io.InputStream)252 TokenStream (org.apache.lucene.analysis.TokenStream)171 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)159 Connection (java.sql.Connection)138 FileReader (java.io.FileReader)129 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)126 FileInputStream (java.io.FileInputStream)124 File (java.io.File)117 BeforeClass (org.junit.BeforeClass)99 Tokenizer (org.apache.lucene.analysis.Tokenizer)91 StringWriter (java.io.StringWriter)89 ArrayList (java.util.ArrayList)86 SqlSession (org.apache.ibatis.session.SqlSession)83 List (java.util.List)76