List of usage examples for java.io CharArrayWriter append
public CharArrayWriter append(char c)
From source file:Main.java
public static void main(String[] args) { char[] ch = { 'A', 'B', 'C', 'D', 'E', 'F' }; CharArrayWriter chw = new CharArrayWriter(); for (char c : ch) { chw.append(c); }// w w w . j a v a2 s . c o m 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); // flush//w w w . j a va 2s. c om 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"; // append character sequence to the writer chw.append(csq); // print character sequence System.out.println(csq);//from w w w . j a v a 2s . co m // 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(); CharSequence csq = "java2s.com"; // closes the stream chw.close();/*from w w w . 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 sequences CharSequence csq = "java2s.com"; CharSequence csq1 = "67890"; CharSequence csq2 = "ABCDE"; CharSequence csq3 = "abcde"; // append character sequences to the writer chw.append(csq); chw.append(csq1);/*from www . java 2 s. c o m*/ chw.append(csq2); chw.append(csq3); // prints out the character sequences System.out.println(chw.toString()); }
From source file:Main.java
public static String encodeAttribute(String value) { CharArrayWriter writer = new CharArrayWriter(); int size = value.length(); for (int i = 0; i < size; i++) { char c = value.charAt(i); switch (c) { case '&': writer.append(ENCODED_AMPERSAND); break; case '"': writer.append(ENCODED_DOUBLE_QUOTE); break; case '<': writer.append(ENCODED_LESS_THAN); break; case '>': writer.append(ENCODED_GREATER_THAN); break; default:/*w ww. j a v a2 s . c o m*/ writer.append(c); break; } } return writer.toString(); }
From source file:com.aliyun.odps.rodps.ROdps.java
public boolean setLogPath(String log_path) throws IOException { String fileName = ROdps.class.getClassLoader().getResource("log4j.properties").getPath(); String mode = "loghome"; File file = new File(fileName); BufferedReader reader = null; try {/*from w ww . j a v a 2 s . com*/ reader = new BufferedReader(new FileReader(file)); CharArrayWriter tempStream = new CharArrayWriter(); String tempString = null; int line = 1; while ((tempString = reader.readLine()) != null) { if (tempString.contains(mode) && (!tempString.contains("${" + mode + "}"))) { tempString = tempString.substring(0, tempString.indexOf('=') + 1) + log_path; } tempStream.write(tempString); tempStream.append(System.getProperty("line.separator")); } reader.close(); FileWriter out = new FileWriter(fileName); tempStream.writeTo(out); out.close(); } catch (IOException e) { e.printStackTrace(); return false; } finally { if (reader != null) { try { reader.close(); } catch (IOException e1) { } } } return true; }
From source file:onl.area51.httpd.action.Response.java
static Response create(Request request) { class State { private final String tag; private final boolean disableMini; private boolean body; public State(String tag, boolean disableMini) { this.tag = tag; this.disableMini = disableMini; }// w w w .j av a 2s. com @Override public String toString() { return tag; } } CharArrayWriter writer = new CharArrayWriter(); return new Response() { private ContentType contentType = ContentType.TEXT_HTML; private Deque<State> deque = new ArrayDeque<>(); private State state; @Override public Response exec(Action a) throws IOException, HttpException { if (a != null) { // Ensure we have finished the current tag startBody(); // Now preserve the stack & start a new one. // This means one action cannot affect the state of this one final Deque<State> orig = deque; deque = new ArrayDeque<>(); try { a.apply(request); } finally { endAll(); deque = orig; } } return this; } @Override public Response setContentType(ContentType contentType) { this.contentType = contentType; return this; } @Override public HttpEntity getEntity() throws IOException { while (!deque.isEmpty()) { end(); } return new StringEntity(writer.toString(), contentType); } private void startBody() { if (state != null && !state.body) { state.body = true; writer.append('>'); } } private void tagOnly() { if (state == null || state.body) { throw new IllegalStateException("Not in tag"); } } @Override public Response write(CharSequence seq, int s, int e) throws IOException { startBody(); writer.append(seq, s, e); return this; } @Override public Response write(char[] v, int s, int l) throws IOException { startBody(); writer.write(v, s, l); return this; } @Override public Response write(char v) throws IOException { startBody(); writer.write(v); return this; } @Override public Response begin(String t, boolean disableMini) throws IOException { startBody(); if (state != null) { deque.addLast(state); } state = new State(t, disableMini); writer.append('<'); writer.write(state.tag); return this; } @Override public Response end() throws IOException { if (state == null) { throw new IllegalStateException("end() called outside of tag"); } // elements like script mustn't be minified, i.e. <script/> is invalid must be <script></script> if (state.disableMini) { startBody(); } if (state.body) { writer.append('<'); writer.append('/'); writer.append(state.tag); writer.append('>'); } else { writer.append('/'); writer.append('>'); } state = deque.pollLast(); return this; } @Override public Response endAll() throws IOException { while (!deque.isEmpty()) { end(); } return this; } @Override public Response attr(String n, CharSequence seq) throws IOException { tagOnly(); writer.append(' '); writer.append(n); writer.append('='); writer.append('"'); writer.append(seq); writer.append('"'); return this; } @Override public Response attr(String n, CharSequence seq, int s, int e) throws IOException { tagOnly(); writer.append(' '); writer.append(n); writer.append('='); writer.append('"'); writer.append(seq, s, e); writer.append('"'); return this; } @Override public Response attr(String n, char[] v) throws IOException { tagOnly(); writer.append(' '); writer.append(n); writer.append('='); writer.append('"'); writer.write(v); writer.append('"'); return this; } @Override public Response attr(String n, char[] v, int s, int l) throws IOException { tagOnly(); writer.append(' '); writer.append(n); writer.append('='); writer.append('"'); writer.write(v, s, l); writer.append('"'); return this; } }; }
From source file:com.allblacks.utils.web.HttpUtil.java
/** * Gets data from URL as char[] throws {@link RuntimeException} If anything * goes wrong//from ww w.j a va 2 s. c om * * @return The content of the URL as a char[] * @throws java.io.IOException */ public char[] postDataAsCharArray(String url, String contentType, String contentName, char[] content) throws IOException { URLConnection urlc = null; OutputStream os = null; InputStream is = null; CharArrayWriter dat = null; BufferedReader reader = null; String boundary = "" + new Date().getTime(); try { urlc = new URL(url).openConnection(); urlc.setDoOutput(true); urlc.setRequestProperty(HttpUtil.CONTENT_TYPE, "multipart/form-data; boundary=---------------------------" + boundary); String message1 = "-----------------------------" + boundary + HttpUtil.BNL; message1 += "Content-Disposition: form-data; name=\"nzbfile\"; filename=\"" + contentName + "\"" + HttpUtil.BNL; message1 += "Content-Type: " + contentType + HttpUtil.BNL; message1 += HttpUtil.BNL; String message2 = HttpUtil.BNL + "-----------------------------" + boundary + "--" + HttpUtil.BNL; os = urlc.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, Charset.forName(HttpUtil.UTF_8))); writer.write(message1); writer.write(content); writer.write(message2); writer.flush(); dat = new CharArrayWriter(); if (urlc.getContentEncoding() != null && urlc.getContentEncoding().equalsIgnoreCase(HttpUtil.GZIP)) { is = new GZIPInputStream(urlc.getInputStream()); } else { is = urlc.getInputStream(); } reader = new BufferedReader(new InputStreamReader(is, Charset.forName(HttpUtil.UTF_8))); int c; while ((c = reader.read()) != -1) { dat.append((char) c); } } catch (IOException exception) { throw exception; } finally { try { reader.close(); os.close(); is.close(); } catch (Exception e) { // we do not care about this } } return dat.toCharArray(); }
From source file:com.silentcircle.silenttext.application.SilentTextApplication.java
public CharSequence getFullJIDForUsername(CharSequence username) { CharArrayWriter out = new CharArrayWriter(); boolean shouldAppend = true; for (int i = 0; i < username.length(); i++) { char c = username.charAt(i); out.append(username.charAt(i)); if (c == '@') { shouldAppend = false;/*from w w w.ja va 2 s .c o m*/ } } if (shouldAppend) { out.append('@'); out.append(getDomain()); } return CharBuffer.wrap(out.toCharArray()); }