List of usage examples for java.io CharArrayWriter CharArrayWriter
public CharArrayWriter()
From source file:org.commoncrawl.util.ArcFileWriter.java
private String escapeURI(String uri, String charsetEncoding) throws IOException { boolean needToChange = false; StringBuffer out = new StringBuffer(uri.length()); Charset charset;// w ww .ja va 2 s.com CharArrayWriter charArrayWriter = new CharArrayWriter(); if (charsetEncoding == null) throw new NullPointerException("charsetName"); try { charset = Charset.forName(charsetEncoding); } catch (IllegalCharsetNameException e) { throw new UnsupportedEncodingException(charsetEncoding); } catch (UnsupportedCharsetException e) { throw new UnsupportedEncodingException(charsetEncoding); } for (int i = 0; i < uri.length();) { int c = (int) uri.charAt(i); // System.out.println("Examining character: " + c); if (dontNeedEncoding.get(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 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) < uri.length()) { int d = (int) uri.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 < uri.length() && !dontNeedEncoding.get((c = (int) uri.charAt(i)))); charArrayWriter.flush(); String str = new String(charArrayWriter.toCharArray()); byte[] ba = str.getBytes(charsetEncoding); 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() : uri); }
From source file:org.apache.struts2.jasper.JspC.java
private void initWebXml() { try {/* w ww .j a v a2s. c om*/ if (webxmlLevel >= INC_WEBXML) { File fmapings = new File(webxmlFile); mapout = new FileWriter(fmapings); servletout = new CharArrayWriter(); mappingout = new CharArrayWriter(); } else { mapout = null; servletout = null; mappingout = null; } if (webxmlLevel >= ALL_WEBXML) { mapout.write(Localizer.getMessage("jspc.webxml.header")); mapout.flush(); } else if ((webxmlLevel >= INC_WEBXML)) { mapout.write(Localizer.getMessage("jspc.webinc.header")); mapout.flush(); } } catch (IOException ioe) { mapout = null; servletout = null; mappingout = null; } }
From source file:org.apache.jasper.JspC.java
private void initWebXml() { try {//www.j a v a2 s . c om if (webxmlLevel >= INC_WEBXML) { File fmapings = new File(webxmlFile); mapout = new FileWriter(fmapings); servletout = new CharArrayWriter(); mappingout = new CharArrayWriter(); } else { mapout = null; servletout = null; mappingout = null; } if (webxmlLevel >= ALL_WEBXML) { mapout.write(Localizer.getMessage("jspc.webxml.header")); mapout.flush(); } else if ((webxmlLevel >= INC_WEBXML) && !addWebXmlMappings) { mapout.write(Localizer.getMessage("jspc.webinc.header")); mapout.flush(); } } catch (IOException ioe) { mapout = null; servletout = null; mappingout = null; } }
From source file:com.tomagoyaky.jdwp.IOUtils.java
/** * Gets the contents of an <code>InputStream</code> as a character array * using the specified character encoding. * <p/>//from ww w. j av a 2 s . co m * This method buffers the input internally, so there is no need to use a * <code>BufferedInputStream</code>. * * @param is the <code>InputStream</code> to read from * @param encoding the encoding to use, null means platform default * @return the requested character array * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs * @since 2.3 */ public static char[] toCharArray(final InputStream is, final Charset encoding) throws IOException { final CharArrayWriter output = new CharArrayWriter(); copy(is, output, encoding); return output.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));/*from w w w. j av a 2s . c o m*/ if (c == '@') { shouldAppend = false; } } if (shouldAppend) { out.append('@'); out.append(getDomain()); } return CharBuffer.wrap(out.toCharArray()); }
From source file:com.google.acre.script.HostEnv.java
/** * This implies an internal problem in acreboot.js, since it should * be handling any user errors./*from w w w.j a v a 2 s . co m*/ */ private void reportDisaster(String message, Throwable exc) { // we hit a java exception. all // bare java exception should have been trapped // and hidden by now, so this is a serious internal // error. try { syslog(ERROR, "hostenv.internal.error", "Internal error in script boot: " + message); startErrorPage(); signalAcreError(message); CharArrayWriter cw = new CharArrayWriter(); PrintWriter pw = new PrintWriter(cw); exc.printStackTrace(pw); if (null != exc.getCause()) { pw.write("Caused by:\n"); pw.write(exc.getCause().getMessage() + "\n"); exc.getCause().printStackTrace(pw); } pw.flush(); String excdump = cw.toString(); syslog(ERROR, "hostenv.internal.error.msg", "ACRE INTERNAL ERROR: \n" + excdump); write("ACRE INTERNAL ERROR -- Please Report to irc://irc.freenode.net/#freebase\n"); write("Request Id: " + req._metaweb_tid + "\n\n"); write(excdump + "\n"); } catch (Throwable e) { syslog(ERROR, "hostenv.internal.error.fatal", "Dispatch: Acre Last chance error, giving up" + exc); syslog(ERROR, "hostenv.internal.error.fatal.failed_on", "Failed reporting the error above" + e); // XXX this should be replaced with an exception class that is unique to this case // and will never be caught. throw new AcreInternalError("Failed while reporting a disaster", e); } }
From source file:org.opensingular.internal.lib.commons.xml.MElement.java
/** * Gera o XML to elemento conforme o funcionamento do mtodo printTabulado * (utilizar preferencialment printTabulado). Existe como convenincia * quando no houver um PrintWriter ou PrintStream disponvel. * * @return o XML com um tag por linha e alinhado conforme o nvel *//* w w w . j a v a 2 s .c o m*/ @Override public String toString() { CharArrayWriter writer = new CharArrayWriter(); PrintWriter out = new PrintWriter(writer); printTabulado(out); out.flush(); return writer.toString(); }
From source file:com.stratelia.silverpeas.silvertrace.SilverTrace.java
/** * Format the trace message for the Error and Fatal specific case * //from w ww. j av a 2 s.co m * @param module * @param classe * @param messageID * @param extraInfos * @param ex * @return the built message */ static protected String formatErrorAndFatalMessage(String module, String classe, String messageID, String extraInfos, Throwable ex) { String extraParams; if (ex != null) { CharArrayWriter buffer = new CharArrayWriter(); ex.printStackTrace(new PrintWriter(buffer)); if (StringUtil.isDefined(extraInfos)) { extraParams = extraInfos + ", EXCEPTION : " + buffer.toString(); } else { extraParams = "EXCEPTION : " + buffer.toString(); } } else { extraParams = extraInfos; } return formatTraceMessage(module, classe, messageID, traceMessages.getMsgString(messageID), extraParams); }
From source file:org.opensingular.internal.lib.commons.xml.MElement.java
/** * Gera o XML do elemento conforme o funcionamento do mtodo print (utilizar * preferencialment printTabulado). Existe como convenincia quando no * houver um PrintWriter ou PrintStream disponvel. * * @return a String que feito parse, retorna o mesmo conteudo *///from ww w .j ava 2 s.c o m public final String toStringExato() { CharArrayWriter writer = new CharArrayWriter(); PrintWriter out = new PrintWriter(writer); print(out, true, true); out.flush(); return writer.toString(); }
From source file:org.opensingular.internal.lib.commons.xml.MElement.java
/** * Gera o XML do elemento conforme o funcionamento do mtodo print (utilizar * preferencialment printTabulado). Existe como convenincia quando no * houver um PrintWriter ou PrintStream disponvel. * * @param printHeader Indica se ser adiciona o identificado inicial de * arquivo XML. Se for false, no ser possvel fazer parse do * resultado sem a adio de informaes complementares. * @return a String que feito parse, retorna o mesmo conteudo *///www .jav a 2 s . c o m public final String toStringExato(boolean printHeader) { CharArrayWriter writer = new CharArrayWriter(); PrintWriter out = new PrintWriter(writer); print(out, printHeader, true); out.flush(); return writer.toString(); }