java.io.CharArrayReader Java Examples

The following examples show how to use java.io.CharArrayReader. 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 Project: openjdk-8   Author: bpupadhyaya   File: bug8005391.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
Example #2
Source Project: jdk8u_jdk   Author: JetBrains   File: OverflowInSkip.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    char[] a = "_123456789_123456789_123456789_123456789"
            .toCharArray(); // a.length > 33
    try (CharArrayReader car = new CharArrayReader(a)) {
        long small = 33;
        long big = Long.MAX_VALUE;

        long smallSkip = car.skip(small);
        if (smallSkip != small)
            throw new Exception("Expected to skip " + small
                    + " chars, but skipped " + smallSkip);

        long expSkip = a.length - small;
        long bigSkip = car.skip(big);
        if (bigSkip != expSkip)
            throw new Exception("Expected to skip " + expSkip
                    + " chars, but skipped " + bigSkip);
    }
}
 
Example #3
Source Project: dragonwell8_jdk   Author: alibaba   File: OverflowInRead.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    char[] a = "_123456789_123456789_123456789_123456789"
            .toCharArray(); // a.length > 33
    try (CharArrayReader car = new CharArrayReader(a)) {
        int len1 = 33;
        char[] buf1 = new char[len1];
        if (car.read(buf1, 0, len1) != len1)
            throw new Exception("Expected to read " + len1 + " chars");

        int len2 = Integer.MAX_VALUE - 32;
        char[] buf2 = new char[len2];
        int expLen2 = a.length - len1;
        if (car.read(buf2, 0, len2) != expLen2)
            throw new Exception("Expected to read " + expLen2 + " chars");
    }
}
 
Example #4
Source Project: j2objc   Author: google   File: OldCharArrayReaderTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * java.io.CharArrayReader#mark(int)
 */
public void test_markI() throws IOException {
    cr = new CharArrayReader(hw);
    cr.skip(5L);
    cr.mark(100);
    cr.read();
    cr.reset();
    assertEquals("Test 1: Failed to mark correct position;",
            'W', cr.read());

    cr.close();
    try {
        cr.mark(100);
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
        // Expected.
    }
}
 
Example #5
Source Project: jTDS   Author: milesibastos   File: Tds5Test.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test writing unitext data from Reader
 */
public void testStreamUniText() throws Exception {
    if (!isVersion15orHigher()) {
        return;
    }
    Statement stmt = con.createStatement();
    stmt.execute("CREATE TABLE #TESTTR (id int, txt unitext)");
    char data[] = new char[20000];
    for (int i = 0; i < data.length; i++) {
        data[i] = (char)('A' + (i % 10));
    }
    data[data.length-1] = '\u0441'; // Force unicode
    PreparedStatement pstmt = con.prepareStatement(
        "INSERT INTO #TESTTR VALUES(?,?)");
    pstmt.setInt(1, 1);
    pstmt.setCharacterStream(2, new CharArrayReader(data), data.length);
    assertEquals(1, pstmt.executeUpdate());
    ResultSet rs = stmt.executeQuery("SELECT * FROM #TESTTR");
    assertNotNull(rs);
    assertTrue(rs.next());
    assertEquals(new String(data), rs.getString(2));
    pstmt.close();
    stmt.close();
}
 
Example #6
Source Project: jdk8u60   Author: chenghanpeng   File: bug8005391.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
Example #7
Source Project: lucene-solr   Author: apache   File: XSLTResponseWriter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse response) throws IOException {
  final Transformer t = getTransformer(request);
  
  // capture the output of the XMLWriter
  final CharArrayWriter w = new CharArrayWriter();
  XMLWriter.writeResponse(w,request,response);
  
  // and write transformed result to our writer
  final Reader r = new BufferedReader(new CharArrayReader(w.toCharArray()));
  final StreamSource source = new StreamSource(r);
  final StreamResult result = new StreamResult(writer);
  try {
    t.transform(source, result);
  } catch(TransformerException te) {
    throw new IOException("XSLT transformation error", te);
  }
}
 
Example #8
Source Project: netbeans   Author: apache   File: FileBackedClobTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTruncate() throws Exception {
    FileBackedClob c;
    c = new FileBackedClob(new CharArrayReader(testCase1));
    c.truncate(5);
    assertEquals(c.length(), 5);
    assertEquals(c.getBackingFile().length(), 5 * 4);
    c.free();
    c = new FileBackedClob(new String(testCase2));
    c.truncate(42);
    assertEquals(c.length(), 42);
    assertEquals(c.getBackingFile().length(), 42 * 4);
    c.free();
    c = new FileBackedClob(new CharArrayReader(testCase3));
    c.truncate(1024);
    assertEquals(c.length(), 1024);
    assertEquals(c.getBackingFile().length(), 1024 * 4);
    c.free();
}
 
Example #9
Source Project: netbeans   Author: apache   File: FileBackedClobTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetSubString() throws Exception {
    FileBackedClob c;
    char[] referenceChars = new char[5];
    System.arraycopy(testCase1, 5, referenceChars, 0, 5);
    String reference = new String(referenceChars);
    c = new FileBackedClob(new CharArrayReader(testCase1));
    assertEquals(reference, c.getSubString(6, 5));
    c.free();
    c = new FileBackedClob(new String(testCase2));
    assertEquals( reference, c.getSubString(6, 5));
    c.free();
    c = new FileBackedClob(new CharArrayReader(testCase3));
    assertEquals(reference, c.getSubString(6, 5));
    c.free();
}
 
Example #10
Source Project: netbeans   Author: apache   File: FileBackedClobTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSetString_long_String() throws Exception {
    FileBackedClob b;
    char[] test1 = "test".toCharArray();
    char[] test2 = "test0123456789".toCharArray();
    char[] firstPartReference = new char[testCase2.length - test1.length - 4];
    char[] secondPartReference = new char[4];
    System.arraycopy(testCase2, 0, firstPartReference, 0, testCase2.length - test1.length - 4);
    System.arraycopy(testCase2, testCase2.length - 4 - 1, secondPartReference, 0, 4);
    b = new FileBackedClob(new CharArrayReader(testCase2));
    b.setString(testCase2.length - test1.length - 4 + 1, new String(test1));
    assertEquals(new String(firstPartReference), b.getSubString(1, testCase2.length - test1.length - 4));
    assertEquals(new String(secondPartReference), b.getSubString(testCase2.length - 4, 4));
    assertEquals(new String(test1), b.getSubString(testCase2.length - 4 - test1.length + 1, test1.length));
    assertEquals(b.length(), 1024);
    b.setString(testCase2.length - test1.length - 4 + 1, new String(test2));
    assertEquals(new String(firstPartReference), b.getSubString(1, testCase2.length - test1.length - 4));
    assertEquals(b.length(), 1024 - test1.length - 4 + test2.length);
    assertEquals(new String(test2), b.getSubString(b.length() - test2.length + 1, test2.length));
    b.free();
}
 
Example #11
Source Project: netbeans   Author: apache   File: FileBackedClobTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSetCharacterStream() throws Exception {
    FileBackedClob b;
    char[] test1 = "test".toCharArray();
    char[] test2 = "test0123456789".toCharArray();
    char[] firstPartReference = new char[testCase2.length - test1.length - 4];
    char[] secondPartReference = new char[4];
    System.arraycopy(testCase2, 0, firstPartReference, 0, testCase2.length - test1.length - 4);
    System.arraycopy(testCase2, testCase2.length - 4 - 1, secondPartReference, 0, 4);
    b = new FileBackedClob(new CharArrayReader(testCase2));
    Writer os = b.setCharacterStream(testCase2.length - test1.length - 4 + 1);
    os.write(test1);
    os.close();
    assertEquals(new String(firstPartReference), b.getSubString(1, testCase2.length - test1.length - 4));
    assertEquals(new String(secondPartReference), b.getSubString(testCase2.length - 4, 4));
    assertEquals(new String(test1), b.getSubString(testCase2.length - 4 - test1.length + 1, test1.length));
    assertEquals(b.length(), 1024);
    os = b.setCharacterStream(testCase2.length - test1.length - 4 + 1);
    os.write(test2);
    os.close();
    assertEquals(new String(firstPartReference), b.getSubString(1, testCase2.length - test1.length - 4));
    assertEquals(b.length(), 1024 - test1.length - 4 + test2.length);
    assertEquals(new String(test2), b.getSubString(b.length() - test2.length + 1, test2.length));
    b.free();
}
 
Example #12
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: OverflowInSkip.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    char[] a = "_123456789_123456789_123456789_123456789"
            .toCharArray(); // a.length > 33
    try (CharArrayReader car = new CharArrayReader(a)) {
        long small = 33;
        long big = Long.MAX_VALUE;

        long smallSkip = car.skip(small);
        if (smallSkip != small)
            throw new Exception("Expected to skip " + small
                    + " chars, but skipped " + smallSkip);

        long expSkip = a.length - small;
        long bigSkip = car.skip(big);
        if (bigSkip != expSkip)
            throw new Exception("Expected to skip " + expSkip
                    + " chars, but skipped " + bigSkip);
    }
}
 
Example #13
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: bug8005391.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
Example #14
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: OverflowInSkip.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    char[] a = "_123456789_123456789_123456789_123456789"
            .toCharArray(); // a.length > 33
    try (CharArrayReader car = new CharArrayReader(a)) {
        long small = 33;
        long big = Long.MAX_VALUE;

        long smallSkip = car.skip(small);
        if (smallSkip != small)
            throw new Exception("Expected to skip " + small
                    + " chars, but skipped " + smallSkip);

        long expSkip = a.length - small;
        long bigSkip = car.skip(big);
        if (bigSkip != expSkip)
            throw new Exception("Expected to skip " + expSkip
                    + " chars, but skipped " + bigSkip);
    }
}
 
Example #15
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: bug8005391.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
Example #16
Source Project: j2objc   Author: google   File: OldCharArrayReaderTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * java.io.CharArrayReader#reset()
 */
public void test_reset() throws IOException {
    cr = new CharArrayReader(hw);
    cr.skip(5L);
    cr.mark(100);
    cr.read();
    cr.reset();
    assertEquals("Test 1: Reset failed to return to marker position.",
            'W', cr.read());

    cr.close();
    try {
        cr.reset();
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
        // Expected.
    }
}
 
Example #17
Source Project: SearchServices   Author: Alfresco   File: CompositeReaderTest.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void threeWrappedReaders() throws IOException
{
    List<String> chunks =
            asList("This is the",
                    " whole string content ",
                    " we are expecting as final result.");

    String expected = String.join("", chunks);

    Reader [] readers =
            chunks.stream()
                .map(String::toCharArray)
                .map(CharArrayReader::new)
                .toArray(CharArrayReader[]::new);

    try(CompositeReader classUnderTest = new CompositeReader(readers))
    {
        assertEquals(expected, IOUtils.toString(classUnderTest));
    }
}
 
Example #18
Source Project: hottub   Author: dsrg-uoft   File: bug8005391.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
Example #19
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: OverflowInRead.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    char[] a = "_123456789_123456789_123456789_123456789"
            .toCharArray(); // a.length > 33
    try (CharArrayReader car = new CharArrayReader(a)) {
        int len1 = 33;
        char[] buf1 = new char[len1];
        if (car.read(buf1, 0, len1) != len1)
            throw new Exception("Expected to read " + len1 + " chars");

        int len2 = Integer.MAX_VALUE - 32;
        char[] buf2 = new char[len2];
        int expLen2 = a.length - len1;
        if (car.read(buf2, 0, len2) != expLen2)
            throw new Exception("Expected to read " + expLen2 + " chars");
    }
}
 
Example #20
Source Project: gson   Author: google   File: JsonParserTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testReadWriteTwoObjects() throws Exception {
  Gson gson = new Gson();
  CharArrayWriter writer = new CharArrayWriter();
  BagOfPrimitives expectedOne = new BagOfPrimitives(1, 1, true, "one");
  writer.write(gson.toJson(expectedOne).toCharArray());
  BagOfPrimitives expectedTwo = new BagOfPrimitives(2, 2, false, "two");
  writer.write(gson.toJson(expectedTwo).toCharArray());
  CharArrayReader reader = new CharArrayReader(writer.toCharArray());

  JsonReader parser = new JsonReader(reader);
  parser.setLenient(true);
  JsonElement element1 = Streams.parse(parser);
  JsonElement element2 = Streams.parse(parser);
  BagOfPrimitives actualOne = gson.fromJson(element1, BagOfPrimitives.class);
  assertEquals("one", actualOne.stringValue);
  BagOfPrimitives actualTwo = gson.fromJson(element2, BagOfPrimitives.class);
  assertEquals("two", actualTwo.stringValue);
}
 
Example #21
Source Project: eosio-java   Author: EOSIO   File: PEMProcessor.java    License: MIT License 5 votes vote down vote up
/**
 * Initialize PEMProcessor with PEM content in String format.
 *
 * @param pemObject - input PEM content in String format.
 * @throws PEMProcessorError When failing to read pem data from the input.
 */
public PEMProcessor(String pemObject) throws PEMProcessorError {
    this.pemObjectString = pemObject;
    try (Reader reader = new CharArrayReader(this.pemObjectString.toCharArray());
            PemReader pemReader = new PemReader(reader)) {
        this.pemObject = pemReader.readPemObject();
        if (this.pemObject == null) {
            throw new PEMProcessorError(ErrorConstants.INVALID_PEM_OBJECT);
        }

    } catch (Exception e) {
        throw new PEMProcessorError(ErrorConstants.ERROR_PARSING_PEM_OBJECT, e);
    }

}
 
Example #22
Source Project: cxf   Author: apache   File: CachedWriter.java    License: Apache License 2.0 5 votes vote down vote up
public Reader getReader() throws IOException {
    flush();
    if (inmem) {
        if (currentStream instanceof LoadingCharArrayWriter) {
            LoadingCharArrayWriter lcaw = (LoadingCharArrayWriter)currentStream;
            return new CharArrayReader(lcaw.rawCharArray(), 0, lcaw.size());
        }
        return null;
    }
    try {
        InputStream fileInputStream = new FileInputStream(tempFile) {
            boolean closed;
            public void close() throws IOException {
                if (!closed) {
                    super.close();
                    maybeDeleteTempFile(this);
                }
                closed = true;
            }
        };
        streamList.add(fileInputStream);
        if (cipherTransformation != null) {
            fileInputStream = new CipherInputStream(fileInputStream, ciphers.getDecryptor()) {
                boolean closed;
                public void close() throws IOException {
                    if (!closed) {
                        super.close();
                        closed = true;
                    }
                }
            };
        }
        return new InputStreamReader(fileInputStream, StandardCharsets.UTF_8);
    } catch (FileNotFoundException e) {
        throw new IOException("Cached file was deleted, " + e.toString());
    }
}
 
Example #23
Source Project: gson   Author: google   File: ParseBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
public void parse(char[] data, Document document) throws Exception {
  JsonFactory jsonFactory = new JsonFactory();
  org.codehaus.jackson.JsonParser jp = jsonFactory.createJsonParser(new CharArrayReader(data));
  jp.configure(org.codehaus.jackson.JsonParser.Feature.CANONICALIZE_FIELD_NAMES, false);
  int depth = 0;
  do {
    switch (jp.nextToken()) {
    case START_OBJECT:
    case START_ARRAY:
      depth++;
      break;
    case END_OBJECT:
    case END_ARRAY:
      depth--;
      break;
    case FIELD_NAME:
      jp.getCurrentName();
      break;
    case VALUE_STRING:
      jp.getText();
      break;
    case VALUE_NUMBER_INT:
    case VALUE_NUMBER_FLOAT:
      jp.getLongValue();
      break;
    }
  } while (depth > 0);
  jp.close();
}
 
Example #24
Source Project: Pydev   Author: fabioz   File: REFTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void testHasPythonShebang2() {
    String s = "" +
            "#!python2\n" +
            "\n" +
            "";
    CharArrayReader reader = new CharArrayReader(s.toCharArray());
    assertTrue(FileUtils.hasPythonShebang(reader));
}
 
Example #25
Source Project: luaj   Author: luaj   File: ScriptEngineTests.java    License: MIT License 5 votes vote down vote up
public void testScriptRedirection() throws ScriptException {
          Reader input = new CharArrayReader("abcdefg\nhijk".toCharArray());
          CharArrayWriter output = new CharArrayWriter();
          CharArrayWriter errors = new CharArrayWriter();
          String script = 
          		"print(\"string written using 'print'\")\n" +
          		"io.write(\"string written using 'io.write()'\\n\")\n" +
          		"io.stdout:write(\"string written using 'io.stdout:write()'\\n\")\n" +
          		"io.stderr:write(\"string written using 'io.stderr:write()'\\n\")\n" +
          		"io.write([[string read using 'io.stdin:read(\"*l\")':]]..io.stdin:read(\"*l\")..\"\\n\")\n";

          // Evaluate script with redirection set
          e.getContext().setReader(input);
          e.getContext().setWriter(output);
          e.getContext().setErrorWriter(errors);
          e.eval(script);
          final String expectedOutput = "string written using 'print'\n"+
          		"string written using 'io.write()'\n"+
          		"string written using 'io.stdout:write()'\n"+
          		"string read using 'io.stdin:read(\"*l\")':abcdefg\n";
          assertEquals(expectedOutput, output.toString());
          final String expectedErrors = "string written using 'io.stderr:write()'\n";
          assertEquals(expectedErrors, errors.toString());

          // Evaluate script with redirection reset
          output.reset();
          errors.reset();
          // e.getContext().setReader(null); // This will block if using actual STDIN
          e.getContext().setWriter(null);
          e.getContext().setErrorWriter(null);
          e.eval(script);
          assertEquals("", output.toString());
          assertEquals("", errors.toString());			
}
 
Example #26
Source Project: unitime   Author: UniTime   File: XmlClobType.java    License: Apache License 2.0 5 votes vote down vote up
public void nullSafeSet(PreparedStatement ps, Object value, int index, SessionImplementor session) throws SQLException, HibernateException {
    if (value == null) {
        ps.setNull(index, sqlTypes()[0]);
    } else {
        try {
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            XMLWriter writer = new XMLWriter(bytes,OutputFormat.createCompactFormat());
            writer.write((Document)value);
            writer.flush(); writer.close();
            ps.setCharacterStream(index, new CharArrayReader(bytes.toString().toCharArray(),0,bytes.size()), bytes.size());
        } catch (IOException e) {
            throw new HibernateException(e.getMessage(),e);
        }
    }
}
 
Example #27
Source Project: maven-native   Author: mojohaus   File: CParserTest.java    License: MIT License 5 votes vote down vote up
/**
 * Checks parsing of #include foo.h.
 *
 * @throws IOException test fails on IOException
 */
public void testNoQuoteOrBracket()
    throws IOException
{
    CharArrayReader reader = new CharArrayReader( "#include foo.h  ".toCharArray() );
    CParser parser = new CParser();
    parser.parse( reader );
    String[] includes = parser.getIncludes();
    assertEquals( includes.length, 0 );
}
 
Example #28
Source Project: chuidiang-ejemplos   Author: chuidiang   File: PruebaCorrelacionIdiomas.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private void analizaTextoYExtraeResultados()
{
    String texto = areaDeTextoAAnalizar.getText();
    CharArrayReader stream = new CharArrayReader(texto.toCharArray());
    PorcentajeCorrelacion[] porcentajes = correlador.analizaIdioma(stream);
    areaResultados.setText("");

    for (int i = porcentajes.length - 1; i >= 0; i--)
    {
        areaResultados.append(porcentajes[i] + "\n");
    }
}
 
Example #29
Source Project: elexis-3-core   Author: elexis   File: SoapConverter.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public boolean load(String input){
	SAXBuilder builder = new SAXBuilder();
	try {
		CharArrayReader car = new CharArrayReader(input.toCharArray());
		doc = builder.build(car);
		eRoot = doc.getRootElement();
		bValid = true;
	} catch (Exception e) {
		ExHandler.handle(e);
		bValid = false;
	}
	return bValid;
	
}
 
Example #30
Source Project: Pydev   Author: fabioz   File: REFTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void testHasPythonShebang1() {
    String s = "" +
            "#!python\n" +
            "\n" +
            "";
    CharArrayReader reader = new CharArrayReader(s.toCharArray());
    assertTrue(FileUtils.hasPythonShebang(reader));
}