Java Code Examples for java.io.CharArrayWriter#flush()
The following examples show how to use
java.io.CharArrayWriter#flush() .
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: bug8005391.java From TencentKona-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 2
Source File: bug8005391.java From jdk8u-dev-jdk 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 3
Source File: bug8005391.java From jdk8u-jdk 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 4
Source File: bug8005391.java From jdk8u_jdk 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 5
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 6
Source File: bug8005391.java From openjdk-8-source 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: 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 8
Source File: bug8005391.java From jdk8u-jdk 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 9
Source File: HTMLEditorKitWriterBug.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) { String htmlDoc = "<pre><p> </pre>"; try { 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(); } catch (Exception ex) { throw new RuntimeException("Test Failed " + ex); } }
Example 10
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 11
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 12
Source File: bug8005391.java From openjdk-jdk8u 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: 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 14
Source File: bug8005391.java From dragonwell8_jdk 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: JRResultSetDataSource.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
protected CharArrayReader getArrayReader(Reader reader, long size) throws IOException { char[] buf = new char[8192]; CharArrayWriter bufWriter = new CharArrayWriter((size > 0) ? (int) size : 8192); BufferedReader bufReader = new BufferedReader(reader, 8192); for (int read = bufReader.read(buf); read > 0; read = bufReader.read(buf)) { bufWriter.write(buf, 0, read); } bufWriter.flush(); return new CharArrayReader(bufWriter.toCharArray()); }
Example 16
Source File: URLEncoder.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Translates a string into {@code application/x-www-form-urlencoded} * format using a specific {@linkplain java.nio.charset.Charset Charset}. * This method uses the supplied charset to obtain the bytes for unsafe * characters. * <p> * <em><strong>Note:</strong> The <a href= * "http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars"> * World Wide Web Consortium Recommendation</a> states that * UTF-8 should be used. Not doing so may introduce incompatibilities.</em> * * @param s {@code String} to be translated. * @param charset the given charset * @return the translated {@code String}. * @throws NullPointerException if {@code s} or {@code charset} is {@code null}. * @see URLDecoder#decode(java.lang.String, java.nio.charset.Charset) * @since 10 */ public static String encode(String s, Charset charset) { Objects.requireNonNull(charset, "charset"); boolean needToChange = false; StringBuilder out = new StringBuilder(s.length()); CharArrayWriter charArrayWriter = new CharArrayWriter(); for (int i = 0; i < s.length();) { int c = (int) s.charAt(i); //System.out.println("Examining character: " + c); if (dontNeedEncoding.get(c)) { if (c == ' ') { c = '+'; needToChange = true; } //System.out.println("Storing: " + c); out.append((char)c); i++; } else { // convert to external encoding before hex conversion do { charArrayWriter.write(c); /* * If this character represents the start of a Unicode * surrogate pair, then pass in two characters. It's not * clear what should be done if a byte reserved in the * surrogate pairs range occurs outside of a legal * surrogate pair. For now, just treat it as if it were * any other character. */ if (c >= 0xD800 && c <= 0xDBFF) { /* System.out.println(Integer.toHexString(c) + " is high surrogate"); */ if ( (i+1) < s.length()) { int d = (int) s.charAt(i+1); /* System.out.println("\tExamining " + Integer.toHexString(d)); */ if (d >= 0xDC00 && d <= 0xDFFF) { /* System.out.println("\t" + Integer.toHexString(d) + " is low surrogate"); */ charArrayWriter.write(d); i++; } } } i++; } while (i < s.length() && !dontNeedEncoding.get((c = (int) s.charAt(i)))); charArrayWriter.flush(); String str = new String(charArrayWriter.toCharArray()); byte[] ba = str.getBytes(charset); for (int j = 0; j < ba.length; j++) { out.append('%'); char ch = Character.forDigit((ba[j] >> 4) & 0xF, 16); // converting to use uppercase letter as part of // the hex value if ch is a letter. if (Character.isLetter(ch)) { ch -= caseDiff; } out.append(ch); ch = Character.forDigit(ba[j] & 0xF, 16); if (Character.isLetter(ch)) { ch -= caseDiff; } out.append(ch); } charArrayWriter.reset(); needToChange = true; } } return (needToChange? out.toString() : s); }
Example 17
Source File: URLEncoder.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
/** * Encode a string according to RFC 1738. * <p/> * <quote> "...Only alphanumerics [0-9a-zA-Z], the special characters "$-_.+!*'()," [not including the quotes - ed], * and reserved characters used for their reserved purposes may be used unencoded within a URL."</quote> * <p/> * <ul> <li><p>The ASCII characters 'a' through 'z', 'A' through 'Z', and '0' through '9' remain the same. * <p/> * <li><p>The unreserved characters - _ . ! ~ * ' ( ) remain the same. * <p/> * <li><p>All other ASCII characters are converted into the 3-character string "%xy", where xy is the two-digit * hexadecimal representation of the character code * <p/> * <li><p>All non-ASCII characters are encoded in two steps: first to a sequence of 2 or 3 bytes, using the UTF-8 * algorithm; secondly each of these bytes is encoded as "%xx". </ul> * <p/> * This method was adapted from http://www.w3.org/International/URLUTF8Encoder.java Licensed under * http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 * * @param s The string to be encoded * @return The encoded string */ public static String encode( final String s, String enc ) throws UnsupportedEncodingException { boolean needToChange = false; final StringBuffer sbuf = new StringBuffer( s.length() ); final char[] sChars = s.toCharArray(); final int len = sChars.length; Charset charset = charset = Charset.forName( enc ); CharArrayWriter charArrayWriter = new CharArrayWriter(); for ( int i = 0; i < len; ) { int c = sChars[ i ]; if ( dontNeedEncoding.get( c ) ) { sbuf.append( (char) c ); i++; } else { // other ASCII // convert to external encoding before hex conversion do { charArrayWriter.write( c ); /* * If this character represents the start of a Unicode * surrogate pair, then pass in two characters. It's not * clear what should be done if a bytes reserved in the * surrogate pairs range occurs outside of a legal * surrogate pair. For now, just treat it as if it were * any other character. */ if ( c >= 0xD800 && c <= 0xDBFF ) { /* System.out.println(Integer.toHexString(c) + " is high surrogate"); */ if ( ( i + 1 ) < s.length() ) { int d = (int) s.charAt( i + 1 ); /* System.out.println("\tExamining " + Integer.toHexString(d)); */ if ( d >= 0xDC00 && d <= 0xDFFF ) { /* System.out.println("\t" + Integer.toHexString(d) + " is low surrogate"); */ charArrayWriter.write( d ); i++; } } } i++; } while ( i < s.length() && !dontNeedEncoding.get( ( c = (int) s.charAt( i ) ) ) ); charArrayWriter.flush(); String str = new String( charArrayWriter.toCharArray() ); byte[] ba = str.getBytes( charset ); for ( int j = 0; j < ba.length; j++ ) { sbuf.append( '%' ); char ch = Character.forDigit( ( ba[ j ] >> 4 ) & 0xF, 16 ); // converting to use uppercase letter as part of // the hex value if ch is a letter. if ( Character.isLetter( ch ) ) { ch -= caseDiff; } sbuf.append( ch ); ch = Character.forDigit( ba[ j ] & 0xF, 16 ); if ( Character.isLetter( ch ) ) { ch -= caseDiff; } sbuf.append( ch ); } charArrayWriter.reset(); needToChange = true; } } return ( needToChange ? sbuf.toString() : s ); }