Example usage for java.util Scanner nextLine

List of usage examples for java.util Scanner nextLine

Introduction

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

Prototype

public String nextLine() 

Source Link

Document

Advances this scanner past the current line and returns the input that was skipped.

Usage

From source file:org.apache.streams.datasift.serializer.DatasiftActivitySerializerTest.java

@Test
public void testConversion() throws Exception {

    Scanner scanner = StreamsScannerUtil.getInstance("/rand_sample_datasift_json.txt");

    String line = null;
    while (scanner.hasNextLine()) {
        try {//from  ww w. ja  v a  2 s . co m
            line = scanner.nextLine();
            Datasift item = MAPPER.readValue(line, Datasift.class);
            testConversion(item);
            String json = MAPPER.writeValueAsString(item);
            testDeserNoNull(json);
            testDeserNoAddProps(json);
        } catch (Exception e) {
            System.err.println(line);
            throw e;
        }
    }
}

From source file:Clases.cCifrado.java

public String pedirClave(String dato) {

    String clave = "";
    Scanner sc = new Scanner(System.in);
    Socket socket;//from   www.  ja  v a 2 s.c o m
    try {
        String ipServidor = receptor;
        int pto = puerto;
        System.out.println("conectando con el servidor...");
        socket = new Socket(ipServidor, pto);
        Scanner entrada = new Scanner(socket.getInputStream());
        PrintStream salidaServer = new PrintStream(socket.getOutputStream());
        salidaServer.println(dato);
        clave = entrada.nextLine();
        System.out.println("Dato recibido: " + clave);
        socket.close();

    } catch (IOException ex) {
        System.err.println("Cliente> " + ex.getMessage());
    }
    return clave;
}

From source file:eu.creatingfuture.propeller.blocklyprop.propeller.PropellerLoad.java

protected List<String> getPorts(String executable) {
    List<String> ports = new ArrayList<>();
    try {//from w  w w . j a va  2  s.  c  o  m
        CommandLine cmdLine = new CommandLine(executable);
        cmdLine.addArgument("-P");
        DefaultExecutor executor = new DefaultExecutor();
        //executor.setExitValues(new int[]{451, 301});

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
        executor.setStreamHandler(streamHandler);

        try {
            exitValue = executor.execute(cmdLine);
        } catch (ExecuteException ee) {
            exitValue = ee.getExitValue();
            logger.log(Level.SEVERE, "Unexpected exit value: {0}", exitValue);
            return ports;
        } finally {
            output = outputStream.toString();
        }

        /*
         if (exitValue == 301) {
         return ports;
         }
         */
        //            System.out.println("output: " + output);
        Scanner scanner = new Scanner(output);

        while (scanner.hasNextLine()) {
            ports.add(scanner.nextLine());
        }

        return ports;
    } catch (IOException ioe) {
        logger.log(Level.SEVERE, null, ioe);
        return null;
    }
}

From source file:eu.creatingfuture.propeller.webLoader.propeller.PropellerLoad.java

protected List<String> getPorts(String executable) {
    List<String> ports = new ArrayList<String>();
    try {//from   w  w  w . j  av a  2 s  .co m
        CommandLine cmdLine = new CommandLine(executable);
        cmdLine.addArgument("-P");
        DefaultExecutor executor = new DefaultExecutor();
        //executor.setExitValues(new int[]{451, 301});

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
        executor.setStreamHandler(streamHandler);

        try {
            exitValue = executor.execute(cmdLine);
        } catch (ExecuteException ee) {
            exitValue = ee.getExitValue();
            logger.log(Level.SEVERE, "Unexpected exit value: {0}", exitValue);
            return ports;
        } finally {
            output = outputStream.toString();
        }

        /*
         if (exitValue == 301) {
         return ports;
         }
         */
        //            System.out.println("output: " + output);
        Scanner scanner = new Scanner(output);

        while (scanner.hasNextLine()) {
            ports.add(scanner.nextLine());
        }

        return ports;
    } catch (IOException ioe) {
        logger.log(Level.SEVERE, null, ioe);
        return null;
    }
}

From source file:org.envirocar.harvest.TrackPublisher.java

protected String readContent(InputStream content) throws IOException {
    Scanner sc = new Scanner(content);
    StringBuilder sb = new StringBuilder(content.available());
    while (sc.hasNext()) {
        sb.append(sc.nextLine());
    }//from   ww  w .  jav a 2  s. co  m
    sc.close();
    return sb.toString();
}

From source file:com.joliciel.frenchTreebank.export.FtbPosTagMapperImpl.java

public FtbPosTagMapperImpl(File file, PosTagSet posTagSet) {
    this.posTagSet = posTagSet;
    Scanner scanner = null;
    try {//from   ww  w.j  a  v  a2s .co  m
        scanner = new Scanner(file);
        List<String> descriptors = new ArrayList<String>();
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            descriptors.add(line);
        }
        this.load(descriptors);
    } catch (FileNotFoundException e) {
        LogUtils.logError(LOG, e);
        throw new RuntimeException(e);
    }
}

From source file:hu.ppke.itk.nlpg.purepos.POSTagger.java

@Override
public void tag(Scanner scanner, PrintStream ps, int maxResultsNumber) {
    String line;/* ww  w.jav  a  2s . c om*/
    while (scanner.hasNext()) {
        line = scanner.nextLine();
        String sentString = tagAndFormat(line, maxResultsNumber);
        ps.println(sentString);

    }

}

From source file:com.joliciel.lefff.LefffPosTagMapperImpl.java

public LefffPosTagMapperImpl(File file, PosTagSet posTagSet) {
    this.posTagSet = posTagSet;
    Scanner scanner = null;
    try {// ww w  .  ja v a2  s . com
        scanner = new Scanner(file);
        List<String> descriptors = new ArrayList<String>();
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            descriptors.add(line);
        }
        this.load(descriptors);
    } catch (FileNotFoundException e) {
        LogUtils.logError(LOG, e);
        throw new RuntimeException(e);
    }
}

From source file:com.joliciel.talismane.machineLearning.TextFileResource.java

public TextFileResource(File file) {
    try {//from  w ww  .  j a  va 2  s  .  co  m
        this.name = file.getName();

        Scanner scanner = new Scanner(file);
        int numParts = -1;
        int i = 1;
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            if (line.length() > 0 && !line.startsWith("#")) {
                StringBuilder sb = new StringBuilder();
                String[] parts = line.split("\t");
                if (parts.length == 1 && line.startsWith("Name: ")) {
                    this.name = line.substring("Name: ".length());
                    i++;
                    continue;
                }
                if (parts.length == 1 && line.startsWith("Multivalued: ")) {
                    boolean multivalued = line.substring("Multivalued: ".length()).equalsIgnoreCase("true");
                    if (multivalued)
                        throw new JolicielException("Did not expect multivalued resource");
                    i++;
                    continue;
                }
                if (numParts < 0)
                    numParts = parts.length;
                if (parts.length != numParts)
                    throw new JolicielException(
                            "Wrong number of elements on line " + i + " in file: " + file.getName());

                for (int j = 0; j < numParts - 1; j++) {
                    sb.append(parts[j]);
                    sb.append("|");
                }
                String key = sb.toString();
                String value = parts[numParts - 1];
                resultMap.put(key, value);

            }
            i++;
        }
    } catch (IOException e) {
        LogUtils.logError(LOG, e);
        throw new RuntimeException(e);
    }
}

From source file:org.mifos.tools.service.ConsoleReaderService.java

@Override
public void run(String... args) throws Exception {
    final Scanner console = new Scanner(System.in);

    while (true) {
        System.out.print("ppiul> ");
        final String command = console.nextLine();
        if (command.equals("quit")) {
            System.out.println("Bye!");
            break;
        } else if (command.startsWith("show")) {
            if (command.contains("config")) {
                this.printProperties();
            } else if (command.contains("countries")) {
                this.printCountries();
            } else {
                this.unknownCommand();
            }//w  w  w.  j  a va  2  s. c o m
        } else if (command.startsWith("set")) {
            this.setProperty(command);
        } else if (command.startsWith("upload")) {
            final String[] message = command.split(" ");
            this.ppiUploaderService.upload(this.properties, message[1]);
        } else if (command.startsWith("help")) {
            this.printHelp();
        } else {
            this.unknownCommand();
        }
    }
}