/** * Splits a string on the given delimiter. * Does include all empty elements on the split. * * @param words the words will be added to this collection. * * @return the collection provided in words parameter */ public static <C extends Collection<String>> C splitString(String line, char delim, C words) { return splitString(line, 0, line.length(), delim, words); }
/** * Splits a string on the given delimiter over the given range. * Does include all empty elements on the split. * * @return the modifiable list from the split */ public static List<String> splitString(String line, int begin, int end, char delim) { return splitString(line, begin, end, delim, new ArrayList<String>()); }
/** * Splits a string on the given delimiter. * Does include all empty elements on the split. * * @return the modifiable list from the split */ public static List<String> splitString(String line, char delim) { return splitString(line, 0, line.length(), delim, new ArrayList<String>()); }
/** * Gets the number of addresses in an address list. The number of addresses is equal to the number * of non-blank lines. */ public int getAddressListCount() throws IOException, SQLException { String list=getAddressList(); List<String> lines=StringUtility.splitString(list, '\n'); int count=0; for(String line : lines) { if(line.trim().length()>0) count++; } return count; }
private void init(String parameters, String encoding) throws UnsupportedEncodingException { for(String nameValue : StringUtility.splitString(parameters, '&')) { int pos = nameValue.indexOf('='); String name; String value; if(pos==-1) { name = URLDecoder.decode(nameValue, encoding); value = ""; // Servlet environment treats no equal sign same as value equal empty string - matching here } else { name = URLDecoder.decode(nameValue.substring(0, pos), encoding); value = URLDecoder.decode(nameValue.substring(pos+1), encoding); } addParameter(name, value); } }
public static Map<String,String> parseQueryString(String queryString) throws UnsupportedEncodingException { if(queryString==null) return null; String requestEncoding = ServletUtil.getRequestEncoding(getRequest()); List<String> pairs = StringUtility.splitString(queryString, '&'); Map<String,String> params = new LinkedHashMap<String,String>(pairs.size() * 4/3 + 1); for(String pair : pairs) { int equalPos = pair.indexOf('='); String name, value; if(equalPos==-1) { name = URLDecoder.decode(pair, requestEncoding); value = ""; } else { name = URLDecoder.decode(pair.substring(0, equalPos), requestEncoding); value = URLDecoder.decode(pair.substring(equalPos + 1), requestEncoding); } if(!params.containsKey(name)) params.put(name, value); } return params; }
/** * Gets the ticket category in "/ path" form. */ private TicketCategory getTicketCategory(String path) throws IllegalArgumentException, IOException, SQLException { TicketCategory tc = null; for(String name : StringUtility.splitString(path, '/')) { TicketCategory newTc = connector.getTicketCategories().getTicketCategory(tc, name); if(newTc==null) { if(tc==null) throw new IllegalArgumentException("Unable to find top-level TicketCategory: "+name); else throw new IllegalArgumentException("Unable to TicketCategory: "+name+" in "+tc); } tc = newTc; } if(tc==null) throw new IllegalArgumentException("Unable to find TicketCategory: "+path); return tc; }
public static Integer getIntForIPAddress(String ipAddress) throws IllegalArgumentException { Integer result = intForIPAddressCache.get(ipAddress); if(result==null) { // There must be four octets with . between List<String> octets=StringUtility.splitString(ipAddress, '.'); if(octets.size()!=4) throw new IllegalArgumentException("Invalid IP address: "+ipAddress); // Each octet should be from 1 to 3 digits, all numbers // and should have a value between 0 and 255 inclusive for(int c=0;c<4;c++) { String tet=octets.get(c); int tetLen=tet.length(); if(tetLen<1 || tetLen>3) throw new IllegalArgumentException("Invalid IP address: "+ipAddress); for(int d=0;d<tetLen;d++) { char ch=tet.charAt(d); if(ch<'0' || ch>'9') throw new IllegalArgumentException("Invalid IP address: "+ipAddress); } int val=Integer.parseInt(tet); if(val<0 || val>255) throw new IllegalArgumentException("Invalid IP address: "+ipAddress); } result = (Integer.parseInt(octets.get(0))<<24) | (Integer.parseInt(octets.get(1))<<16) | (Integer.parseInt(octets.get(2))<<8) | (Integer.parseInt(octets.get(3))&255) ; Integer existing = intForIPAddressCache.putIfAbsent(ipAddress, result); if(existing!=null) result = existing; } return result; }
final int lineNum = c+1; String line = lines.get(c); List<String> fields = StringUtility.splitString(line, '\t'); if(fields.size()!=6) throw new ParseException( accessor.getMessage(
for(int i=0, numLines=lines.size(); i<numLines; i++) { String line = lines.get(i); List<String> columns = StringUtility.splitString(line, "\",\""); if(columns.size() != 15) throw new IOException("Line does not have 15 columns: " + columns.size()); String mountPoint = columns.get(0);
for(String line : lines) { lineNum++; List<String> values = StringUtility.splitString(line, '\t'); if(values.size() != 3) { throw new ParseException(
nameWords=StringUtility.splitString(name); int len = nameWords.length; for (int c = 0; c < len; c++) nameWords[c]=nameWords[c].toLowerCase(); versionWords = StringUtility.splitString(version); int len = versionWords.length; for (int c = 0; c < len; c++) versionWords[c]=versionWords[c].toLowerCase();
final int lineNum = c+1; String line = lines.get(c); List<String> fields = StringUtility.splitString(line, '\t'); if(fields.size()!=5) throw new ParseException( accessor.getMessage(
if(result.getExitVal() != 0) throw new IOException("Unable to get status: " + result.getStderr()); List<String> split = new ArrayList<>(StringUtility.splitString(result.getStdout(), (char)0)); if(!split.isEmpty()) {
for(String line : lines) { lineNum++; List<String> values = StringUtility.splitString(line, '\t'); if(values.size() != 7) { throw new ParseException(
final int lineNum = c+1; final String line = lines.get(c); final List<String> fields = StringUtility.splitString(line, '\t'); if(fields.size()!=7) throw new ParseException( accessor.getMessage( final int stripeCount = Integer.parseInt(fields.get(4).trim()); final long segStartPe = Long.parseLong(fields.get(5).trim()); final List<String> segPeRanges = StringUtility.splitString(fields.get(6).trim(), ' ');
List<String> tcolumns=StringUtility.splitString(columnName, ','); int addPos=d--; int numAdded=0; while(c<argCount) { String columnName=args[c++]; List<String> exprs=StringUtility.splitString(columnName, ','); for(int d=0;d<exprs.size();d++) { String expr=exprs.get(d).trim();
response = StringUtility.splitString(responseString, X_DELIM_CHAR); if(response.size()<68) throw new Exception("Not enough fields in response"); for(int i=0; i<response.size(); i++) {