List of usage examples for java.lang Character isISOControl
public static boolean isISOControl(int codePoint)
From source file:org.lnicholls.galleon.util.Tools.java
public static String clean(String value) { StringBuffer buffer = new StringBuffer(value.length()); synchronized (buffer) { for (int i = 0; i < value.length(); i++) { if (value.charAt(i) == '') buffer.append("'"); else if (value.charAt(i) >= '0' && value.charAt(i) <= '9') buffer.append(value.charAt(i)); else if (!Character.isISOControl(value.charAt(i))) buffer.append(value.charAt(i)); }/*w w w .j a v a2 s. co m*/ } return buffer.toString(); }
From source file:org.apache.jk.common.MsgAjp.java
public static String hexLine(byte buf[], int start, int len) { StringBuffer sb = new StringBuffer(); for (int i = start; i < start + 16; i++) { if (i < len + 4) sb.append(hex(buf[i]) + " "); else//from w w w.j a v a 2 s . co m sb.append(" "); } sb.append(" | "); for (int i = start; i < start + 16 && i < len + 4; i++) { if (!Character.isISOControl((char) buf[i])) sb.append(new Character((char) buf[i])); else sb.append("."); } return sb.toString(); }
From source file:org.dspace.content.DSpaceObjectServiceImpl.java
@Override public void addMetadata(Context context, T dso, MetadataField metadataField, String lang, List<String> values, List<String> authorities, List<Integer> confidences) throws SQLException { boolean authorityControlled = metadataAuthorityService.isAuthorityControlled(metadataField); boolean authorityRequired = metadataAuthorityService.isAuthorityRequired(metadataField); // We will not verify that they are valid entries in the registry // until update() is called. for (int i = 0; i < values.size(); i++) { MetadataValue metadataValue = metadataValueService.create(context, dso, metadataField); metadataValue.setLanguage(lang == null ? null : lang.trim()); // Logic to set Authority and Confidence: // - normalize an empty string for authority to NULL. // - if authority key is present, use given confidence or NOVALUE if not given // - otherwise, preserve confidence if meaningful value was given since it may document a failed authority lookup // - CF_UNSET signifies no authority nor meaningful confidence. // - it's possible to have empty authority & CF_ACCEPTED if e.g. user deletes authority key if (authorityControlled) { if (authorities != null && authorities.get(i) != null && authorities.get(i).length() > 0) { metadataValue.setAuthority(authorities.get(i)); metadataValue.setConfidence(confidences == null ? Choices.CF_NOVALUE : confidences.get(i)); } else { metadataValue.setAuthority(null); metadataValue.setConfidence(confidences == null ? Choices.CF_UNSET : confidences.get(i)); }/*from ww w. j a v a 2 s.c o m*/ // authority sanity check: if authority is required, was it supplied? // XXX FIXME? can't throw a "real" exception here without changing all the callers to expect it, so use a runtime exception if (authorityRequired && (metadataValue.getAuthority() == null || metadataValue.getAuthority().length() == 0)) { throw new IllegalArgumentException("The metadata field \"" + metadataField.toString() + "\" requires an authority key but none was provided. Value=\"" + values.get(i) + "\""); } } if (values.get(i) != null) { // remove control unicode char String temp = values.get(i).trim(); char[] dcvalue = temp.toCharArray(); for (int charPos = 0; charPos < dcvalue.length; charPos++) { if (Character.isISOControl(dcvalue[charPos]) && !String.valueOf(dcvalue[charPos]).equals("\u0009") && !String.valueOf(dcvalue[charPos]).equals("\n") && !String.valueOf(dcvalue[charPos]).equals("\r")) { dcvalue[charPos] = ' '; } } metadataValue.setValue(String.valueOf(dcvalue)); ; } else { metadataValue.setValue(null); } //An update here isn't needed, this is persited upon the merge of the owning object // metadataValueService.update(context, metadataValue); dso.addDetails(metadataField.toString()); } }
From source file:org.realityforge.proxy_servlet.AbstractProxyServlet.java
/** * Encodes characters in the query or fragment part of the URI. * <p/>/*from ww w.ja v a 2s . com*/ * <p>Unfortunately, an incoming URI sometimes has characters disallowed by the spec. HttpClient * insists that the outgoing proxied request has a valid URI because it uses Java's {@link java.net.URI}. * To be more forgiving, we must escape the problematic characters. See the URI class for the * spec. * * @param in example: name=value&foo=bar#fragment */ private static CharSequence encodeUriQuery(final CharSequence in) { //Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things. StringBuilder sb = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < MAX_ASCII_VALUE) { if (ASCII_QUERY_CHARS.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) { //not-ascii escape = false; } if (!escape) { if (null != sb) { sb.append(c); } } else { //escape if (null == sb) { final int formatLength = 5 * 3; sb = new StringBuilder(in.length() + formatLength); sb.append(in, 0, i); formatter = new Formatter(sb); } //leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c); } } return sb != null ? sb : in; }
From source file:org.ocpsoft.rewrite.servlet.config.proxy.ProxyServlet.java
/** * Encodes characters in the query or fragment part of the URI. * /*from w ww . j a v a 2 s .c om*/ * <p> * Unfortunately, an incoming URI sometimes has characters disallowed by the spec. HttpClient insists that the * outgoing proxied request has a valid URI because it uses Java's {@link URI}. To be more forgiving, we must escape * the problematic characters. See the URI class for the spec. * * @param in example: name=value&foo=bar#fragment */ protected static CharSequence encodeUriQuery(CharSequence in) { /* * Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things. TODO: * replace/compare to with Rewrite Encoding */ StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get(c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) { /* * not-ascii */ escape = false; } if (!escape) { if (outBuf != null) outBuf.append(c); } else { /* * escape */ if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } /* * leading %, 0 padded, width 2, capital hex */ formatter.format("%%%02X", (int) c);// TODO } } return outBuf != null ? outBuf : in; }
From source file:uk.ac.ebi.phenotype.web.proxy.ExternalUrlConfiguratbleProxyServlet.java
/** * <p>//w ww . ja v a 2 s . c o m * Encodes characters in the query or fragment part of the URI. * * <p> * Unfortunately, an incoming URI sometimes has characters disallowed by the * spec. HttpClient insists that the outgoing proxied request has a valid * URI because it uses Java's {@link URI}. To be more forgiving, we must * escape the problematic characters. See the URI class for the spec. * * @param in * example: name=value&foo=bar#fragment */ static CharSequence encodeUriQuery(CharSequence in) { // Note that I can't simply use URI.java to encode because it will // escape pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {// not-ascii escape = false; } if (!escape) { if (outBuf != null) outBuf.append(c); } else { // escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } // leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c);// TODO } } return outBuf != null ? outBuf : in; }
From source file:be.milieuinfo.core.proxy.controller.ProxyServlet.java
/** * <p>Encodes characters in the query or fragment part of the URI. * * <p>Unfortunately, an incoming URI sometimes has characters disallowed by the spec. HttpClient * insists that the outgoing proxied request has a valid URI because it uses Java's {@link URI}. To be more * forgiving, we must escape the problematic characters. See the URI class for the spec. * * @param in example: name=value&foo=bar#fragment *///from w ww . j ava 2s . c o m static CharSequence encodeUriQuery(CharSequence in) { //Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {//not-ascii escape = false; } if (!escape) { if (outBuf != null) outBuf.append(c); } else { //escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } //leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c);//TODO } } return outBuf != null ? outBuf : in; }
From source file:au.org.ala.delta.util.Utils.java
public static char GetNextChar(String RTFString, int[] startPos, int[] endPos) { char result = 0; int skipLevel = 0; endPos[0] = RTFString.length();/*w w w .j a v a 2 s .c o m*/ while (result == 0 && startPos[0] < endPos[0]) { char ch = RTFString.charAt(startPos[0]); if (ch == '{' || ch == '}') { ++startPos[0]; if (skipLevel != 0) { if (ch == '{') { ++skipLevel; } else { --skipLevel; } } } else if (skipLevel != 0) { ++startPos[0]; } else if (ch == '\\') { int cmdStart = startPos[0] + 1; if (cmdStart >= endPos[0]) { // A pathological case - not actually good RTF result = ch; } else { ch = RTFString.charAt(cmdStart); if (Character.isLetter(ch)) { int[] curPos = new int[] { cmdStart }; while (++curPos[0] < endPos[0] && Character.isLetter(RTFString.charAt(curPos[0]))) { } String test = RTFString.substring(cmdStart, cmdStart + curPos[0] - cmdStart); int numStart = curPos[0]; boolean hasParam = false; if (curPos[0] < endPos[0] && (RTFString.charAt(curPos[0]) == '-' || Character.isDigit(RTFString.charAt(curPos[0])))) { hasParam = true; while (++curPos[0] < endPos[0] && Character.isDigit(RTFString.charAt(curPos[0]))) { } } if (curPos[0] < endPos[0] && RTFString.charAt(curPos[0]) == ' ') { ++curPos[0]; } for (int i = 0; i < nSkipWords; ++i) { if (skipWords[i] == test) { skipLevel = 1; break; } } if (skipLevel != 0) { } else if (test == "u") { // Actually had RTF unicode... result = (char) Integer.parseInt(RTFString.substring(numStart, curPos[0] - numStart)); char ansiVal = GetNextChar(RTFString, curPos, endPos); curPos[0] = endPos[0]; result |= ansiVal << 16; } else if (!hasParam) { // Currently match only parameter-less commands for (int i = 0; i < nRTFCmds; ++i) { if (RTFreps[i].cmdString == test) { result = RTFreps[i].unicodeValue; if (result > 0x100) result |= (char) RTFreps[i].repString.charAt(0) << 16; } } } if (result != 0) { // && endPos == RTFString.size()) endPos[0] = curPos[0]; } else { startPos[0] = curPos[0]; } } else if (ch == '{' || ch == '}' || ch == '\\') { result = ch; endPos[0] = cmdStart + 1; } else if (ch == '~') { result = 0xa0; endPos[0] = cmdStart + 1; } else if (ch == '-') { result = 0xad; endPos[0] = cmdStart + 1; } else if (ch == '\'' && cmdStart + 2 < endPos[0]) { char[] buff = new char[2]; buff[0] = RTFString.charAt(cmdStart + 1); buff[1] = RTFString.charAt(cmdStart + 2); result = (char) Integer.parseInt(new String(buff), 16); endPos[0] = cmdStart + 1 + 2; } else { result = ch; endPos[0] = cmdStart + 1; } } } else if (!Character.isISOControl(ch) || ch >= 0x80) { if (ch >= 0x80 && ch < 0xa0) { result = (char) (winANSIChars[ch - 0x80] | ch << 16); } else { result = ch; } endPos[0] = startPos[0] + 1; } else ++startPos[0]; } if ((result >> 16) == 0) result |= (result << 16); return result; }
From source file:com.googlecode.jsonplugin.JSONWriter.java
/** * escape characters/*from www . ja v a 2s. c o m*/ */ private void string(Object obj) { this.add('"'); CharacterIterator it = new StringCharacterIterator(obj.toString()); for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) { if (c == '"') { this.add("\\\""); } else if (c == '\\') { this.add("\\\\"); } else if (c == '/') { this.add("\\/"); } else if (c == '\b') { this.add("\\b"); } else if (c == '\f') { this.add("\\f"); } else if (c == '\n') { this.add("\\n"); } else if (c == '\r') { this.add("\\r"); } else if (c == '\t') { this.add("\\t"); } else if (Character.isISOControl(c)) { this.unicode(c); } else { this.add(c); } } this.add('"'); }
From source file:com.sangupta.jerry.util.FileUtils.java
/** * Dump a given file into HEX starting at given offset and reading given number of rows where * a row consists of 16-bytes./*from w w w. j a va 2 s .c o m*/ * * @param out * @param file * @param offset * @param maxRows * @throws IOException */ public static void hexDump(PrintStream out, File file, long offset, int maxRows) throws IOException { InputStream is = null; BufferedInputStream bis = null; try { is = new FileInputStream(file); bis = new BufferedInputStream(is); bis.skip(offset); int row = 0; if (maxRows == 0) { maxRows = Integer.MAX_VALUE; } StringBuilder builder1 = new StringBuilder(100); StringBuilder builder2 = new StringBuilder(100); while (bis.available() > 0) { out.printf("%04X ", row * 16); for (int j = 0; j < 16; j++) { if (bis.available() > 0) { int value = (int) bis.read(); builder1.append(String.format("%02X ", value)); if (!Character.isISOControl(value)) { builder2.append((char) value); } else { builder2.append("."); } } else { for (; j < 16; j++) { builder1.append(" "); } } } out.print(builder1); out.println(builder2); row++; if (row > maxRows) { break; } builder1.setLength(0); builder2.setLength(0); } } finally { IOUtils.closeQuietly(bis); IOUtils.closeQuietly(is); } }