List of usage examples for org.apache.commons.lang CharUtils isAsciiPrintable
public static boolean isAsciiPrintable(char ch)
Checks whether the character is ASCII 7 bit printable.
From source file:com.htmlhifive.tools.codeassist.core.proposal.build.ObjectLiteralCodeBuilder.java
@Override protected void buildEnd(StringBuilder sb, StringBuilder part, int tempInsertPosition) { // ?/*from www.jav a2 s .co m*/ boolean delflg = true; int deletePosition = 0; int insertPosition = tempInsertPosition; for (int currentPosition = insertPosition - 1; currentPosition > 0; currentPosition--) { if (sb.charAt(currentPosition) == ',') { deletePosition = currentPosition; break; } if (CharUtils.isAsciiPrintable(sb.charAt(currentPosition))) { delflg = false; break; } } // while (sb.charAt(currentPosition) != ',') { // currentPosition--; // System.out.println(sb.charAt(currentPosition)); // } if (delflg) { insertPosition--; sb.deleteCharAt(deletePosition); } super.buildEnd(sb, part, insertPosition); }
From source file:mitm.common.extractor.impl.DefaultTextExtractor.java
private void readText(RewindableInputStream input, TextExtractorContext context, Writer writer) throws IOException { int c;//from w ww . j a va2s . c om while ((c = input.read()) != -1) { if (CharUtils.isAsciiPrintable((char) c)) { writer.write(c); } } }
From source file:de.interactive_instruments.ShapeChange.Model.EA.EADocument.java
/** * Replace all spaces with underscores and removes non-ASCII characters and removes ASCII characters that are not printable. * * @param filename//from w w w . j a v a 2 s . co m * @return */ private String escapeFileName(String filename) { if (filename == null) { return null; } else { StringBuilder sb = new StringBuilder(); for (int i = 0; i < filename.length(); i++) { char aChar = filename.charAt(i); if (aChar == ' ') { sb.append('_'); } else if (CharUtils.isAsciiPrintable(aChar)) { sb.append(aChar); } else { // ignore character if not ASCII printable } } return sb.toString(); } }
From source file:com.test.stringtest.StringUtils.java
/** * <p>Checks if the string contains only ASCII printable characters.</p> * // ww w . j a va 2 s . co m * <p><code>null</code> will return <code>false</code>. * An empty String ("") will return <code>true</code>.</p> * * <pre> * StringUtils.isAsciiPrintable(null) = false * StringUtils.isAsciiPrintable("") = true * StringUtils.isAsciiPrintable(" ") = true * StringUtils.isAsciiPrintable("Ceki") = true * StringUtils.isAsciiPrintable("ab2c") = true * StringUtils.isAsciiPrintable("!ab-c~") = true * StringUtils.isAsciiPrintable("\u0020") = true * StringUtils.isAsciiPrintable("\u0021") = true * StringUtils.isAsciiPrintable("\u007e") = true * StringUtils.isAsciiPrintable("\u007f") = false * StringUtils.isAsciiPrintable("Ceki G\u00fclc\u00fc") = false * </pre> * * @param str the string to check, may be null * @return <code>true</code> if every character is in the range * 32 thru 126 * @since 2.1 */ public static boolean isAsciiPrintable(String str) { if (str == null) { return false; } int sz = str.length(); for (int i = 0; i < sz; i++) { if (CharUtils.isAsciiPrintable(str.charAt(i)) == false) { return false; } } return true; }
From source file:org.apache.tajo.cli.DescTableCommand.java
protected String toFormattedString(TableDesc desc) { StringBuilder sb = new StringBuilder(); sb.append("\ntable name: ").append(desc.getName()).append("\n"); sb.append("table path: ").append(desc.getPath()).append("\n"); sb.append("store type: ").append(desc.getMeta().getStoreType()).append("\n"); if (desc.getStats() != null) { long row = desc.getStats().getNumRows(); String rowText = row == TajoClient.UNKNOWN_ROW_NUMBER ? "unknown" : row + ""; sb.append("number of rows: ").append(rowText).append("\n"); sb.append("volume: ").append(FileUtil.humanReadableByteCount(desc.getStats().getNumBytes(), true)) .append("\n"); }/*from www . ja v a 2 s. c om*/ sb.append("Options: \n"); for (Map.Entry<String, String> entry : desc.getMeta().toMap().entrySet()) { /* * Checks whether the character is ASCII 7 bit printable. * For example, a printable unicode '\u007c' become the character |. * * Control-chars : ctrl-a(\u0001), tab(\u0009) .. * Printable-chars : '|'(\u007c), ','(\u002c) .. * */ String value = entry.getValue(); String unescaped = StringEscapeUtils.unescapeJava(value); if (unescaped.length() == 1 && CharUtils.isAsciiPrintable(unescaped.charAt(0))) { value = unescaped; } sb.append("\t").append("'").append(entry.getKey()).append("'").append("=").append("'").append(value) .append("'").append("\n"); } sb.append("\n"); sb.append("schema: \n"); for (int i = 0; i < desc.getSchema().size(); i++) { Column col = desc.getSchema().getColumn(i); sb.append(col.getSimpleName()).append("\t").append(col.getDataType().getType()); if (col.getDataType().hasLength()) { sb.append("(").append(col.getDataType().getLength()).append(")"); } sb.append("\n"); } sb.append("\n"); if (desc.getPartitionMethod() != null) { PartitionMethodDesc partition = desc.getPartitionMethod(); sb.append("Partitions: \n"); sb.append("type:").append(partition.getPartitionType().name()).append("\n"); sb.append("columns:").append(":"); sb.append(TUtil.arrayToString(partition.getExpressionSchema().toArray())); } return sb.toString(); }
From source file:org.apache.tajo.cli.tsql.commands.DescTableCommand.java
protected String toFormattedString(TableDesc desc) { StringBuilder sb = new StringBuilder(); sb.append("\ntable name: ").append(desc.getName()).append("\n"); sb.append("table uri: ").append(desc.getUri()).append("\n"); sb.append("store type: ").append(desc.getMeta().getDataFormat()).append("\n"); if (desc.getStats() != null) { long row = desc.getStats().getNumRows(); String rowText = row == TajoConstants.UNKNOWN_ROW_NUMBER ? "unknown" : row + ""; sb.append("number of rows: ").append(rowText).append("\n"); sb.append("volume: ").append(FileUtil.humanReadableByteCount(desc.getStats().getNumBytes(), true)) .append("\n"); }/* ww w.j a va 2s .c o m*/ sb.append("Options:\n"); for (Map.Entry<String, String> entry : desc.getMeta().toMap().entrySet()) { /* * Checks whether the character is ASCII 7 bit printable. * For example, a printable unicode '\u007c' become the character |. * * Control-chars : ctrl-a(\u0001), tab(\u0009) .. * Printable-chars : '|'(\u007c), ','(\u002c) .. * */ String value = entry.getValue(); String unescaped = StringEscapeUtils.unescapeJava(value); if (unescaped.length() == 1 && CharUtils.isAsciiPrintable(unescaped.charAt(0))) { value = unescaped; } sb.append("\t").append("'").append(entry.getKey()).append("'").append("=").append("'").append(value) .append("'").append("\n"); } sb.append("\n"); sb.append("schema: \n"); for (int i = 0; i < desc.getSchema().size(); i++) { Column col = desc.getSchema().getColumn(i); sb.append(col.getSimpleName()).append("\t").append(col.getTypeDesc()); sb.append("\n"); } sb.append("\n"); if (desc.getPartitionMethod() != null) { PartitionMethodDesc partition = desc.getPartitionMethod(); sb.append("Partitions: \n"); sb.append("type:").append(partition.getPartitionType().name()).append("\n"); sb.append("columns:").append(":"); sb.append(StringUtils.join(partition.getExpressionSchema().toArray())); } return sb.toString(); }
From source file:org.kie.workbench.common.services.datamodeller.validation.ValidationUtils.java
public static Boolean isJavaIdentifier(String s) { if (StringUtils.isBlank(s)) return false; if (!SourceVersion.isName(s)) return false; for (int i = 0; i < s.length(); i++) { if (!CharUtils.isAsciiPrintable(s.charAt(i))) return false; }// w w w . java2 s .c om return true; }
From source file:org.owasp.jbrofuzz.core.Verifier.java
/** * <p>Return the contents of an internal file a String.</p> * //from w w w . j ava 2s. c o m * @param fileName e.g. fuzzers.jbrf; headers.jbrf * @return the contents of the file as a String * * @author subere@uncon.org * @version 2.1 * @since 2.1 */ private static String parseExtFile(String fileName) { final File inputFile = new File(System.getProperty("user.dir") + File.separator + fileName); JBroFuzzFileFilter jbfff = new JBroFuzzFileFilter(); if (!jbfff.accept(inputFile)) { return "This file is not accepted"; } if (inputFile.exists()) { if (inputFile.isDirectory()) { return "File is a directory:\n\n" + fileName; } if (!inputFile.canRead()) { return "File cannot be read:\n\n" + fileName; } } else { return "File does not exist:\n\n" + fileName; } int counter = 0; InputStream in = null; FileInputStream fis = null; final StringBuffer fileContents = new StringBuffer(); try { fis = new FileInputStream(inputFile); in = new BufferedInputStream(fis); int c; // Read, having as upper maximum the int maximum while (((c = in.read()) > 0) && (counter <= MAX_CHARS)) { // Allow the character only if its printable ascii or \n if ((CharUtils.isAsciiPrintable((char) c)) || (((char) c) == '\n')) { fileContents.append((char) c); } counter++; } in.close(); fis.close(); } catch (final IOException e) { return "Attempting to open the file caused an I/O Error:\n\n" + fileName; } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(fis); } if (counter == MAX_CHARS) { final String maxMessage = "\n... stopped reading file after " + MAX_CHARS + " characters.\n"; fileContents.append(maxMessage); Logger.log(maxMessage, 3); } return fileContents.toString(); }
From source file:org.owasp.jbrofuzz.core.Verifier.java
/** * <p>Return the contents of any .jbrf file, given the * file's absolute path.</p>//from w w w . ja v a 2 s. co m * * @param fuzzersFilePath The absolute path pointing to * a .jbrf file * @return the contents of the file as a String * * @author subere@uncon.org * @version 2.1 * @since 2.1 */ private static String parseExtFilePath(String fuzzersFilePath) { final File inputFile = new File(fuzzersFilePath); if (inputFile.exists()) { if (inputFile.isDirectory()) { return "File is a directory:\n\n" + fuzzersFilePath; } if (!inputFile.canRead()) { return "File cannot be read:\n\n" + fuzzersFilePath; } } else { return "File does not exist:\n\n" + fuzzersFilePath; } int counter = 0; InputStream in = null; FileInputStream fis = null; final StringBuffer fileContents = new StringBuffer(); try { fis = new FileInputStream(inputFile); in = new BufferedInputStream(fis); int c; // Read, having as upper maximum the int maximum while (((c = in.read()) > 0) && (counter <= MAX_CHARS)) { // Allow the character only if its printable ascii or \n if ((CharUtils.isAsciiPrintable((char) c)) || (((char) c) == '\n')) { fileContents.append((char) c); } counter++; } in.close(); fis.close(); } catch (final IOException e) { return "Attempting to open the file caused an I/O Error:\n\n" + fuzzersFilePath; } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(fis); } if (counter == MAX_CHARS) { final String maxMessage = "\n... stopped reading file after " + MAX_CHARS + " characters.\n"; fileContents.append(maxMessage); Logger.log(maxMessage, 3); } return fileContents.toString(); }
From source file:org.owasp.jbrofuzz.core.Verifier.java
/** * <p>Return the contents of an internal file a String.</p> * //from w w w . j a v a 2s .co m * @param fileName e.g. fuzzers.jbrf; headers.jbrf * @return the contents of the file as a String * * @author subere@uncon.org * @version 2.0 * @since 2.0 */ private static String parseFile(String fileName) { final StringBuffer fileContents = new StringBuffer(); // Attempt to read from the jar file final URL fileURL = ClassLoader.getSystemClassLoader().getResource(fileName); if (fileURL == null) { throw new RuntimeException(ERROR_MSG + "could not find " + fileName); } // Read the characters from the file BufferedReader in = null; try { final URLConnection connection = fileURL.openConnection(); connection.connect(); in = new BufferedReader(new InputStreamReader(connection.getInputStream())); int counter = 0; int c; while (((c = in.read()) > 0) && (counter < MAX_CHARS)) { // Allow the character only if its printable ascii or \n if ((CharUtils.isAsciiPrintable((char) c)) || (((char) c) == '\n')) { fileContents.append((char) c); } counter++; } in.close(); if (counter == MAX_CHARS) { throw new RuntimeException(ERROR_MSG + "\n... stopped reading file :" + fileName + "\nafter " + MAX_CHARS + " characters.\n\n"); } } catch (final IOException e1) { throw new RuntimeException(ERROR_MSG + "could not read " + fileName); } finally { IOUtils.closeQuietly(in); } return fileContents.toString(); }