Search in sources :

Example 61 with StringReader

use of java.io.StringReader in project groovy-core by groovy.

the class BaseTemplate method fragment.

/**
     * Renders an embedded template as a fragment. Fragments are cached in a template, meaning that
     * if you use the same fragment in a template, it will only be compiled once, but once <b>per template
     * instance</b>. This is less performant than using {@link #layout(java.util.Map, String)}.
     *
     * @param model model to be passed to the template
     * @param templateText template body
     * @return this template instance
     * @throws IOException
     * @throws ClassNotFoundException
     */
public Object fragment(Map model, String templateText) throws IOException, ClassNotFoundException {
    Template template = cachedFragments.get(templateText);
    if (template == null) {
        template = engine.createTemplate(new StringReader(templateText));
        cachedFragments.put(templateText, template);
    }
    template.make(model).writeTo(out);
    return this;
}
Also used : StringReader(java.io.StringReader) Template(groovy.text.Template)

Example 62 with StringReader

use of java.io.StringReader in project j2objc by google.

the class OldPushbackReaderTest method test_unread_$CII_ArrayIndexOutOfBoundsException.

public void test_unread_$CII_ArrayIndexOutOfBoundsException() throws IOException {
    //a pushback reader with one character buffer
    pbr = new PushbackReader(new StringReader(pbString));
    try {
        pbr.unread(new char[pbString.length()], 0, -1);
        fail("should throw ArrayIndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        pbr.unread(new char[10], 10, 1);
        fail("should throw ArrayIndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
}
Also used : StringReader(java.io.StringReader) PushbackReader(java.io.PushbackReader)

Example 63 with StringReader

use of java.io.StringReader in project j2objc by google.

the class OldStringReaderTest method test_markI.

public void test_markI() throws IOException {
    sr = new StringReader(testString);
    try {
        sr.mark(-1);
        fail("IllegalArgumentException not thrown!");
    } catch (IllegalArgumentException e) {
    }
}
Also used : StringReader(java.io.StringReader)

Example 64 with StringReader

use of java.io.StringReader in project j2objc by google.

the class OldPushbackReaderTest method test_ConstructorLjava_io_Reader.

/**
     * java.io.PushbackReader#PushbackReader(java.io.Reader)
     */
public void test_ConstructorLjava_io_Reader() {
    // Test for method java.io.PushbackReader(java.io.Reader)
    try {
        pbr.close();
        pbr = new PushbackReader(new StringReader(pbString));
        char[] buf = new char[5];
        pbr.read(buf, 0, 5);
        pbr.unread(buf);
        fail("Created reader with buffer larger than 1");
        ;
    } catch (IOException e) {
    // Expected
    }
    try {
        pbr = new PushbackReader(null);
    } catch (NullPointerException e) {
    // EXpected
    }
}
Also used : StringReader(java.io.StringReader) IOException(java.io.IOException) PushbackReader(java.io.PushbackReader)

Example 65 with StringReader

use of java.io.StringReader in project j2objc by google.

the class OldAndroidPushbackReaderTest method testPushbackReader.

public void testPushbackReader() throws Exception {
    String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
    StringReader aa = new StringReader(str);
    StringReader ba = new StringReader(str);
    StringReader ca = new StringReader(str);
    PushbackReader a = new PushbackReader(aa, 5);
    try {
        a.unread("PUSH".toCharArray());
        Assert.assertEquals("PUSHAbCdEfGhIjKlMnOpQrStUvWxYz", read(a));
    } finally {
        a.close();
    }
    PushbackReader b = new PushbackReader(ba, 15);
    try {
        b.unread('X');
        Assert.assertEquals("XAbCdEfGhI", read(b, 10));
    } finally {
        b.close();
    }
    PushbackReader c = new PushbackReader(ca);
    try {
        Assert.assertEquals("bdfhjlnprtvxz", skipRead(c));
    } finally {
        c.close();
    }
}
Also used : StringReader(java.io.StringReader) PushbackReader(java.io.PushbackReader)

Aggregations

StringReader (java.io.StringReader)4150 Test (org.junit.Test)1003 IOException (java.io.IOException)589 Reader (java.io.Reader)445 InputSource (org.xml.sax.InputSource)408 BufferedReader (java.io.BufferedReader)342 TokenStream (org.apache.lucene.analysis.TokenStream)302 ArrayList (java.util.ArrayList)273 StringWriter (java.io.StringWriter)251 Tokenizer (org.apache.lucene.analysis.Tokenizer)241 Document (org.w3c.dom.Document)232 JSONReader (com.alibaba.fastjson.JSONReader)195 DocumentBuilder (javax.xml.parsers.DocumentBuilder)180 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)157 Map (java.util.Map)144 HashMap (java.util.HashMap)136 Element (org.w3c.dom.Element)134 StreamSource (javax.xml.transform.stream.StreamSource)132 ParserResult (org.jabref.logic.importer.ParserResult)130 MockTokenizer (org.apache.lucene.analysis.MockTokenizer)120