List of usage examples for java.io CharArrayWriter toString
public String toString()
From source file:Main.java
public static void main(String[] args) { CharArrayWriter chw = new CharArrayWriter(); CharSequence csq = "java2s.com"; // append character sequence to the writer chw.append(csq);//from w w w. j av a 2s . c o m // flush chw.flush(); // prints out the character sequences System.out.println(chw.toString()); }
From source file:Main.java
public static void main(String[] args) { CharArrayWriter chw = new CharArrayWriter(); CharSequence csq = "java2s.com"; // closes the stream chw.close();//from w ww. ja v a 2 s. c o m // append character sequence to the writer chw.append(csq); // prints out the character sequences System.out.println(chw.toString()); }
From source file:Main.java
public static void main(String[] args) { CharArrayWriter chw = new CharArrayWriter(); // declare character sequence CharSequence csq = "tutorial from java2s.com"; // append character sequence to the writer chw.append(csq, 2, 5);/*from ww w. j av a 2 s . c o m*/ // prints out the character sequences System.out.println(chw.toString()); }
From source file:Main.java
public static void main(String[] args) { CharArrayWriter chw = new CharArrayWriter(); CharSequence csq = "java2s.com"; // append character sequence to the writer chw.append(csq);//from w w w. ja v a2 s . co m // print character sequence System.out.println(csq); // invoke reset() chw.reset(); csq = "1234567890"; chw.append(csq); System.out.println(chw.toString()); }
From source file:Main.java
public static void main(String[] args) { CharArrayWriter chw = new CharArrayWriter(); // declare character sequences CharSequence csq = "java2s.com"; CharSequence csq1 = "67890"; CharSequence csq2 = "ABCDE"; CharSequence csq3 = "abcde"; // append character sequences to the writer chw.append(csq);/* w w w.j av a2 s .c o m*/ chw.append(csq1); chw.append(csq2); chw.append(csq3); // prints out the character sequences System.out.println(chw.toString()); }
From source file:Main.java
/** Pops up a message box, blocking the current thread. */ public static void pause(final Throwable t) { final CharArrayWriter caw = new CharArrayWriter(); t.printStackTrace(new PrintWriter(caw)); pause(caw.toString()); }
From source file:Main.java
/** * Reads the XML document and returns it as a {@link String}. * /*from w ww .ja v a2 s .c o m*/ * @param url the URL of the XML document * * @return the XML document, as a {@link String} * * @throws IOException */ public static String readXmlDocument(URL url) throws IOException { Reader in = new InputStreamReader(url.openStream()); CharArrayWriter out = new CharArrayWriter(); FileCopyUtils.copy(in, out); return out.toString(); }
From source file:Main.java
/** * Fully reads the characters available from the supplied Reader * and returns these characters as a String object. * * @param reader The Reader to read the characters from. * @return A String existing of the characters that were read. * @throws IOException If I/O error occurred. *///from ww w . jav a2 s . co m public static final String readFully(Reader reader) throws IOException { CharArrayWriter out = new CharArrayWriter(4096); transfer(reader, out); out.close(); return out.toString(); }
From source file:Main.java
/** * Reads an XML document and returns it as a {@link String}. * //from ww w .j a va2 s.c o m * @param source the input source for the XML document * * @return the XML document, as a {@link String} * * @throws IOException */ public static String readXmlDocument(InputSource source) throws IOException { CharArrayWriter out = new CharArrayWriter(); FileCopyUtils.copy(source.getCharacterStream(), out); return out.toString(); }
From source file:Main.java
/** Reads an <code>InputStream</code> into a string. * @param in The stream to read into a string. * @return The stream as a string//from ww w. j a va 2 s . c o m * @throws IOException */ public static String toString(InputStream in) throws IOException { if (in == null) { return null; } final Reader reader = new InputStreamReader(in); final char[] buffer = new char[100]; final CharArrayWriter writer = new CharArrayWriter(1000); int read; while ((read = reader.read(buffer)) > -1) writer.write(buffer, 0, read); return writer.toString(); }