Example usage for java.util Scanner hasNextLine

List of usage examples for java.util Scanner hasNextLine

Introduction

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

Prototype

public boolean hasNextLine() 

Source Link

Document

Returns true if there is another line in the input of this scanner.

Usage

From source file:com.mirth.connect.server.controllers.DefaultExtensionController.java

private List<String> parseUninstallScript(String script) {
    List<String> scriptList = new ArrayList<String>();
    StringBuilder sb = new StringBuilder();
    boolean blankLine = false;
    Scanner scanner = new Scanner(script);

    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();

        if (StringUtils.isNotBlank(line)) {
            sb.append(line + " ");
        } else {/*w  w w  .  ja  v a2  s  .co m*/
            blankLine = true;
        }

        if (blankLine || !scanner.hasNextLine()) {
            scriptList.add(sb.toString().trim());
            blankLine = false;
            sb.delete(0, sb.length());
        }
    }

    return scriptList;
}

From source file:com.telefonica.euro_iaas.paasmanager.claudia.impl.ClaudiaClientOpenStackImpl.java

private String processGpgKey(String gpgKey) {
    String processedKey = "";
    Scanner scanner = new Scanner(gpgKey);
    while (scanner.hasNextLine()) {
        processedKey = processedKey + "      " + scanner.nextLine() + "\n";
    }/*from   w ww .  ja  v a  2  s  .c  o m*/
    scanner.close();
    return processedKey;
}

From source file:com.smi.travel.monitor.MonitorAmadeus.java

@Override
void buildContentList(String file) {
    String pathFile = this.monitorDirectory + file;
    Path fFilePath;//  ww  w  . j a  v a  2  s .c  o  m
    fFilePath = Paths.get(pathFile);
    boolean pullSectionPassenger = false;
    StringBuffer passengerData = new StringBuffer();
    String key = null;
    sectionData = new MultiValueMap();

    Scanner scanner = null;
    try {
        scanner = new Scanner(fFilePath, ENCODING.name());

        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            //                System.out.println("Read** " + line);
            //                if (line.equalsIgnoreCase("END")) {
            if (line.startsWith("END")) {
                //                    System.out.println("Found ENDX and goto Save data");
                sectionData.put("I-", passengerData.toString());
                break;
            }

            //check whether in SectionPassenger
            if (pullSectionPassenger && (line.charAt(0) == 'I' && line.charAt(1) == '-')) {
                // found new passenger. Save old one
                sectionData.put("I-", passengerData.toString());
                passengerData = new StringBuffer();
            } else if (pullSectionPassenger) {
                if (line.charAt(1) == '-') {
                    key = line.substring(0, 2);
                    sectionData.put(key, line);
                }
                passengerData.append(line);
                passengerData.append("\n");
                continue;
            }

            //                System.out.println(line);
            if (line.charAt(0) == 'I' && line.charAt(1) == '-') {
                //pull all passenger data.
                pullSectionPassenger = true;
                passengerData.append(line);
                passengerData.append("\n");
                continue;
            } else if (line.charAt(1) == '-') {
                key = line.substring(0, 2);
            } else {
                key = line.substring(0, 3);
            }
            sectionData.put(key, line);
            //                System.out.println("Key " + key + " ,[" + line);
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (scanner != null) {
            scanner.close();
        }
    }
}

From source file:edu.wfu.inotado.impl.InotadoServiceImpl.java

/**
 * Validate the input string and parse it
 * // www .j a v a 2 s .  c o  m
 * @param text
 * @return
 * @throws InotadoException
 */
private Map<String, Properties> getCustomProperties(String text) throws InotadoException {
    Map<String, Properties> propMap = new HashMap<String, Properties>();
    Scanner scanner = new Scanner(text);
    String[] propKeys = null;
    String[] propValues = null;
    int ln = 0;
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        ln++;

        if (ln == 1) {
            // process header
            if (!StringUtils.containsIgnoreCase(line, "siteid")) {
                log.error("\"siteId\" is not found in the header line. Aboard operation.");
                throw new InotadoException("Header row is not properly specified");
            }
            propKeys = StringUtils.split(line, "\t");
        } else {
            // process content
            propValues = StringUtils.split(line, "\t");
            // skip to next if this line is not properly entered
            if (propValues.length < propKeys.length) {
                log.warn("There is no enough value contained in this line: " + line);
                continue;
            }
            String siteId = propValues[1];

            if (!siteService.siteExists(siteId)) {
                // not site found, skip this line
                continue;
            }

            Properties props = new Properties();
            // get properties
            for (int i = 2; i < propValues.length; i++) {
                props.put(propKeys[i], propValues[i]);
            }
            propMap.put(siteId, props);
        }
    }
    return propMap;
}

From source file:org.mrgeo.hdfs.tile.SplitFile.java

public int numSplits(final InputStream splitFileInputStream) throws IOException {
    final java.util.Scanner in = new java.util.Scanner(
            new BufferedReader(new InputStreamReader(splitFileInputStream)));
    int numSplits = 0;
    try {/*  w ww  .j  ava2  s  .c  o  m*/
        boolean firstline = true;
        boolean hasPartitionNames = false;
        while (in.hasNextLine()) {
            if (firstline) {
                firstline = false;
                final long split = ByteBuffer.wrap(Base64.decodeBase64(in.nextLine().getBytes())).getLong();
                if (split == HAS_PARTITION_NAMES) {
                    hasPartitionNames = true;
                } else {
                    numSplits++;
                }
            } else {
                in.nextLine();
                numSplits++;
                if (hasPartitionNames) {
                    in.nextLine();
                }
            }
        }
    } finally {
        in.close();
    }
    return numSplits;
}

From source file:ml.shifu.shifu.core.processor.stats.MapReducerStatsWorker.java

/**
 * Scan the stats result and save them into column configure
 * // w ww .  j a v  a 2  s  . c o  m
 * @param scanner
 *            the scanners to be read
 */
private void scanStatsResult(Scanner scanner, int ccInitSize) {
    while (scanner.hasNextLine()) {
        String[] raw = scanner.nextLine().trim().split("\\|");

        if (raw.length == 1) {
            continue;
        }

        if (raw.length < 25) {
            log.info("The stats data has " + raw.length + " fields.");
            log.info("The stats data is - " + Arrays.toString(raw));
        }

        int columnNum = Integer.parseInt(raw[0]);

        int corrColumnNum = columnNum;
        if (columnNum >= ccInitSize) {
            corrColumnNum = columnNum % ccInitSize;
        }

        try {
            ColumnConfig basicConfig = this.columnConfigList.get(corrColumnNum);
            log.debug("basicConfig is - " + basicConfig.getColumnName() + " corrColumnNum:" + corrColumnNum);

            ColumnConfig config = null;
            if (columnNum >= ccInitSize) {
                config = new ColumnConfig();
                config.setColumnNum(columnNum);
                config.setColumnName(basicConfig.getColumnName() + "_" + (columnNum / ccInitSize));
                config.setVersion(basicConfig.getVersion());
                config.setColumnType(basicConfig.getColumnType());
                config.setColumnFlag(basicConfig.getColumnFlag() == ColumnFlag.Target ? ColumnFlag.Meta
                        : basicConfig.getColumnFlag());

                log.debug("basicConfig is - " + basicConfig.getColumnName() + " corrColumnNum:" + corrColumnNum
                        + ", currColumnName: " + columnNum + ", currColumnType:" + config.getColumnType());

                this.columnConfigList.add(config);
            } else {
                config = basicConfig;
            }

            if (config.isHybrid()) {
                String[] splits = CommonUtils.split(raw[1], Constants.HYBRID_BIN_STR_DILIMETER);
                config.setBinBoundary(CommonUtils.stringToDoubleList(splits[0]));
                String binCategory = Base64Utils.base64Decode(splits[1]);
                config.setBinCategory(
                        CommonUtils.stringToStringList(binCategory, CalculateStatsUDF.CATEGORY_VAL_SEPARATOR));
            } else if (config.isCategorical()) {
                String binCategory = Base64Utils.base64Decode(raw[1]);
                config.setBinCategory(
                        CommonUtils.stringToStringList(binCategory, CalculateStatsUDF.CATEGORY_VAL_SEPARATOR));
                config.setBinBoundary(null);
            } else {
                config.setBinBoundary(CommonUtils.stringToDoubleList(raw[1]));
                config.setBinCategory(null);
            }
            config.setBinCountNeg(CommonUtils.stringToIntegerList(raw[2]));
            config.setBinCountPos(CommonUtils.stringToIntegerList(raw[3]));
            // config.setBinAvgScore(CommonUtils.stringToIntegerList(raw[4]));
            config.setBinPosCaseRate(CommonUtils.stringToDoubleList(raw[5]));
            config.setBinLength(config.getBinCountNeg().size());
            config.setKs(parseDouble(raw[6]));
            config.setIv(parseDouble(raw[7]));
            config.setMax(parseDouble(raw[8]));
            config.setMin(parseDouble(raw[9]));
            config.setMean(parseDouble(raw[10]));
            config.setStdDev(parseDouble(raw[11], Double.NaN));

            // magic?
            config.setColumnType(ColumnType.of(raw[12]));

            config.setMedian(parseDouble(raw[13]));

            config.setMissingCnt(parseLong(raw[14]));
            config.setTotalCount(parseLong(raw[15]));
            config.setMissingPercentage(parseDouble(raw[16]));

            config.setBinWeightedNeg(CommonUtils.stringToDoubleList(raw[17]));
            config.setBinWeightedPos(CommonUtils.stringToDoubleList(raw[18]));
            config.getColumnStats().setWoe(parseDouble(raw[19]));
            config.getColumnStats().setWeightedWoe(parseDouble(raw[20]));
            config.getColumnStats().setWeightedKs(parseDouble(raw[21]));
            config.getColumnStats().setWeightedIv(parseDouble(raw[22]));
            config.getColumnBinning().setBinCountWoe(CommonUtils.stringToDoubleList(raw[23]));
            config.getColumnBinning().setBinWeightedWoe(CommonUtils.stringToDoubleList(raw[24]));
            // TODO magic code?
            if (raw.length >= 26) {
                config.getColumnStats().setSkewness(parseDouble(raw[25]));
            }
            if (raw.length >= 27) {
                config.getColumnStats().setKurtosis(parseDouble(raw[26]));
            }
            if (raw.length >= 30) {
                config.getColumnStats().setValidNumCount(parseLong(raw[29]));
            }
            if (raw.length >= 31) {
                config.getColumnStats().setDistinctCount(parseLong(raw[30]));
            }
            if (raw.length >= 32) {
                if (raw[31] != null) {
                    List<String> sampleValues = Arrays.asList(Base64Utils.base64Decode(raw[31]).split(","));
                    config.setSampleValues(sampleValues);
                }
            }
            if (raw.length >= 33) {
                config.getColumnStats().set25th(parseDouble(raw[32]));
            }
            if (raw.length >= 34) {
                config.getColumnStats().set75th(parseDouble(raw[33]));
            }
        } catch (Exception e) {
            log.error(String.format("Fail to process following column : %s name: %s error: %s", columnNum,
                    this.columnConfigList.get(corrColumnNum).getColumnName(), e.getMessage()), e);
            continue;
        }
    }
}

From source file:com.joliciel.talismane.terminology.viewer.TerminologyViewerController.java

@FXML
protected void initialize() throws Exception {
    String currentDirPath = System.getProperty("user.dir");
    File confDir = new File(currentDirPath + "/conf/");
    confDir.mkdirs();/*from ww w. ja  v  a 2  s.  c o m*/
    File iniFile = new File(confDir, "talismane_terminology_viewer.ini");
    if (!iniFile.exists())
        iniFile.createNewFile();
    else {
        Scanner scanner = new Scanner(
                new BufferedReader(new InputStreamReader(new FileInputStream(iniFile), "UTF-8")));

        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            if (!line.startsWith("#")) {
                int equalsPos = line.indexOf('=');
                String parameter = line.substring(0, equalsPos);
                String value = line.substring(equalsPos + 1);
                if (parameter.equals("editor")) {
                    editor = value;
                } else if (parameter.equals("arguments")) {
                    arguments = value;
                } else if (parameter.equals("jdbc.url")) {
                    databaseURL = value;
                } else if (parameter.equals("jdbc.username")) {
                    databaseUsername = value;
                } else if (parameter.equals("jdbc.password")) {
                    databasePassword = value;
                } else if (parameter.equals("project.code")) {
                    projectCode = value;
                } else if (parameter.equals("csvSeparator")) {
                    csvSeparator = value;
                }
            }
        }
        scanner.close();
    }
}

From source file:edu.brandeis.cs.develops.eptosql.Cli.java

public void parse() throws IOException {
    CommandLineParser parser = new BasicParser();

    CodeGenerationOption cgo = CodeGenerationOption.UNNESTED;
    IROption iro = IROption.ENABLE;/* www.ja  v a  2s.  c  o m*/
    CommandLine cmd = null;
    Scanner sc = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    if (cmd.hasOption("h"))
        help();
    if (cmd.hasOption("nested"))
        cgo = CodeGenerationOption.NESTED;
    if (cmd.hasOption("disable_ir"))
        iro = IROption.DISABLE;
    if (cmd.hasOption("f")) {
        //log.log(Level.INFO, "Using cli argument -f=" + cmd.getOptionValue("f"));
        String filename = cmd.getOptionValue("f");
        sc = new Scanner(new File(filename));
    } else {
        sc = new Scanner(System.in);
    }
    String plan;
    while ((sc.hasNextLine())) {
        plan = sc.nextLine().trim();
        if (plan.length() == 0)
            continue;
        System.out.println(EPtoSQL.syncCompile(cgo, iro, plan));
    }
    sc.close();
}

From source file:com.pinterest.arcee.autoscaling.AwsAutoScalingManager.java

private Map<String, String> transformUserDataToConfigMap(String clusterName, String userData) throws Exception {
    String userDataString = userData.replace(String.format(userDataTemplate, clusterName, pinfoEnvironment),
            "");/*from   w ww  . j  a  va  2s .  c  o  m*/
    Map<String, String> resultMap = new HashMap<>();
    if (userDataString.length() == 0) {
        return resultMap;
    }

    Scanner scanner = new Scanner(userDataString);
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        List<String> config = Arrays.asList(line.split(": "));
        if (config.size() == 2) {
            resultMap.put(config.get(0), config.get(1));
        }
    }
    scanner.close();
    return resultMap;
}

From source file:org.dspace.installer_edm.InstallerCrosswalk.java

/**
 * Lee el fuente del java para introducirlo en una cadena
 *
 * @throws java.io.FileNotFoundException
 *///from  w  w  w  . j av a2 s  .  c om
protected void readCrossWalk2String() throws FileNotFoundException {
    Scanner edmCrossWalkScanner = null;
    try {
        StringBuilder fileContents = new StringBuilder((int) edmCrossWalkFile.length());
        edmCrossWalkScanner = new Scanner(edmCrossWalkFile);
        String lineSeparator = System.getProperty("line.separator");
        while (edmCrossWalkScanner.hasNextLine()) {
            fileContents.append(edmCrossWalkScanner.nextLine()).append(lineSeparator);
        }
        edmCrossWalkContent = fileContents.toString();
    } finally {
        if (edmCrossWalkScanner != null)
            edmCrossWalkScanner.close();
    }
}