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 File: JsonParserTest.java From gson with Apache License 2.0 | 6 votes |
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 #2
Source File: OverflowInRead.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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 #3
Source File: OverflowInSkip.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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 #4
Source File: OldCharArrayReaderTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * 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 File: Tds5Test.java From jTDS with GNU Lesser General Public License v2.1 | 6 votes |
/** * 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 File: bug8005391.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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 File: XSLTResponseWriter.java From lucene-solr with Apache License 2.0 | 6 votes |
@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 File: FileBackedClobTest.java From netbeans with Apache License 2.0 | 6 votes |
@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 File: FileBackedClobTest.java From netbeans with Apache License 2.0 | 6 votes |
@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 File: FileBackedClobTest.java From netbeans with Apache License 2.0 | 6 votes |
@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 File: OverflowInSkip.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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 #12
Source File: bug8005391.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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 #13
Source File: OverflowInSkip.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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 #14
Source File: bug8005391.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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 #15
Source File: OldCharArrayReaderTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * 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 #16
Source File: CompositeReaderTest.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
@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 #17
Source File: bug8005391.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
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 #18
Source File: bug8005391.java From hottub with GNU General Public License v2.0 | 6 votes |
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 File: FileBackedClobTest.java From netbeans with Apache License 2.0 | 6 votes |
@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 #20
Source File: OverflowInRead.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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 #21
Source File: DriverManagerTests.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Create a PrintWriter and use to to send output via DriverManager.println * Validate that if you disable the writer, the output sent is not present */ @Test public void tests18() throws Exception { CharArrayWriter cw = new CharArrayWriter(); PrintWriter pw = new PrintWriter(cw); DriverManager.setLogWriter(pw); assertTrue(DriverManager.getLogWriter() == pw); DriverManager.println(results[0]); DriverManager.setLogWriter(null); assertTrue(DriverManager.getLogWriter() == null); DriverManager.println(noOutput); DriverManager.setLogWriter(pw); DriverManager.println(results[1]); DriverManager.println(results[2]); DriverManager.println(results[3]); DriverManager.setLogWriter(null); DriverManager.println(noOutput); /* * Check we do not get the output when the stream is disabled */ BufferedReader reader = new BufferedReader(new CharArrayReader(cw.toCharArray())); for (String result : results) { assertTrue(result.equals(reader.readLine())); } }
Example #22
Source File: Parser.java From big-c with Apache License 2.0 | 5 votes |
Lexer(String s) { tok = new StreamTokenizer(new CharArrayReader(s.toCharArray())); tok.quoteChar('"'); tok.parseNumbers(); tok.ordinaryChar(','); tok.ordinaryChar('('); tok.ordinaryChar(')'); tok.wordChars('$','$'); tok.wordChars('_','_'); }
Example #23
Source File: DriverManagerTests.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Create a PrintWriter and use to to send output via DriverManager.println * Validate that if you disable the writer, the output sent is not present */ @Test public void tests18() throws Exception { CharArrayWriter cw = new CharArrayWriter(); PrintWriter pw = new PrintWriter(cw); DriverManager.setLogWriter(pw); assertTrue(DriverManager.getLogWriter() == pw); DriverManager.println(results[0]); DriverManager.setLogWriter(null); assertTrue(DriverManager.getLogWriter() == null); DriverManager.println(noOutput); DriverManager.setLogWriter(pw); DriverManager.println(results[1]); DriverManager.println(results[2]); DriverManager.println(results[3]); DriverManager.setLogWriter(null); DriverManager.println(noOutput); /* * Check we do not get the output when the stream is disabled */ BufferedReader reader = new BufferedReader(new CharArrayReader(cw.toCharArray())); for (String result : results) { assertTrue(result.equals(reader.readLine())); } }
Example #24
Source File: NetconfSessionMinaImpl.java From onos with Apache License 2.0 | 5 votes |
@Deprecated private void startSession() throws IOException { final ConnectFuture connectFuture; connectFuture = client.connect(deviceInfo.name(), deviceInfo.ip().toString(), deviceInfo.port()) .verify(connectTimeout, TimeUnit.SECONDS); session = connectFuture.getSession(); //Using the device ssh key if possible if (deviceInfo.getKey() != null) { try (PEMParser pemParser = new PEMParser(new CharArrayReader(deviceInfo.getKey()))) { JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME); try { KeyPair kp = converter.getKeyPair((PEMKeyPair) pemParser.readObject()); session.addPublicKeyIdentity(kp); } catch (IOException e) { throw new NetconfException("Failed to authenticate session with device " + deviceInfo + "check key to be a valid key", e); } } } else { session.addPasswordIdentity(deviceInfo.password()); } session.auth().verify(connectTimeout, TimeUnit.SECONDS); Set<ClientSession.ClientSessionEvent> event = session.waitFor( ImmutableSet.of(ClientSession.ClientSessionEvent.WAIT_AUTH, ClientSession.ClientSessionEvent.CLOSED, ClientSession.ClientSessionEvent.AUTHED), 0); if (!event.contains(ClientSession.ClientSessionEvent.AUTHED)) { log.debug("Session closed {} {}", event, session.isClosed()); throw new NetconfException("Failed to authenticate session with device " + deviceInfo + "check the user/pwd or key"); } openChannel(); }
Example #25
Source File: DataDeserializer.java From hj-t212-parser with Apache License 2.0 | 5 votes |
public Data deserialize(char[] data) throws IOException, T212FormatException { PushbackReader reader = new PushbackReader(new CharArrayReader(data)); SegmentParser parser = new SegmentParser(reader); parser.configured(segmentParserConfigurator); Map<String,Object> result = null; try { result = segmentDeserializer.deserialize(parser); } catch (SegmentFormatException e) { T212FormatException.segment_exception(e); } return deserialize(result); }
Example #26
Source File: LogUtils.java From teamengine with Apache License 2.0 | 5 votes |
public static XdmNode getContextFromLog( net.sf.saxon.s9api.DocumentBuilder builder, Document log) throws Exception { Element starttest = (Element) log.getElementsByTagName("starttest") .item(0); NodeList nl = starttest.getElementsByTagName("context"); if (nl == null || nl.getLength() == 0) { return null; } else { Element context = (Element) nl.item(0); Element value = (Element) context.getElementsByTagName("value") .item(0); nl = value.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (n.getNodeType() == Node.ATTRIBUTE_NODE) { String s = DomUtils.serializeNode(value); XdmNode xn = builder.build(new StreamSource( new CharArrayReader(s.toCharArray()))); return (XdmNode) xn.axisIterator(Axis.ATTRIBUTE).next(); } else if (n.getNodeType() == Node.ELEMENT_NODE) { Document doc = DomUtils.createDocument(n); return builder.build(new DOMSource(doc)); } } } return null; }
Example #27
Source File: FileBackedClobTest.java From netbeans with Apache License 2.0 | 5 votes |
@Test public void testFree() throws Exception { FileBackedClob b; b = new FileBackedClob(new CharArrayReader(testCase2)); assertTrue(b.getBackingFile().exists()); b.free(); assertFalse(b.getBackingFile().exists()); }
Example #28
Source File: FileBackedClobTest.java From netbeans with Apache License 2.0 | 5 votes |
@Test public void testFinalize() throws Exception { FileBackedClob b; b = new FileBackedClob(new CharArrayReader(testCase2)); assertTrue(b.getBackingFile().exists()); try { b.finalize(); } catch (Throwable ex) { Exceptions.printStackTrace(ex); } assertFalse(b.getBackingFile().exists()); }
Example #29
Source File: CParserTest.java From maven-native with MIT License | 5 votes |
/** * Checks parsing of #import "foo.h. * * @throws IOException test fails on IOException */ public void testIncompleteImmediateImportQuote() throws IOException { CharArrayReader reader = new CharArrayReader( "#import \"foo.h ".toCharArray() ); CParser parser = new CParser(); parser.parse( reader ); String[] includes = parser.getIncludes(); assertEquals( includes.length, 0 ); }
Example #30
Source File: CParserTest.java From maven-native with MIT License | 5 votes |
/** * Checks parsing of #include "foo.h. * * @throws IOException test fails on IOException */ public void testIncompleteImmediateIncludeQuote() 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 ); }