List of usage examples for java.lang StringBuffer appendCodePoint
@Override public synchronized StringBuffer appendCodePoint(int codePoint)
From source file:Main.java
public static void main(String[] arg) { StringBuffer buffer = new StringBuffer("from java2s.com"); buffer.appendCodePoint(66); System.out.println(buffer);// w ww .j a v a 2s. c o m }
From source file:org.neugierig.proximo.ProximoBus.java
static String fetchURL(URL url) throws IOException { InputStream input = url.openStream(); StringBuffer buffer = new StringBuffer(8 << 10); int byte_read; while ((byte_read = input.read()) != -1) { // This is incorrect for non-ASCII, but we don't have any of that. buffer.appendCodePoint(byte_read); }//from www . j a v a 2 s. c om return buffer.toString(); }
From source file:com.kyne.webby.rtk.web.Connection.java
@Override public void run() { InputStream in = null;//from ww w. j a v a 2s . c om try { in = this.clientSocket.getInputStream(); String url = null; String params = null; final StringBuffer buff = new StringBuffer(); final int b = in.read(); if (b < 0) { return; } buff.appendCodePoint(b); while (0 != in.available()) { buff.appendCodePoint(in.read()); } final String httpContent = buff.toString(); final StringTokenizer tokenizer = new StringTokenizer(httpContent, "\n"); final String firstLine = tokenizer.nextToken(); final String[] splittedFirstLine = firstLine.split(" "); if (splittedFirstLine.length > 1) { final String requestUrl = (firstLine.split(" "))[1]; //GET /url?params HTTP/1.X or //POST /url HTTP/1.X final Matcher result = this.urlRegex.matcher(requestUrl); if (result.find()) { url = result.group(1); params = result.group(2); } else { LogHelper.warn("Invalid URL format : " + requestUrl); } if (httpContent.startsWith("POST")) { String lastLine = null; while (tokenizer.hasMoreTokens()) { lastLine = tokenizer.nextToken(); } params = "?" + lastLine; } } else { LogHelper.warn("Empty Request with HttpContent = " + httpContent); } final boolean isAllowedRessource; if (url == null) { LogHelper.warn("Null url " + url); isAllowedRessource = false; } else { isAllowedRessource = this.isRestrictedUrl(url) || this.isContextualCallUrl(url) || this.webServer.isAllowedRessource(url) || this.isPredefinedUrl(url); } if (isAllowedRessource) { if (url != null && params != null) { this.handleRequest(url, params, this.clientSocket); } } else { this.handleRequest("/404", params, clientSocket); //Forward to 404 } } catch (final SocketException e) { /* Pics or it didn't happen ! */ } catch (final Exception e) { LogHelper.error(e.getMessage(), e); } finally { if (in != null) { try { in.close(); } catch (final IOException e) { /**/ } } } }
From source file:org.renjin.parser.RLexer.java
private int consumeSpecialValue(int c) { StringBuffer buffer = new StringBuffer(); buffer.appendCodePoint(c); while ((c = xxgetc()) != R_EOF && c != '%') { if (c == '\n') { xxungetc(c);//from w w w . jav a 2 s . c om return ERROR; } //buffer.append(c); /* * buffer.append(c) causes renjin to interprete the matrix production operator %*% * as %42%. Chaning it to buffer.appendCodePoint(c) seems to fix the error. */ buffer.appendCodePoint(c); } if (c == '%') { buffer.appendCodePoint(c); } yylval = Symbol.get(buffer.toString()); return SPECIAL; }
From source file:org.renjin.parser.RLexer.java
private int consumeSymbolValue(int c) { StringBuffer buffer = new StringBuffer(); do {//from ww w . j ava 2s . co m buffer.appendCodePoint(c); } while ((c = xxgetc()) != R_EOF && (Character.isLetterOrDigit(c) || c == '.' || c == '_')); xxungetc(c); int keyword; if ((keyword = lookupKeyword(buffer.toString())) != 0) { if (keyword == FUNCTION) { parseState.getFunctionSource().descend(); } return keyword; } yylval = Symbol.get(buffer.toString()); return SYMBOL; }
From source file:r.parser.RLexer.java
private int consumeSpecialValue(int c) { StringBuffer buffer = new StringBuffer(); buffer.appendCodePoint(c); while ((c = xxgetc()) != R_EOF && c != '%') { if (c == '\n') { xxungetc(c);//from ww w . j a va 2 s .c om return ERROR; } //buffer.append(c); /* * buffer.append(c) causes renjin to interprete the matrix production operator %*% * as %42%. Chaning it to buffer.appendCodePoint(c) seems to fix the error. */ buffer.appendCodePoint(c); } if (c == '%') { buffer.appendCodePoint(c); } yylval = install(buffer.toString()); return SPECIAL; }
From source file:r.parser.RLexer.java
private int consumeSymbolValue(int c) { StringBuffer buffer = new StringBuffer(); do {/*from w ww . j av a2 s . c om*/ buffer.appendCodePoint(c); } while ((c = xxgetc()) != R_EOF && (Character.isLetterOrDigit(c) || c == '.' || c == '_')); xxungetc(c); int keyword; if ((keyword = lookupKeyword(buffer.toString())) != 0) { if (keyword == FUNCTION) { parseState.getFunctionSource().descend(); } return keyword; } yylval = install(buffer.toString()); return SYMBOL; }
From source file:org.renjin.parser.RLexer.java
/** * @param c//w ww . ja v a 2s .com * @param forSymbol true when parsing backticked symbols * @return */ private int consumeStringValue(int c, boolean forSymbol) { int quote = c; int have_warned = 0; CTEXT ctext = new CTEXT(); StringBuffer stext = new StringBuffer(); while ((c = xxgetc()) != R_EOF && c != quote) { ctext.push(c); if (c == '\n') { xxungetc(c); /* Fix by Mark Bravington to allow multiline strings * by pretending we've seen a backslash. Was: * return ERROR; */ c = '\\'; } if (c == '\\') { c = xxgetc(); ctext.push(c); if ('0' <= c && c <= '8') { int octal = c - '0'; if ('0' <= (c = xxgetc()) && c <= '8') { ctext.push(c); octal = 8 * octal + c - '0'; if ('0' <= (c = xxgetc()) && c <= '8') { ctext.push(c); octal = 8 * octal + c - '0'; } else { xxungetc(c); ctext.pop(); } } else { xxungetc(c); ctext.pop(); } c = octal; } else if (c == 'x') { int val = 0; int i; int ext; for (i = 0; i < 2; i++) { c = xxgetc(); ctext.push(c); if (c >= '0' && c <= '9') { ext = c - '0'; } else if (c >= 'A' && c <= 'F') { ext = c - 'A' + 10; } else if (c >= 'a' && c <= 'f') { ext = c - 'a' + 10; } else { xxungetc(c); ctext.pop(); if (i == 0) { /* was just \x */ if (parseOptions.isGenerateCode() && parseOptions.isWarnEscapes()) { have_warned++; logger.warning("'\\x' used without hex digits"); } val = 'x'; } break; } val = 16 * val + ext; } c = val; } else if (c == 'u') { int val = 0; int i; int ext; boolean delim = false; if (forSymbol) { throw new RLexException(String.format( "\\uxxxx sequences not supported inside backticks (line %d)", srcRef.xxlineno)); } if ((c = xxgetc()) == '{') { delim = true; ctext.push(c); } else { xxungetc(c); } for (i = 0; i < 4; i++) { c = xxgetc(); ctext.push(c); if (c >= '0' && c <= '9') { ext = c - '0'; } else if ((c >= 'A') && (c <= 'F')) { ext = c - 'A' + 10; } else if (c >= 'a' && c <= 'f') { ext = c - 'a' + 10; } else { xxungetc(c); ctext.pop(); if (i == 0) { /* was just \x */ if (parseOptions.isGenerateCode() && parseOptions.isWarnEscapes()) { have_warned++; logger.warning("\\u used without hex digits"); } val = 'u'; } break; } val = 16 * val + ext; } if (delim) { if ((c = xxgetc()) != '}') { throw new RLexException( String.format("invalid \\u{xxxx} sequence (line %d)", srcRef.xxlineno)); } else { ctext.push(c); } } stext.appendCodePoint(val); //WTEXT_PUSH(val); /* this assumes wchar_t is Unicode */ //use_wcs = TRUE; continue; } else if (c == 'U') { int val = 0; int i; int ext; boolean delim = false; if (forSymbol) { throw new RLexException(String.format( "\\Uxxxxxxxx sequences not supported inside backticks (line %d)", srcRef.xxlineno)); } if ((c = xxgetc()) == '{') { delim = true; ctext.push(c); } else { xxungetc(c); } for (i = 0; i < 8; i++) { c = xxgetc(); ctext.push(c); if (c >= '0' && c <= '9') { ext = c - '0'; } else if (c >= 'A' && c <= 'F') { ext = c - 'A' + 10; } else if (c >= 'a' && c <= 'f') { ext = c - 'a' + 10; } else { xxungetc(c); ctext.pop(); if (i == 0) { /* was just \x */ if (parseOptions.isGenerateCode() && parseOptions.isWarnEscapes()) { have_warned++; logger.warning("\\U used without hex digits"); } val = 'U'; } break; } val = 16 * val + ext; } if (delim) { if ((c = xxgetc()) != '}') { logger.severe( String.format("invalid \\U{xxxxxxxx} sequence (line %d)", srcRef.xxlineno)); } else { ctext.push(c); } } ctext.push(val); continue; } else { switch (c) { case 'a': c = 7; break; case 'b': c = '\b'; break; case 'f': c = '\f'; break; case 'n': c = '\n'; break; case 'r': c = '\r'; break; case 't': c = '\t'; break; case 'v': c = 11; break; case '\\': c = '\\'; break; case '"': case '\'': case ' ': case '\n': break; default: if (parseOptions.isGenerateCode() && parseOptions.isWarnEscapes()) { have_warned++; logger.warning(String.format("'\\%c' is an unrecognized escape in a character string", (char) c)); } break; } } } stext.appendCodePoint(c); } if (forSymbol) { yylval = Symbol.get(stext.toString()); return SYMBOL; } else { yylval = StringVector.valueOf(stext.toString()); } if (have_warned != 0) { logger.warning(String.format("unrecognized escape(s) removed from \"%s\"", ctext)); } return STR_CONST; }
From source file:r.parser.RLexer.java
/** * @param c/*ww w. j a v a 2s. com*/ * @param forSymbol true when parsing backticked symbols * @return */ private int consumeStringValue(int c, boolean forSymbol) { int quote = c; int have_warned = 0; CTEXT ctext = new CTEXT(); StringBuffer stext = new StringBuffer(); while ((c = xxgetc()) != R_EOF && c != quote) { ctext.push(c); if (c == '\n') { xxungetc(c); /* Fix by Mark Bravington to allow multiline strings * by pretending we've seen a backslash. Was: * return ERROR; */ c = '\\'; } if (c == '\\') { c = xxgetc(); ctext.push(c); if ('0' <= c && c <= '8') { int octal = c - '0'; if ('0' <= (c = xxgetc()) && c <= '8') { ctext.push(c); octal = 8 * octal + c - '0'; if ('0' <= (c = xxgetc()) && c <= '8') { ctext.push(c); octal = 8 * octal + c - '0'; } else { xxungetc(c); ctext.pop(); } } else { xxungetc(c); ctext.pop(); } c = octal; } else if (c == 'x') { int val = 0; int i; int ext; for (i = 0; i < 2; i++) { c = xxgetc(); ctext.push(c); if (c >= '0' && c <= '9') { ext = c - '0'; } else if (c >= 'A' && c <= 'F') { ext = c - 'A' + 10; } else if (c >= 'a' && c <= 'f') { ext = c - 'a' + 10; } else { xxungetc(c); ctext.pop(); if (i == 0) { /* was just \x */ if (parseOptions.isGenerateCode() && parseOptions.isWarnEscapes()) { have_warned++; logger.warning("'\\x' used without hex digits"); } val = 'x'; } break; } val = 16 * val + ext; } c = val; } else if (c == 'u') { int val = 0; int i; int ext; boolean delim = false; if (forSymbol) { throw new RLexException(String.format( "\\uxxxx sequences not supported inside backticks (line %d)", srcRef.xxlineno)); } if ((c = xxgetc()) == '{') { delim = true; ctext.push(c); } else { xxungetc(c); } for (i = 0; i < 4; i++) { c = xxgetc(); ctext.push(c); if (c >= '0' && c <= '9') { ext = c - '0'; } else if ((c >= 'A') && (c <= 'F')) { ext = c - 'A' + 10; } else if (c >= 'a' && c <= 'f') { ext = c - 'a' + 10; } else { xxungetc(c); ctext.pop(); if (i == 0) { /* was just \x */ if (parseOptions.isGenerateCode() && parseOptions.isWarnEscapes()) { have_warned++; logger.warning("\\u used without hex digits"); } val = 'u'; } break; } val = 16 * val + ext; } if (delim) { if ((c = xxgetc()) != '}') { throw new RLexException( String.format("invalid \\u{xxxx} sequence (line %d)", srcRef.xxlineno)); } else { ctext.push(c); } } stext.appendCodePoint(val); //WTEXT_PUSH(val); /* this assumes wchar_t is Unicode */ //use_wcs = TRUE; continue; } else if (c == 'U') { int val = 0; int i; int ext; boolean delim = false; if (forSymbol) { throw new RLexException(String.format( "\\Uxxxxxxxx sequences not supported inside backticks (line %d)", srcRef.xxlineno)); } if ((c = xxgetc()) == '{') { delim = true; ctext.push(c); } else { xxungetc(c); } for (i = 0; i < 8; i++) { c = xxgetc(); ctext.push(c); if (c >= '0' && c <= '9') { ext = c - '0'; } else if (c >= 'A' && c <= 'F') { ext = c - 'A' + 10; } else if (c >= 'a' && c <= 'f') { ext = c - 'a' + 10; } else { xxungetc(c); ctext.pop(); if (i == 0) { /* was just \x */ if (parseOptions.isGenerateCode() && parseOptions.isWarnEscapes()) { have_warned++; logger.warning("\\U used without hex digits"); } val = 'U'; } break; } val = 16 * val + ext; } if (delim) { if ((c = xxgetc()) != '}') { logger.severe( String.format("invalid \\U{xxxxxxxx} sequence (line %d)", srcRef.xxlineno)); } else { ctext.push(c); } } ctext.push(val); continue; } else { switch (c) { case 'a': c = 7; break; case 'b': c = '\b'; break; case 'f': c = '\f'; break; case 'n': c = '\n'; break; case 'r': c = '\r'; break; case 't': c = '\t'; break; case 'v': c = 11; break; case '\\': c = '\\'; break; case '"': case '\'': case ' ': case '\n': break; default: if (parseOptions.isGenerateCode() && parseOptions.isWarnEscapes()) { have_warned++; logger.warning(String.format("'\\%c' is an unrecognized escape in a character string", (char) c)); } break; } } } stext.appendCodePoint(c); } if (forSymbol) { yylval = install(stext.toString()); return SYMBOL; } else { yylval = new StringVector(stext.toString()); } if (have_warned != 0) { logger.warning(String.format("unrecognized escape(s) removed from \"%s\"", ctext)); } return STR_CONST; }