List of usage examples for java.lang Character isISOControl
public static boolean isISOControl(int codePoint)
From source file:com.forerunnergames.tools.common.Strings.java
/** * Checks whether the character c is a printable character. * * @param c/*from ww w .ja va 2s . co m*/ * The character to check. * * @return True if the character c is a printable character, false otherwise. */ public static boolean isPrintable(final char c) { final Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.of(c); return !Character.isISOControl(c) && c != KeyEvent.CHAR_UNDEFINED && unicodeBlock != null && unicodeBlock != Character.UnicodeBlock.SPECIALS; }
From source file:org.apache.impala.datagenerator.HBaseTestDataRegionAssigment.java
/** * Returns non-printable characters in escaped octal, otherwise returns the characters. */// w w w.j a v a2s . c om public static String printKey(byte[] key) { StringBuilder result = new StringBuilder(); for (int i = 0; i < key.length; ++i) { if (!Character.isISOControl(key[i])) { result.append((char) key[i]); } else { result.append("\\"); result.append(Integer.toOctalString(key[i])); } } return result.toString(); }
From source file:com.microsoft.rest.interceptors.LoggingInterceptor.java
private static boolean isPlaintext(Buffer buffer) throws EOFException { try {//from w w w .j a va2 s .com Buffer prefix = new Buffer(); long byteCount = buffer.size() < 64 ? buffer.size() : 64; buffer.copyTo(prefix, 0, byteCount); for (int i = 0; i < 16; i++) { if (prefix.exhausted()) { break; } int codePoint = prefix.readUtf8CodePoint(); if (Character.isISOControl(codePoint) && !Character.isWhitespace(codePoint)) { return false; } } return true; } catch (EOFException e) { return false; } }
From source file:htsjdk.samtools.reference.FastaReferenceWriter.java
private static void checkSequenceName(final String name) { ValidationUtils.nonEmpty(name, "Sequence name"); for (int i = 0; i < name.length(); i++) { final char ch = name.charAt(i); if (Character.isWhitespace(ch)) { throw new IllegalArgumentException("the input name contains blank characters: '" + name + "'"); } else if (Character.isISOControl(ch)) { throw new IllegalArgumentException("the input name contains control characters: '" + name + "'"); }/*w w w .j a v a2 s . co m*/ } }
From source file:org.tridas.io.util.StringUtils.java
/** * Given a string, escape any < > & ' " characters for XML. Also, * if any characters are unprintable, they're escaped as raw values * (&#xxxx;), so loading the output in any old text editor shouldn't * mangle anything./*from w w w . j a v a 2 s .co m*/ * * @param input * a string * @return the same string, with </>/& escaped */ public static String escapeForXML(String input) { // FIXME: if there are no <>& symbols, just return the string // as-is to save the GC // MAYBE: does SAX or somebody already have a method that does // this better? // MAYBE: use regexps in 1.4? // BETTER: isn't there a String.replace() or something that // would do this in about 2 lines? StringBuffer output = new StringBuffer(); for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); switch (c) { case '&': output.append("&"); break; case '<': output.append("<"); break; case '>': output.append(">"); break; case '\"': output.append("""); break; case '\'': output.append("'"); break; default: if (Character.isISOControl(c)) { // if it's not printable, &#x-escape it. // (this came up when trying to save // "<dating>^D</dating>" which shouldn't happen, // anyway, but better safe than sorry.) // BUG: aren't there non-iso-control characters // which won't show up correctly? do they need // the right encoding=""? do they have it? if (c < 32) { output.append("ILLEGAL-XML-CHAR:"); } else { output.append("&#x"); } String hex = Integer.toHexString(c); for (int ii = 0; ii < 4 - hex.length(); ii++) { output.append("0"); } output.append(hex); output.append(";"); } else { output.append(c); } } } return output.toString(); }
From source file:org.opennms.netmgt.snmp.snmp4j.Snmp4JValue.java
private String toStringDottingCntrlChars(final byte[] value) { final byte[] results = new byte[value.length]; for (int i = 0; i < value.length; i++) { results[i] = Character.isISOControl((char) value[i]) ? (byte) '.' : value[i]; }/*from w w w . j a v a2 s . c om*/ return new String(results); }
From source file:htsjdk.samtools.reference.FastaReferenceWriter.java
private static String checkDescription(final String description) { if (description == null || description.isEmpty()) { return ""; }/*from w w w.j ava 2 s. c om*/ for (int i = 0; i < description.length(); i++) { final char c = description.charAt(i); if (Character.isISOControl(c) && c != '\t') { // tab is the only valid control char in the description. throw new IllegalArgumentException( "the input name contains non-tab control characters: '" + description + "'"); } } return description; }
From source file:org.codelibs.fess.helper.ViewHelper.java
protected String escapeHighlight(final String text) { final String escaped = LaFunctions.h(text); int pos = escaped.indexOf(escapedHighlightPre); while (pos >= 0) { int c = escaped.codePointAt(pos); if (Character.isISOControl(c) || hihglightTerminalCharSet.contains(c)) { break; }//from w w w. j a v a2 s . c o m pos--; } final String value = escaped.substring(pos + 1); return value.replaceAll(escapedHighlightPre, highlightTagPre).replaceAll(escapedHighlightPost, highlightTagPost); }
From source file:com.loopeer.codereader.api.HttpJsonLoggingInterceptor.java
/** * Returns true if the body in question probably contains human readable text. Uses a small sample * of code points to detect unicode control characters commonly used in binary file signatures. *///from ww w . j ava2s . com static boolean isPlaintext(Buffer buffer) { try { Buffer prefix = new Buffer(); long byteCount = buffer.size() < 64 ? buffer.size() : 64; buffer.copyTo(prefix, 0, byteCount); for (int i = 0; i < 16; i++) { if (prefix.exhausted()) { break; } int codePoint = prefix.readUtf8CodePoint(); if (Character.isISOControl(codePoint) && !Character.isWhitespace(codePoint)) { return false; } } return true; } catch (EOFException e) { return false; // Truncated UTF-8 sequence. } }
From source file:com.gatf.xstream.GatfPrettyPrintWriter.java
private void writeText(String text, boolean isAttribute) { int length = text.length(); for (int i = 0; i < length; i++) { char c = text.charAt(i); switch (c) { case '\0': if (mode == XML_QUIRKS) { this.writer.write(NULL); } else { throw new StreamException("Invalid character 0x0 in XML stream"); }/*from www . j a va 2 s .c o m*/ break; case '&': this.writer.write(AMP); break; case '<': this.writer.write(LT); break; case '>': this.writer.write(GT); break; case '"': this.writer.write(QUOT); break; case '\'': this.writer.write(APOS); break; case '\r': this.writer.write(CR); break; case '\t': case '\n': if (!isAttribute) { this.writer.write(c); break; } default: if (Character.isDefined(c) && !Character.isISOControl(c)) { if (mode != XML_QUIRKS) { if (c > '\ud7ff' && c < '\ue000') { throw new StreamException( "Invalid character 0x" + Integer.toHexString(c) + " in XML stream"); } } this.writer.write(c); } else { if (mode == XML_1_0) { if (c < 9 || c == '\u000b' || c == '\u000c' || c == '\u000e' || (c >= '\u000f' && c <= '\u001f')) { throw new StreamException( "Invalid character 0x" + Integer.toHexString(c) + " in XML 1.0 stream"); } } if (mode != XML_QUIRKS) { if (c == '\ufffe' || c == '\uffff') { throw new StreamException( "Invalid character 0x" + Integer.toHexString(c) + " in XML stream"); } } this.writer.write("&#x"); this.writer.write(Integer.toHexString(c)); this.writer.write(';'); } } } }