List of usage examples for java.lang StringBuilder charAt
char charAt(int index);
From source file:com.dalabs.droop.util.OptionsFileUtil.java
/** * Expands any options file that may be present in the given set of arguments. * * @param args the given arguments/*from www .j av a 2 s . c o m*/ * @return a new string array that contains the expanded arguments. * @throws Exception */ public static String[] expandArguments(String[] args) throws Exception { List<String> options = new ArrayList<String>(); for (int i = 0; i < args.length; i++) { if (args[i].equals(Droop.DROOP_OPTIONS_FILE_SPECIFIER)) { if (i == args.length - 1) { throw new Exception("Missing options file"); } String fileName = args[++i]; File optionsFile = new File(fileName); BufferedReader reader = null; StringBuilder buffer = new StringBuilder(); try { reader = new BufferedReader(new FileReader(optionsFile)); String nextLine = null; while ((nextLine = reader.readLine()) != null) { nextLine = nextLine.trim(); if (nextLine.length() == 0 || nextLine.startsWith("#")) { // empty line or comment continue; } buffer.append(nextLine); if (nextLine.endsWith("\\")) { if (buffer.charAt(0) == '\'' || buffer.charAt(0) == '"') { throw new Exception("Multiline quoted strings not supported in file(" + fileName + "): " + buffer.toString()); } // Remove the trailing back-slash and continue buffer.deleteCharAt(buffer.length() - 1); } else { // The buffer contains a full option options.add(removeQuotesEncolosingOption(fileName, buffer.toString())); buffer.delete(0, buffer.length()); } } // Assert that the buffer is empty if (buffer.length() != 0) { throw new Exception( "Malformed option in options file(" + fileName + "): " + buffer.toString()); } } catch (IOException ex) { throw new Exception("Unable to read options file: " + fileName, ex); } finally { if (reader != null) { try { reader.close(); } catch (IOException ex) { LOG.info("Exception while closing reader", ex); } } } } else { // Regular option. Parse it and put it on the appropriate list options.add(args[i]); } } return options.toArray(new String[options.size()]); }
From source file:com.cloudera.sqoop.util.OptionsFileUtil.java
/** * Expands any options file that may be present in the given set of arguments. * * @param args the given arguments/*from w w w .j ava 2 s . c om*/ * @return a new string array that contains the expanded arguments. * @throws Exception */ public static String[] expandArguments(String[] args) throws Exception { List<String> options = new ArrayList<String>(); for (int i = 0; i < args.length; i++) { if (args[i].equals(Sqoop.SQOOP_OPTIONS_FILE_SPECIFIER)) { if (i == args.length - 1) { throw new Exception("Missing options file"); } String fileName = args[++i]; File optionsFile = new File(fileName); BufferedReader reader = null; StringBuilder buffer = new StringBuilder(); try { reader = new BufferedReader(new FileReader(optionsFile)); String nextLine = null; while ((nextLine = reader.readLine()) != null) { nextLine = nextLine.trim(); if (nextLine.length() == 0 || nextLine.startsWith("#")) { // empty line or comment continue; } buffer.append(nextLine); if (nextLine.endsWith("\\")) { if (buffer.charAt(0) == '\'' || buffer.charAt(0) == '"') { throw new Exception("Multiline quoted strings not supported in file(" + fileName + "): " + buffer.toString()); } // Remove the trailing back-slash and continue buffer.deleteCharAt(buffer.length() - 1); } else { // The buffer contains a full option options.add(removeQuotesEncolosingOption(fileName, buffer.toString())); buffer.delete(0, buffer.length()); } } // Assert that the buffer is empty if (buffer.length() != 0) { throw new Exception( "Malformed option in options file(" + fileName + "): " + buffer.toString()); } } catch (IOException ex) { throw new Exception("Unable to read options file: " + fileName, ex); } finally { if (reader != null) { try { reader.close(); } catch (IOException ex) { LOG.info("Exception while closing reader", ex); } } } } else { // Regular option. Parse it and put it on the appropriate list options.add(args[i]); } } return options.toArray(new String[options.size()]); }
From source file:de.codesourcery.jasm16.utils.Misc.java
public static String removeLeadingWhitespace(String input) { StringBuilder output = new StringBuilder(input); while (output.length() > 0 && Character.isWhitespace(output.charAt(0))) { output.delete(0, 1);//www . ja va 2 s. c o m } return output.toString(); }
From source file:org.ejbca.util.StringTools.java
/** * Strips all special characters from a string by replacing them with a forward slash, '/'. * This method is used for various Strings, like SubjectDNs and usernames. * * @param str the string whose contents will be stripped. * * @return the stripped version of the input string. *//*from w w w . j av a 2s . c om*/ public static String strip(final String str) { if (str == null) { return null; } final StringBuilder buf = new StringBuilder(str); for (int i = 0; i < stripChars.length; i++) { int index = 0; int end = buf.length(); while (index < end) { if (buf.charAt(index) == stripChars[i]) { // Found an illegal character. Replace it with a '/'. buf.setCharAt(index, '/'); } else if (buf.charAt(index) == '\\') { // Found an escape character. if (index + 1 == end) { // If this is the last character we should remove it. buf.setCharAt(index, '/'); } else if (!isAllowed(buf.charAt(index + 1))) { // We did not allow this character to be escaped. Replace both the \ and the character with a single '/'. buf.setCharAt(index, '/'); buf.deleteCharAt(index + 1); end--; } else { index++; } } index++; } } return buf.toString(); }
From source file:org.loklak.geo.GeoNames.java
public static String normalize(final String text) { final StringBuilder l = new StringBuilder(); for (int i = 0; i < text.length(); i++) { final char c = text.charAt(i); if (Character.isLetterOrDigit(c)) { l.append(Character.toLowerCase(c)); } else {/*from w w w . java2 s . co m*/ if (l.length() > 0 && l.charAt(l.length() - 1) != ' ') l.append(' '); } } if (l.length() > 0 && l.charAt(l.length() - 1) == ' ') l.setLength(l.length() - 1); return l.toString(); }
From source file:com.hybridbpm.core.util.HybridbpmCoreUtil.java
public static String checkClassName(String name) { name = name.replaceAll("\\s+", "").replaceAll("\\W", ""); StringBuilder result = new StringBuilder(); for (Character c : name.toCharArray()) { if (Character.isJavaIdentifierPart(c)) { result.append(c);//w ww . j a v a2 s . c o m } else { result.append("_"); } } while (!Character.isJavaIdentifierStart(result.charAt(0))) { result.deleteCharAt(0); } return Character.toUpperCase(result.charAt(0)) + result.substring(1); }
From source file:com.hybridbpm.core.util.HybridbpmCoreUtil.java
public static String generateFieldName(String name) { String nameValue = name;/*from w w w.j av a 2s . c o m*/ StringBuilder result = new StringBuilder(); for (Character c : nameValue.toCharArray()) { if (Character.isJavaIdentifierPart(c)) { result.append(c); } else { result.append(""); } } while (!Character.isJavaIdentifierStart(result.charAt(0))) { result.deleteCharAt(0); } return Character.toLowerCase(result.charAt(0)) + result.substring(1); }
From source file:com.magic.util.StringUtil.java
/** Make sure the string starts with a forward slash but does not end with one; converts back-slashes to forward-slashes; if in String is null or empty, returns zero length string. */ public static String cleanUpPathPrefix(String prefix) { if (prefix == null || prefix.length() == 0) return ""; StringBuilder cppBuff = new StringBuilder(prefix.replace('\\', '/')); if (cppBuff.charAt(0) != '/') { cppBuff.insert(0, '/'); }/*w w w. j a va2 s. c o m*/ if (cppBuff.charAt(cppBuff.length() - 1) == '/') { cppBuff.deleteCharAt(cppBuff.length() - 1); } return cppBuff.toString(); }
From source file:com.hybridbpm.core.util.HybridbpmCoreUtil.java
public static String generateClassName(String name, String version) { StringBuilder nameValue = new StringBuilder(); nameValue.append(name != null ? name : "").append("_").append(version != null ? version : "_"); StringBuilder result = new StringBuilder(); for (Character c : nameValue.toString().toCharArray()) { if (Character.isJavaIdentifierPart(c)) { result.append(c);// w w w.ja v a 2s . c o m } else { result.append("_"); } } while (!Character.isJavaIdentifierStart(result.charAt(0))) { result.deleteCharAt(0); } return Character.toUpperCase(result.charAt(0)) + result.substring(1); }
From source file:org.apache.jackrabbit.oak.plugins.document.util.Utils.java
public static String getPreviousPathFor(String path, Revision r, int height) { if (!PathUtils.isAbsolute(path)) { throw new IllegalArgumentException("path must be absolute: " + path); }/*from ww w . ja v a 2 s . c o m*/ StringBuilder sb = new StringBuilder(path.length() + REVISION_LENGTH + 3); sb.append("p").append(path); if (sb.charAt(sb.length() - 1) != '/') { sb.append('/'); } r.toStringBuilder(sb).append("/").append(height); return sb.toString(); }