Example usage for java.util Scanner useDelimiter

List of usage examples for java.util Scanner useDelimiter

Introduction

In this page you can find the example usage for java.util Scanner useDelimiter.

Prototype

public Scanner useDelimiter(String pattern) 

Source Link

Document

Sets this scanner's delimiting pattern to a pattern constructed from the specified String .

Usage

From source file:eu.project.ttc.resources.CompostInflectionRules.java

public void load(DataResource data) throws ResourceInitializationException {
    InputStream inputStream;/*from  ww w.  j  av  a2 s.c om*/
    this.inflectionRules = Lists.newArrayList();
    try {
        inputStream = data.getInputStream();
        Scanner scanner = null;
        try {
            scanner = new Scanner(inputStream, "UTF-8");
            scanner.useDelimiter(TermSuiteConstants.LINE_BREAK);
            while (scanner.hasNext()) {
                String rawLine = scanner.next();
                String line = rawLine.split(";")[0];
                String[] args = line.split(",");
                if (args.length != 2 && !line.trim().isEmpty()) {
                    LOGGER.warn("Bad inflection rules format: " + rawLine);
                } else {
                    this.inflectionRules.add(new InflectionRule(args[0].trim(), args[1].trim()));
                }
            }
            this.inflectionRules = ImmutableList.copyOf(this.inflectionRules);
        } catch (Exception e) {
            throw new ResourceInitializationException(e);
        } finally {
            IOUtils.closeQuietly(scanner);
            IOUtils.closeQuietly(inputStream);
        }
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    }
}

From source file:org.trafodion.rest.util.NetworkConfiguration.java

public void checkCloud() {
    //Ideally we want to use http://jclouds.apache.org/ so we can support all cloud providers.
    //For now, use OpenStack Nova to retrieve int/ext network address map.
    LOG.info("Checking Cloud environment");
    String cloudCommand = conf.get(Constants.REST_CLOUD_COMMAND, Constants.DEFAULT_REST_CLOUD_COMMAND);
    ScriptContext scriptContext = new ScriptContext();
    scriptContext.setScriptName(Constants.SYS_SHELL_SCRIPT_NAME);
    scriptContext.setCommand(cloudCommand);
    LOG.info(scriptContext.getScriptName() + " exec [" + scriptContext.getCommand() + "]");
    ScriptManager.getInstance().runScript(scriptContext);//This will block while script is running

    StringBuilder sb = new StringBuilder();
    sb.append(scriptContext.getScriptName() + " exit code [" + scriptContext.getExitCode() + "]");
    if (!scriptContext.getStdOut().toString().isEmpty())
        sb.append(", stdout [" + scriptContext.getStdOut().toString() + "]");
    if (!scriptContext.getStdErr().toString().isEmpty())
        sb.append(", stderr [" + scriptContext.getStdErr().toString() + "]");
    LOG.info(sb.toString());/*  ww  w  .  j  a v  a  2s  .  c  om*/

    if (!scriptContext.getStdOut().toString().isEmpty()) {
        Scanner scn = new Scanner(scriptContext.getStdOut().toString());
        scn.useDelimiter(",");
        intHostAddress = scn.next();//internal ip
        extHostAddress = scn.next();//external ip      
        scn.close();
        LOG.info("Cloud environment found");
    } else
        LOG.info("Cloud environment not found");
}

From source file:org.sipfoundry.sipxconfig.conference.FreeswitchApiResultParserImpl.java

private ActiveConferenceMember parseConferenceMember(String line, String conferenceName) {
    ActiveConferenceMember member = new ActiveConferenceMember();

    Scanner scan = new Scanner(line);
    scan.useDelimiter(COMMAND_LIST_DELIM);

    member.setId(scan.nextInt());//  w  ww . j  a  v  a2s .com

    String sipAddress = scan.next().split("/")[2];

    member.setUuid(scan.next());

    String callerIdName = scan.next();
    if (callerIdName.equals(conferenceName)) {
        callerIdName = "";
    }

    scan.next(); // skip caller ID number

    String permissions = scan.next();
    member.setCanHear(permissions.contains("hear"));
    member.setCanSpeak(permissions.contains("speak"));

    member.setName(callerIdName + " (" + sipAddress + ")");

    member.setVolumeIn(scan.nextInt());
    member.setVolumeOut(scan.nextInt());
    member.setEnergyLevel(scan.nextInt());
    return member;
}

From source file:edu.harvard.hul.ois.fits.junit.AudioStdSchemaTestXmlUnit_NoMD5.java

@Test
public void testAudioMD_noMD5() throws Exception {

    Fits fits = new Fits();

    // First generate the FITS output
    File input = new File("testfiles/test.wav");
    FitsOutput fitsOut = fits.examine(input);

    XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat());
    String actualXmlStr = serializer.outputString(fitsOut.getFitsXml());

    // Read in the expected XML file
    Scanner scan = new Scanner(new File("testfiles/output/FITS_test_wav_NO_MD5.xml"));
    String expectedXmlStr = scan.useDelimiter("\\Z").next();
    scan.close();/*www. j a  v  a2 s.  com*/

    // 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", "lastmodified", "startDate", "startTime", "timestamp",
            "fitsExecutionTime", "executionTime", "filepath", "lastmodified", "location"));

    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:ch.cyberduck.core.importer.WinScpBookmarkCollection.java

@Override
protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException {
    try {/*www  .jav  a2s  . com*/
        final BufferedReader in = new BufferedReader(
                new InputStreamReader(file.getInputStream(), Charset.forName("UTF-8")));
        try {
            Host current = null;
            String line;
            while ((line = in.readLine()) != null) {
                if (line.startsWith("[Sessions\\")) {
                    current = new Host(protocols.forScheme(Scheme.sftp));
                    current.getCredentials()
                            .setUsername(PreferencesFactory.get().getProperty("connection.login.anon.name"));
                    Pattern pattern = Pattern.compile("\\[Session\\\\(.*)\\]");
                    Matcher matcher = pattern.matcher(line);
                    if (matcher.matches()) {
                        current.setNickname(matcher.group(1));
                    }
                } else if (StringUtils.isBlank(line)) {
                    this.add(current);
                    current = null;
                } else {
                    if (null == current) {
                        log.warn("Failed to detect start of bookmark");
                        continue;
                    }
                    Scanner scanner = new Scanner(line);
                    scanner.useDelimiter("=");
                    if (!scanner.hasNext()) {
                        log.warn("Missing key in line:" + line);
                        continue;
                    }
                    String name = scanner.next().toLowerCase(Locale.ROOT);
                    if (!scanner.hasNext()) {
                        log.warn("Missing value in line:" + line);
                        continue;
                    }
                    String value = scanner.next();
                    if ("hostname".equals(name)) {
                        current.setHostname(value);
                    } else if ("username".equals(name)) {
                        current.getCredentials().setUsername(value);
                    } else if ("portnumber".equals(name)) {
                        try {
                            current.setPort(Integer.parseInt(value));
                        } catch (NumberFormatException e) {
                            log.warn("Invalid Port:" + e.getMessage());
                        }
                    } else if ("fsprotocol".equals(name)) {
                        try {
                            switch (Integer.parseInt(value)) {
                            case 0:
                            case 1:
                            case 2:
                                current.setProtocol(protocols.forScheme(Scheme.sftp));
                                break;
                            case 5:
                                current.setProtocol(protocols.forScheme(Scheme.ftp));
                                break;
                            }
                            // Reset port to default
                            current.setPort(-1);
                        } catch (NumberFormatException e) {
                            log.warn("Unknown Protocol:" + e.getMessage());
                        }
                    }
                }
            }
        } finally {
            IOUtils.closeQuietly(in);
        }
    } catch (IOException e) {
        throw new AccessDeniedException(e.getMessage(), e);
    }
}

From source file:com.viddu.handlebars.HandlebarsNashorn.java

@Override
public String render(InputStream templateStream, String contextJson) throws HandlebarsException {
    Scanner scanner = new Scanner(templateStream, StandardCharsets.UTF_8.name());
    String template = scanner.useDelimiter("\\A").next();
    scanner.close();//from ww  w. j  a  va 2 s . c o m
    return render(template, contextJson);
}

From source file:com.viddu.handlebars.HandlebarsNashorn.java

@Override
public String render(InputStream templateStream, Map<String, Object> context) throws HandlebarsException {
    Scanner scanner = new Scanner(templateStream, StandardCharsets.UTF_8.name());
    String template = scanner.useDelimiter("\\A").next();
    scanner.close();/*from  ww w  .ja  v  a2  s . co  m*/
    return render(template, context);
}

From source file:com.viddu.handlebars.HandlebarsNashorn.java

@Override
public String render(InputStream templateStream, Collection<?> context) throws HandlebarsException {
    Scanner scanner = new Scanner(templateStream, StandardCharsets.UTF_8.name());
    String template = scanner.useDelimiter("\\A").next();
    scanner.close();/*ww  w  .ja v  a2 s  . c o m*/
    return render(template, context);
}

From source file:com.viddu.handlebars.HandlebarsNashorn.java

@Override
public String render(InputStream templateStream, Object context) throws HandlebarsException {
    Scanner scanner = new Scanner(templateStream, StandardCharsets.UTF_8.name());
    String template = scanner.useDelimiter("\\A").next();
    scanner.close();//w  w w  .  jav  a2 s .  co m
    return render(template, context);
}

From source file:kuona.jenkins.analyser.JenkinsClient.java

/**
 * Perform a GET request and parse the response and return a simple string of the content
 *
 * @param path path to request, can be relative or absolute
 * @return the entity text//from w  w w  . j a  v  a2s  . c o  m
 * @throws IOException, HttpResponseException
 */
public String get(String path) throws IOException {
    HttpGet getMethod = new HttpGet(api(path));
    HttpResponse response = client.execute(getMethod, localContext);
    try {
        httpResponseValidator.validateResponse(response);
        Scanner s = new Scanner(response.getEntity().getContent());
        s.useDelimiter("\\z");
        StringBuffer sb = new StringBuffer();
        while (s.hasNext()) {
            sb.append(s.next());
        }
        return sb.toString();
    } finally {
        releaseConnection(getMethod);
    }
}