List of usage examples for java.io CharArrayWriter size
public int size()
From source file:Main.java
public static void main(String[] args) throws Exception { String str = "from java2s.com!"; CharArrayWriter chw = new CharArrayWriter(); // create destination character array writer CharArrayWriter chwd = new CharArrayWriter(); chw.write(str);// ww w.j a v a 2 s .co m chw.writeTo(chwd); // print the destination buffer content as string System.out.println(chwd.toString()); System.out.println(chwd.size()); }
From source file:Main.java
public static void main(String args[]) throws IOException { CharArrayWriter outStream = new CharArrayWriter(); String s = "This is a test."; for (int i = 0; i < s.length(); ++i) outStream.write(s.charAt(i));/*from w w w . ja va2 s . c o m*/ System.out.println("outstream: " + outStream); System.out.println("size: " + outStream.size()); CharArrayReader inStream; inStream = new CharArrayReader(outStream.toCharArray()); int ch = 0; StringBuffer sb = new StringBuffer(""); while ((ch = inStream.read()) != -1) sb.append((char) ch); s = sb.toString(); System.out.println(s.length() + " characters were read"); System.out.println("They are: " + s); }
From source file:com.sap.prd.mobile.ios.mios.OTAManagerTest.java
@Test public void testOtaUrlIsNull() throws Exception { OTAManager otaManager = new OTAManager(null, "", "", "", "", "", "", null); Assert.assertFalse(otaManager.generateOtaHTML()); CharArrayWriter charWriter = new CharArrayWriter(); try {// ww w . j a v a 2s . c o m otaManager.writeOtaHtml(new PrintWriter(charWriter)); assertTrue(charWriter.size() == 0); } finally { closeQuietly(charWriter); } }
From source file:org.apache.jmeter.save.CSVSaveService.java
/** * Reads from file and splits input into strings according to the delimiter, * taking note of quoted strings./*from w ww .j av a 2 s .co m*/ * <p> * Handles DOS (CRLF), Unix (LF), and Mac (CR) line-endings equally. * <p> * A blank line - or a quoted blank line - both return an array containing * a single empty String. * @param infile * input file - must support mark(1) * @param delim * delimiter (e.g. comma) * @return array of strings, will be empty if there is no data, i.e. if the input is at EOF. * @throws IOException * also for unexpected quote characters */ public static String[] csvReadFile(BufferedReader infile, char delim) throws IOException { int ch; ParserState state = ParserState.INITIAL; List<String> list = new ArrayList<>(); CharArrayWriter baos = new CharArrayWriter(200); boolean push = false; while (-1 != (ch = infile.read())) { push = false; switch (state) { case INITIAL: if (ch == QUOTING_CHAR) { state = ParserState.QUOTED; } else if (isDelimOrEOL(delim, ch)) { push = true; } else { baos.write(ch); state = ParserState.PLAIN; } break; case PLAIN: if (ch == QUOTING_CHAR) { baos.write(ch); throw new IOException("Cannot have quote-char in plain field:[" + baos.toString() + "]"); } else if (isDelimOrEOL(delim, ch)) { push = true; state = ParserState.INITIAL; } else { baos.write(ch); } break; case QUOTED: if (ch == QUOTING_CHAR) { state = ParserState.EMBEDDEDQUOTE; } else { baos.write(ch); } break; case EMBEDDEDQUOTE: if (ch == QUOTING_CHAR) { baos.write(QUOTING_CHAR); // doubled quote => quote state = ParserState.QUOTED; } else if (isDelimOrEOL(delim, ch)) { push = true; state = ParserState.INITIAL; } else { baos.write(QUOTING_CHAR); throw new IOException( "Cannot have single quote-char in quoted field:[" + baos.toString() + "]"); } break; default: throw new IllegalStateException("Unexpected state " + state); } // switch(state) if (push) { if (ch == '\r') {// Remove following \n if present infile.mark(1); if (infile.read() != '\n') { infile.reset(); // did not find \n, put the character // back } } String s = baos.toString(); list.add(s); baos.reset(); } if ((ch == '\n' || ch == '\r') && state != ParserState.QUOTED) { break; } } // while not EOF if (ch == -1) {// EOF (or end of string) so collect any remaining data if (state == ParserState.QUOTED) { throw new IOException("Missing trailing quote-char in quoted field:[\"" + baos.toString() + "]"); } // Do we have some data, or a trailing empty field? if (baos.size() > 0 // we have some data || push // we've started a field || state == ParserState.EMBEDDEDQUOTE // Just seen "" ) { list.add(baos.toString()); } } return list.toArray(new String[list.size()]); }