Search in sources :

Example 96 with Reader

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

the class JFlexXrefTest method bug18586.

@Test
public void bug18586() throws IOException {
    String filename = repository.getSourceRoot() + "/sql/bug18586.sql";
    Reader in = new InputStreamReader(new FileInputStream(filename), "UTF-8");
    SQLXref xref = new SQLXref(in);
    xref.setDefs(ctags.doCtags(filename + "\n"));
    // The next call used to fail with an ArrayIndexOutOfBoundsException.
    xref.write(new StringWriter());
}
Also used : InputStreamReader(java.io.InputStreamReader) StringWriter(java.io.StringWriter) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) FileInputStream(java.io.FileInputStream) SQLXref(org.opensolaris.opengrok.analysis.sql.SQLXref) Test(org.junit.Test)

Example 97 with Reader

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

the class ContextTest method testLongLineNearBufferBoundary.

/**
     * Test that we don't get an {@code ArrayIndexOutOfBoundsException} when a
     * long (>100 characters) line which contains a match is not terminated
     * with a newline character before the buffer boundary. Bug #383.
     *
     * @throws org.apache.lucene.queryparser.classic.ParseException
     */
@Test
public void testLongLineNearBufferBoundary() throws ParseException {
    char[] chars = new char[Context.MAXFILEREAD];
    Arrays.fill(chars, 'a');
    char[] substring = " this is a test ".toCharArray();
    System.arraycopy(substring, 0, chars, Context.MAXFILEREAD - substring.length, substring.length);
    Reader in = new CharArrayReader(chars);
    QueryBuilder qb = new QueryBuilder().setFreetext("test");
    Context c = new Context(qb.build(), qb.getQueries());
    StringWriter out = new StringWriter();
    boolean match = c.getContext(in, out, "", "", "", null, true, qb.isDefSearch(), null);
    assertTrue("No match found", match);
    String s = out.toString();
    assertTrue("Match not written to Writer", s.contains(" this is a <b>test</b>"));
    assertTrue("No match on line #1", s.contains("href=\"#1\""));
}
Also used : CharArrayReader(java.io.CharArrayReader) StringWriter(java.io.StringWriter) CharArrayReader(java.io.CharArrayReader) Reader(java.io.Reader) StringReader(java.io.StringReader) QueryBuilder(org.opensolaris.opengrok.search.QueryBuilder) Test(org.junit.Test)

Example 98 with Reader

use of java.io.Reader in project druid by alibaba.

the class EncodingConvertFilter method clob_getCharacterStream.

@Override
public Reader clob_getCharacterStream(FilterChain chain, ClobProxy wrapper, long pos, long length) throws SQLException {
    Reader reader = super.clob_getCharacterStream(chain, wrapper, pos, length);
    String text = Utils.read(reader);
    return new StringReader(decode(wrapper.getConnectionWrapper(), text));
}
Also used : StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader)

Example 99 with Reader

use of java.io.Reader in project druid by alibaba.

the class EncodingConvertFilter method callableStatement_setCharacterStream.

@Override
public void callableStatement_setCharacterStream(FilterChain chain, CallableStatementProxy statement, String parameterName, java.io.Reader reader, int length) throws SQLException {
    String text = Utils.read(reader, length);
    String encodeText = encode(statement.getConnectionProxy(), text);
    Reader encodeReader = new StringReader(encodeText);
    super.callableStatement_setCharacterStream(chain, statement, parameterName, encodeReader, encodeText.length());
}
Also used : StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader)

Example 100 with Reader

use of java.io.Reader in project druid by alibaba.

the class EncodingConvertFilter method callableStatement_setCharacterStream.

// ///////////// callableStatement_
@Override
public void callableStatement_setCharacterStream(FilterChain chain, CallableStatementProxy statement, String parameterName, java.io.Reader reader) throws SQLException {
    String text = Utils.read(reader);
    Reader encodeReader = new StringReader(encode(statement.getConnectionProxy(), text));
    super.callableStatement_setCharacterStream(chain, statement, parameterName, encodeReader);
}
Also used : StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader)

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