Search in sources :

Example 91 with Reader

use of java.io.Reader in project OpenGrok by OpenGrok.

the class TroffAnalyzer method analyze.

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
    //this is to explicitely use appropriate analyzers tokenstream to workaround #1376 symbols search works like full text search 
    this.SymbolTokenizer.setReader(getReader(src.getStream()));
    TextField full = new TextField(QueryBuilder.FULL, SymbolTokenizer);
    doc.add(full);
    if (xrefOut != null) {
        try (Reader in = getReader(src.getStream())) {
            writeXref(in, xrefOut);
        }
    }
}
Also used : TextField(org.apache.lucene.document.TextField) Reader(java.io.Reader)

Example 92 with Reader

use of java.io.Reader in project OpenGrok by OpenGrok.

the class UuencodeAnalyzer method analyze.

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
    //this is to explicitely use appropriate analyzers tokenstream to workaround #1376 symbols search works like full text search 
    TextField full = new TextField(QueryBuilder.FULL, SymbolTokenizer);
    this.SymbolTokenizer.setReader(getReader(src.getStream()));
    doc.add(full);
    if (xrefOut != null) {
        try (Reader in = getReader(src.getStream())) {
            writeXref(in, xrefOut);
        }
    }
}
Also used : TextField(org.apache.lucene.document.TextField) Reader(java.io.Reader)

Example 93 with Reader

use of java.io.Reader in project OpenGrok by OpenGrok.

the class CVSRepositoryTest method testParseAnnotation.

/**
     * Test of parseAnnotation method, of class CVSRepository.
     * @throws java.lang.Exception
     */
@Test
public void testParseAnnotation() throws Exception {
    String revId1 = "1.1";
    String revId2 = "1.2.3";
    String revId3 = "1.0";
    String author1 = "author1";
    String author2 = "author_long2";
    String author3 = "author3";
    String output = "just jibberish in output\n\n" + revId1 + "     (" + author1 + " 01-Mar-07) \n" + revId2 + "    (" + author2 + " 02-Mar-08)   if (some code)\n" + revId3 + "       (" + author3 + " 30-Apr-07)           call_function(i);\n";
    Reader input = new StringReader(output);
    String fileName = "something.ext";
    Annotation result = instance.parseAnnotation(input, fileName);
    assertNotNull(result);
    assertEquals(3, result.size());
    for (int i = 1; i <= 3; i++) {
        assertEquals(true, result.isEnabled(i));
    }
    assertEquals(revId1, result.getRevision(1));
    assertEquals(revId2, result.getRevision(2));
    assertEquals(revId3, result.getRevision(3));
    assertEquals(author1, result.getAuthor(1));
    assertEquals(author2, result.getAuthor(2));
    assertEquals(author3, result.getAuthor(3));
    assertEquals(author2.length(), result.getWidestAuthor());
    assertEquals(revId2.length(), result.getWidestRevision());
    assertEquals(fileName, result.getFilename());
}
Also used : StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) Test(org.junit.Test)

Example 94 with Reader

use of java.io.Reader in project OpenGrok by OpenGrok.

the class ExpandTabsReaderTest method testExpandTabs.

/**
     * Test that tabs are expanded to spaces.
     */
@Test
public void testExpandTabs() throws IOException {
    // Create a couple of lines to see if tabs are expanded as expected.
    String inputLine = "abc\tdef\t\t12345678\t1\t1234567\tabc";
    StringBuilder input = new StringBuilder();
    input.append(inputLine).append('\n');
    input.append(inputLine).append('\r');
    input.append('\t');
    // Create Reader that reads the test input.
    StringReader sr = new StringReader(input.toString());
    // Wrap the input in an ExpandTabsReader with tab size 8.
    Reader expandedInput = new ExpandTabsReader(sr, 8);
    // Here's what inputLine should be expanded to.
    String expectedLine = "abc     def             12345678        1       1234567 abc";
    // Verify that tabs are expanded.
    BufferedReader br = new BufferedReader(expandedInput);
    assertEquals(expectedLine, br.readLine());
    assertEquals(expectedLine, br.readLine());
    assertEquals("        ", br.readLine());
    assertNull(br.readLine());
}
Also used : StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) Test(org.junit.Test)

Example 95 with Reader

use of java.io.Reader in project OpenGrok by OpenGrok.

the class JFlexXrefTest method bug15890Anchor.

/**
     * Helper method for {@link #testBug15890Anchor()}.
     *
     * @param klass the Xref sub-class to test
     * @param path path to input file with a definition
     */
private void bug15890Anchor(Class<? extends JFlexXref> klass, String path) throws Exception {
    File file = new File(repository.getSourceRoot() + File.separator + path);
    Definitions defs = ctags.doCtags(file.getAbsolutePath() + "\n");
    // Input files contain non-ascii characters and are encoded in UTF-8
    Reader in = new InputStreamReader(new FileInputStream(file), "UTF-8");
    JFlexXref xref = klass.getConstructor(Reader.class).newInstance(in);
    xref.setDefs(defs);
    StringWriter out = new StringWriter();
    xref.write(out);
    //TODO improve below to reflect all possible classes of a definition
    assertTrue("No anchor found", out.toString().contains("\" name=\"bug15890\"/><a href="));
}
Also used : InputStreamReader(java.io.InputStreamReader) StringWriter(java.io.StringWriter) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

Reader (java.io.Reader)1498 InputStreamReader (java.io.InputStreamReader)526 StringReader (java.io.StringReader)498 IOException (java.io.IOException)348 BufferedReader (java.io.BufferedReader)242 InputStream (java.io.InputStream)219 TokenStream (org.apache.lucene.analysis.TokenStream)171 Test (org.junit.Test)170 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)159 Connection (java.sql.Connection)137 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)126 FileReader (java.io.FileReader)108 FileInputStream (java.io.FileInputStream)107 File (java.io.File)105 BeforeClass (org.junit.BeforeClass)99 Tokenizer (org.apache.lucene.analysis.Tokenizer)91 SqlSession (org.apache.ibatis.session.SqlSession)83 StringWriter (java.io.StringWriter)81 ArrayList (java.util.ArrayList)77 Writer (java.io.Writer)63