List of usage examples for java.io StringReader read
public int read() throws IOException
From source file:org.ecoinformatics.seek.R.RExpression.java
private String _writeDataFile(String dat) { String fn = ""; try {/* www. j a va 2s . c o m*/ String home = System.getProperty("user.home"); home = home.replace('\\', '/'); fn = home + "/" + _getUniqueFileName("dat") + cntr; File dataFile = new File(fn); StringReader is = new StringReader(dat); FileWriter os = new FileWriter(dataFile); int c; while ((c = is.read()) != -1) { os.write(c); } is.close(); os.close(); } catch (Exception exc) { log.error("error writing data file! - RExpression"); } cntr++; return fn; }
From source file:de.innovationgate.utils.WGUtils.java
/** * Encodes an input string of plain text to it's XML representation. The * special characters &, <, > and " and all characters with character code >= * 127 are converted to numeric XML entities. * // w w w. jav a2 s . c o m * @param input * The plain text string to convert * @return The XML representation of the plain text. */ public static String encodeXML(String input) { StringReader in = new StringReader(input); StringBuffer out = new StringBuffer(); int ch; try { while ((ch = in.read()) != -1) { if (ch < 127 && ch != '&' && ch != '<' && ch != '>' && ch != '"') { out.append((char) ch); } else { out.append('&').append('#').append(ch).append(';'); } } } catch (IOException exc) { exc.printStackTrace(); } return out.toString(); }
From source file:de.innovationgate.utils.WGUtils.java
public static String encodeHTML(String input, boolean reduceToASCII, int lineFeedTreatment, Set<Integer> additionalCharsToEncode) { if (input == null) { return ""; }// ww w. j a va 2 s .c o m if (additionalCharsToEncode == null) { additionalCharsToEncode = Collections.emptySet(); } StringReader in = new StringReader(input); StringBuffer out = new StringBuffer(); int ch; try { while ((ch = in.read()) != -1) { if (ch == '\n') { if (lineFeedTreatment == LINEFEEDS_CONVERT_TO_BR) { out.append("<br>"); } else if (lineFeedTreatment == LINEFEEDS_KEEP) { out.append("\n"); } } else if ((!reduceToASCII || ch < 127) && ch != '&' && ch != '<' && ch != '>' && ch != '"' && !additionalCharsToEncode.contains(ch)) { out.append((char) ch); } else { out.append('&').append('#').append(ch).append(';'); } } } catch (IOException exc) { exc.printStackTrace(); } return out.toString(); }
From source file:org.apache.cocoon.generation.JXTemplateGenerator.java
private static JXTExpression compileExpr(String inStr) throws Exception { try {// ww w . ja v a2 s . co m if (inStr == null) { return null; } StringReader in = new StringReader(inStr.trim()); int ch; boolean xpath = false; boolean inExpr = false; StringBuffer expr = new StringBuffer(); while ((ch = in.read()) != -1) { char c = (char) ch; if (inExpr) { if (c == '\\') { ch = in.read(); expr.append((ch == -1) ? '\\' : (char) ch); } else if (c == '}') { return compile(expr.toString(), xpath); } else { expr.append(c); } } else { if (c == '$' || c == '#') { ch = in.read(); if (ch == '{') { inExpr = true; xpath = c == '#'; continue; } } // hack: invalid expression? // just return the original and swallow exception return new JXTExpression(inStr, null); } } if (inExpr) { // unclosed #{} or ${} throw new Exception("Unterminated " + (xpath ? "#" : "$") + "{"); } } catch (IOException ignored) { ignored.printStackTrace(); } return new JXTExpression(inStr, null); }