List of usage examples for java.util Scanner useDelimiter
public Scanner useDelimiter(String pattern)
From source file:edu.harvard.hul.ois.fits.junit.VideoStdSchemaTestXmlUnit.java
@Test public void testVideoXmlUnitCombinedOutput_AVC() throws Exception { File input = new File("testfiles/FITS-SAMPLE-44_1_1_4_4_4_6_1_1_2_3_1.mp4"); Fits fits = new Fits(); FitsOutput fitsOut = fits.examine(input); // Output stream for FITS to write to ByteArrayOutputStream out = new ByteArrayOutputStream(); // Create combined output in the stream passed in Fits.outputStandardCombinedFormat(fitsOut, out); // Turn output stream into a String HtmlUnit can use String actualXmlStr = new String(out.toByteArray(), "UTF-8"); // Read in the expected XML file Scanner scan = new Scanner( new File("testfiles/output/FITS-SAMPLE-44_1_1_4_4_4_6_1_1_2_3_1_mp4_Combined.xml")); String expectedXmlStr = scan.useDelimiter("\\Z").next(); scan.close();/* w w w . j a v a2s .co m*/ // Set up XMLUnit XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalizeWhitespace(true); Diff diff = new Diff(expectedXmlStr, actualXmlStr); // Initialize attributes or elements to ignore for difference checking diff.overrideDifferenceListener(new IgnoreNamedElementsDifferenceListener("version", "toolversion", "dateModified", "fslastmodified", "startDate", "startTime", "timestamp", "fitsExecutionTime", "executionTime", "filepath", "location", "ebucore:locator")); DetailedDiff detailedDiff = new DetailedDiff(diff); // Display any Differences List<Difference> diffs = detailedDiff.getAllDifferences(); if (!diff.identical()) { StringBuffer differenceDescription = new StringBuffer(); differenceDescription.append(diffs.size()).append(" differences"); System.out.println(differenceDescription.toString()); for (Difference difference : diffs) { System.out.println(difference.toString()); } } assertTrue("Differences in XML", diff.identical()); }
From source file:edu.american.student.stonewall.display.html.framework.HTMLElement.java
private List<Browser> getBrowsersToCheck() { List<Browser> toReturn = new ArrayList<Browser>(); InputStream is = this.getClass().getClassLoader().getResourceAsStream("browsers.conf"); if (is != null) { Scanner in = new Scanner(is); in.useDelimiter("\n"); while (in.hasNext()) { String line = in.next(); toReturn.add(Browser.getBrowser(line)); }/* ww w .j av a 2s. co m*/ } else { log.warn("Ignoring browser check. browsers.conf not found!"); } return toReturn; }
From source file:edu.harvard.hul.ois.fits.junit.VideoStdSchemaTestXmlUnit.java
@Test public void testVideoXmlUnitStandardOutput_AVC() throws Exception { // First generate the FITS output File input = new File("testfiles/FITS-SAMPLE-44_1_1_4_4_4_6_1_1_2_3_1.mp4"); Fits fits = new Fits(); FitsOutput fitsOut = fits.examine(input); // Output stream for FITS to write to ByteArrayOutputStream out = new ByteArrayOutputStream(); // Create standard output in the stream passed in Fits.outputStandardSchemaXml(fitsOut, out); // Turn output stream into a String HtmlUnit can use String actualXmlStr = new String(out.toByteArray(), "UTF-8"); // Read in the expected XML file Scanner scan = new Scanner( new File("testfiles/output/FITS-SAMPLE-44_1_1_4_4_4_6_1_1_2_3_1_mp4_FITS_Standard.xml")); String expectedXmlStr = scan.useDelimiter("\\Z").next(); scan.close();/* w w w .j a v a2 s . c o m*/ // Set up XMLUnit XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalizeWhitespace(true); Diff diff = new Diff(expectedXmlStr, actualXmlStr); // Initialize attributes or elements to ignore for difference checking diff.overrideDifferenceListener(new IgnoreNamedElementsDifferenceListener("version", "toolversion", "dateModified", "fslastmodified", "startDate", "startTime", "timestamp", "fitsExecutionTime", "executionTime", // Not in Standard Output //"filepath", //"location", "ebucore:locator")); DetailedDiff detailedDiff = new DetailedDiff(diff); // Display any Differences List<Difference> diffs = detailedDiff.getAllDifferences(); if (!diff.identical()) { StringBuffer differenceDescription = new StringBuffer(); differenceDescription.append(diffs.size()).append(" differences"); System.out.println(differenceDescription.toString()); for (Difference difference : diffs) { System.out.println(difference.toString()); } } assertTrue("Differences in XML", diff.identical()); }
From source file:com.jayway.restassured.internal.http.URIBuilder.java
/** * Adds all parameters within the Scanner to the list of * <code>parameters</code>, as encoded by <code>encoding</code>. For * example, a scanner containing the string <code>a=1&b=2&c=3</code> would * add the {@link NameValuePair NameValuePairs} a=1, b=2, and c=3 to the * list of parameters./*from w w w. ja v a2 s. co m*/ * <p> * Note that this method has been copied from {@link URLEncodedUtils#parse(java.util.List, java.util.Scanner, String)} but it doesn't do URL decoding. * </p> */ private List<NameValuePair> parse(URI uri) { List<NameValuePair> parameters = new ArrayList<NameValuePair>(); final String query = uri.getRawQuery(); if (query != null && query.length() > 0) { final Scanner scanner = new Scanner(query); scanner.useDelimiter(PARAMETER_SEPARATOR); while (scanner.hasNext()) { String name; String value = null; String token = scanner.next(); int i = token.indexOf(NAME_VALUE_SEPARATOR); if (i != -1) { name = token.substring(0, i).trim(); value = token.substring(i + 1).trim(); } else { name = token.trim(); } parameters.add(new BasicNameValuePair(name, value)); } } return parameters; }
From source file:files.populate.java
private void populate_reviews(Connection connection, String string) { String fileName = "/Users/yash/Documents/workspace/HW 3/data/yelp_review.json"; Path path = Paths.get(fileName); Scanner scanner = null; try {//from w w w . j a v a2s. c o m scanner = new Scanner(path); } catch (IOException e) { e.printStackTrace(); } //read file line by line scanner.useDelimiter("\n"); int i = 0; while (scanner.hasNext()) { if (i < 20) { JSONParser parser = new JSONParser(); String s = (String) scanner.next(); s = s.replace("'", "''"); JSONObject obj; try { obj = (JSONObject) parser.parse(s); String text = (String) obj.get("text"); text = text.replace("\n", ""); Map votes = (Map) obj.get("votes"); String query = "insert into yelp_reviews values (" + votes.get("useful") + "," + votes.get("funny") + "," + votes.get("cool") + ",'" + obj.get("user_id") + "','" + obj.get("review_id") + "'," + obj.get("stars") + ",'" + obj.get("date") + "','" + text + "','" + obj.get("type") + "','" + obj.get("business_id") + "')"; System.out.println(query); Statement statement = connection.createStatement(); statement.executeUpdate(query); statement.close(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } ++i; } } }
From source file:files.populate.java
private void populate_checkin(Connection connection, String string) { String fileName = "/Users/yash/Documents/workspace/HW 3/data/yelp_checkin.json"; Path path = Paths.get(fileName); Scanner scanner = null; try {/*w w w .j a v a 2 s . c o m*/ scanner = new Scanner(path); } catch (IOException e) { e.printStackTrace(); } //read file line by line scanner.useDelimiter("\n"); int i = 0; while (scanner.hasNext()) { if (i < 20) { JSONParser parser = new JSONParser(); String s = (String) scanner.next(); s = s.replace("'", "''"); JSONObject obj; try { obj = (JSONObject) parser.parse(s); Map checkin_info = (Map) obj.get("checkin_info"); Set keys = checkin_info.keySet(); Object[] days = keys.toArray(); Statement statement = connection.createStatement(); for (int j = 0; j < days.length; ++j) { // String thiskey = days[j].toString(); String q3 = "insert into yelp_checkin values ('" + obj.get("business_id") + "','" + obj.get("type") + "','" + thiskey + "','" + checkin_info.get(thiskey) + "')"; // statement.executeUpdate(q3); } statement.close(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } ++i; } else { break; } } }
From source file:com.zilotti.hostsjuggler.view.ActiveHostsFileWindow.java
private void highlightActiveHostsFile(File hostsFile) throws IOException, ParseException { BufferedReader br = null;/* w ww. j ava2 s .c o m*/ try { /* Converts the file to text */ // StringReader fileReader = new StringReader(getLinuxHostsFile()); // For testing br = new BufferedReader(new FileReader(hostsFile)); /* Character counter */ int charCounter = 0; /* Line counter */ int lineCounter = 1; /* Line */ String line = null; while ((line = br.readLine()) != null) { line += "\n"; activeHostsFileStyledText.append(line); /* * Remark line */ if (line.startsWith(REM_LINE_CHAR)) { int prevCharCounter = charCounter; charCounter += line.length(); formatRemark(prevCharCounter, charCounter); if (log.isTraceEnabled()) { log.trace("line ='" + line + "'"); //log.trace("remark='"+ getWindowsHostsFile().substring(prevCharCounter, charCounter) +"' ("+ prevCharCounter +","+ charCounter +")"); } } else if (StringUtils.isBlank(line)) // Empty line { charCounter += line.length(); } else // Expects a host line { int localCharCounter = charCounter; charCounter += line.length(); Scanner scanner = new Scanner(line); scanner.useDelimiter(Pattern.compile("(\\s)")); /* Output of the parsing code */ String ipAddress = null; /* Verifies the number of tokens. At least two must exist (IP address and one name) */ if (scanner.hasNext()) { /* The first token must be an IP address */ { ipAddress = scanner.next(); if (!NetworkUtils.isIpAddress(ipAddress)) throw new ParseException("IP address expected. Token found: " + ipAddress, lineCounter); int prevCharCounter = localCharCounter; localCharCounter += ipAddress.length() + 1; // Sums 1 because of the lost space formatIpAddress(prevCharCounter, localCharCounter); } /* The remaining tokens are the host names associated to the IP address */ { while (scanner.hasNext()) { String hostName = scanner.next(); if (StringUtils.isWhitespace(hostName) || StringUtils.isBlank(hostName)) { localCharCounter++; } else if (NetworkUtils.isHostName(hostName)) { int prevCharCounter = localCharCounter; localCharCounter += hostName.length() + 1; // 1 to compensate the space lost // if(log.isTraceEnabled()) // log.trace("hostName='"+ getWindowsHostsFile().substring(prevCharCounter, localCharCounter) +"' ("+ prevCharCounter +","+ localCharCounter +")"); formatHostName(prevCharCounter, localCharCounter); } else throw new ParseException("Host name expected at token " + localCharCounter + ". Found: " + hostName, lineCounter); } } } else throw new ParseException("At least 2 tokens are expected from a host line.", lineCounter); } lineCounter++; } } finally { if (br != null) br.close(); } }
From source file:files.populate.java
void populate_users(Connection connection, String filename) { String fileName = "/Users/yash/Documents/workspace/HW 3/data/yelp_user.json"; Path path = Paths.get(fileName); Scanner scanner = null; try {// w w w . j a v a 2s . c o m scanner = new Scanner(path); } catch (IOException e) { e.printStackTrace(); } //read file line by line scanner.useDelimiter("\n"); int i = 0; while (scanner.hasNext()) { if (i < 500) { JSONParser parser = new JSONParser(); String s = (String) scanner.next(); JSONObject obj; try { obj = (JSONObject) parser.parse(s); Map votes = (Map) obj.get("votes"); ArrayList friends; friends = (ArrayList) obj.get("friends"); Map compliments = (Map) obj.get("compliments"); // String query = "INSERT INTO YELP_USERS (user_id,yelping_since,name,fans,average_stars,type,review_count,VOTES_FUNNY,VOTES_COOL,VOTES_USEFUL) VALUES('" + obj.get("user_id") + "','" + obj.get("yelping_since") + "','" + obj.get("name") + "'," + obj.get("fans") + "," + obj.get("average_stars") + ",'" + obj.get("type") + "'," + obj.get("review_count") + "," + votes.get("funny") + "," + votes.get("cool") + "," + votes.get("useful") + ")"; System.out.println(query); Statement statement = connection.createStatement(); statement.executeUpdate(query); for (int j = 0; j < friends.size(); ++j) { String q2 = "insert into users_friends values ('" + obj.get("user_id") + "','" + friends.get(j) + "')"; System.out.println(q2); statement.executeUpdate(q2); } Set keys = compliments.keySet(); Object[] keys1 = keys.toArray(); for (int j = 0; j < keys1.length; ++j) { // String q2 = "insert into users_friends values ("+obj.get("user_id")+","+compliments.get(j)+")"; String thiskey = keys1[j].toString(); long val = (long) compliments.get(thiskey); String q3 = "insert into users_compliments values ('" + obj.get("user_id") + "','" + thiskey + "'," + val + ")"; System.out.println(q3); statement.executeUpdate(q3); } statement.close(); } catch (ParseException ex) { Logger.getLogger(populate.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(populate.class.getName()).log(Level.SEVERE, null, ex); } i++; } else break; } scanner.close(); }
From source file:openscim.restful.server.resources.group.ldap.LdapGroupResource.java
@Override public Response createGroup(UriInfo uriInfo, Group group) { // check the ldap template has been setup correctly if (ldapTemplate != null) { // create the mapper if it doesn't already exists if (mapper == null) mapper = new GroupAttributesMapper(properties); // build the group dn String dn = group.getId(); if (properties .getProperty(GroupAttributesMapper.CONCEAL_GROUP_DNS, GroupAttributesMapper.DEFAULT_CONCEAL_GROUP_DNS) .equalsIgnoreCase(GroupAttributesMapper.DEFAULT_CONCEAL_GROUP_DNS)) { // utilise ldap formated dn dn = properties.getProperty(GroupAttributesMapper.GID_ATTRIBUTE, GroupAttributesMapper.DEFAULT_GID_ATTRIBUTE) + "=" + group.getId() + "," + properties.getProperty(GroupAttributesMapper.GROUP_BASEDN, GroupAttributesMapper.DEFAULT_GROUP_BASEDN); }// ww w. j a v a 2 s. c o m try { try { // retrieve the group Group lookedGroup = (Group) ldapTemplate.lookup(dn, mapper); // check if the group was found if (lookedGroup != null) { // user already exists return ResourceUtilities.buildErrorResponse(HttpStatus.CONFLICT, HttpStatus.CONFLICT.getMessage() + ": Resource " + dn + " already exists"); } } catch (Exception nException) { // group not found, do nothing } Attributes groupAttributes = new BasicAttributes(); // get the objectclasses String objectclasses = properties.getProperty(GroupAttributesMapper.GROUP_OBJECTCLASS_ATTRIBUTE, GroupAttributesMapper.DEFAULT_GROUP_OBJECTCLASS_ATTRIBUTE); // set the objectclass of the group Scanner scanner = new Scanner(objectclasses); scanner.useDelimiter(","); while (scanner.hasNext()) { groupAttributes.put("objectclass", scanner.next()); } // set the gid String gidAtttributeName = properties.getProperty(GroupAttributesMapper.GID_ATTRIBUTE, GroupAttributesMapper.DEFAULT_GID_ATTRIBUTE); groupAttributes.put(gidAtttributeName, group.getId()); // get the member attribute name String memberAtttributeName = properties.getProperty(GroupAttributesMapper.MEMBER_ATTRIBUTE, GroupAttributesMapper.DEFAULT_MEMBER_ATTRIBUTE); // set the members Attribute memberAttribute = new BasicAttribute(memberAtttributeName); if (group.getAny() instanceof List) { List members = (List) group.getAny(); for (Object object : members) { if (object instanceof PluralAttribute) { PluralAttribute member = (PluralAttribute) object; String uid = member.getValue(); // build the user dn String userdn = uid; if (properties.getProperty(UserAttributesMapper.CONCEAL_ACCOUNT_DNS, "true") .equalsIgnoreCase("true")) { // utilise ldap formated dn userdn = properties.getProperty(UserAttributesMapper.UID_ATTRIBUTE, UserAttributesMapper.DEFAULT_UID_ATTRIBUTE) + "=" + uid + "," + properties.getProperty(UserAttributesMapper.ACCOUNT_BASEDN, UserAttributesMapper.DEFAULT_ACCOUNT_BASEDN); } memberAttribute.add(userdn); } } } groupAttributes.put(memberAttribute); // create the group ldapTemplate.bind(dn, null, groupAttributes); // determine the url of the new resource URI location = new URI("/Group/" + dn); if (properties .getProperty(GroupAttributesMapper.CONCEAL_GROUP_DNS, GroupAttributesMapper.DEFAULT_CONCEAL_GROUP_DNS) .equalsIgnoreCase(GroupAttributesMapper.DEFAULT_CONCEAL_GROUP_DNS)) { location = new URI("/User/" + group.getId()); } // group stored successfully, return the group return Response.created(location).entity(group).build(); } catch (URISyntaxException usException) { // problem generating entity location logger.error("problem generating entity location"); // return a server error return ResourceUtilities.buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.NOT_IMPLEMENTED.getMessage() + ": Service Provider problem generating entity location"); } catch (Exception nException) { // problem creating group logger.error("problem creating group"); // return a server error return ResourceUtilities.buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.NOT_IMPLEMENTED.getMessage() + ": Service Provider problem creating group"); } } else { // ldap not configured logger.error("ldap not configured"); // return a server error return ResourceUtilities.buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.NOT_IMPLEMENTED.getMessage() + ": Service Provider group ldap repository not configured"); } }
From source file:com.anuta.internal.YangHelperMojo.java
private double versionCompare(String version1, String version2) { Scanner v1Scanner = new Scanner(version1); Scanner v2Scanner = new Scanner(version2); v1Scanner.useDelimiter("\\."); v2Scanner.useDelimiter("\\."); while (v1Scanner.hasNextInt() && v2Scanner.hasNextInt()) { int v1 = v1Scanner.nextInt(); int v2 = v2Scanner.nextInt(); if (v1 < v2) { return -1; } else if (v1 > v2) { return 1; }//from www . j a va 2 s . c om } if (v1Scanner.hasNextInt()) { return 1; } else if (v2Scanner.hasNextInt()) { return -1; } else { return 0; } }