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:br.com.intelidev.dao.DadosDao.java

public List<Dados> get_stream_data(String stream_api, String user, String pass) {

    HttpsURLConnection conn = null;
    List<Dados> list_return = new ArrayList<>();
    int i;/* w ww  . ja  va2 s  . c o  m*/

    try {
        // Create url to the Device Cloud server for a given web service request
        //00000000-00000000-00409DFF-FF6064F8/xbee.analog/[00:13:A2:00:40:E6:5A:88]!/AD1
        ObjectMapper mapper = new ObjectMapper();
        URL url = new URL("https://devicecloud.digi.com/ws/v1/streams/history/" + stream_api);
        //URL url = new URL("https://devicecloud.digi.com/ws/v1/streams/history/00000000-00000000-00409DFF-FF6064F8/xbee.analog/[00:13:A2:00:40:E6:5A:88]!/AD1");
        conn = (HttpsURLConnection) url.openConnection();
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setRequestMethod("GET");

        // Build authentication string
        String userpassword = user + ":" + pass;
        System.out.println(userpassword);

        // can change this to use a different base64 encoder
        String encodedAuthorization = Base64.encodeBase64String(userpassword.getBytes()).trim();

        // set request headers
        conn.setRequestProperty("Authorization", "Basic " + encodedAuthorization);
        // Get input stream from response and convert to String
        InputStream is = conn.getInputStream();

        Scanner isScanner = new Scanner(is);
        StringBuffer buf = new StringBuffer();
        while (isScanner.hasNextLine()) {
            buf.append(isScanner.nextLine() + "\n");
        }
        String responseContent = buf.toString();

        // add line returns between tags to make it a bit more readable
        responseContent = responseContent.replaceAll("><", ">\n<");

        // Output response to standard out
        System.out.println(responseContent);
        // Convert JSON string to Object
        StreamDados stream = mapper.readValue(responseContent, StreamDados.class);
        //System.out.println(stream.getList());
        System.out.println(stream.getList().size());
        for (i = 0; i < stream.getList().size(); i++) {
            list_return.add(stream.getList().get(i));
            //System.out.println("ts: "+ stream.getList().get(i).getTimestamp() + "Value: " + stream.getList().get(i).getValue());

        }

    } catch (Exception e) {
        // Print any exceptions that occur
        System.out.println("br.com.intelidev.dao.DadosDao.get_stream_data() e" + e);
    } finally {
        if (conn != null)
            conn.disconnect();
    }

    return list_return;
}

From source file:com.joliciel.talismane.posTagger.PosTagSetImpl.java

void load(Scanner scanner) {
    List<String> descriptors = new ArrayList<String>();
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        descriptors.add(line);/*from   w w w .  j  av a 2s. c o m*/
    }
    this.load(descriptors);
}

From source file:com.chromium.fontinstaller.ui.fontlist.FontListFragment.java

private void populateFontList() {
    InputStream fontFile = null;/* www  . j a v  a  2  s .co  m*/
    try {
        fontFile = activity.getAssets().open("fonts");
        Scanner scanner = new Scanner(fontFile);
        while (scanner.hasNextLine()) {
            fontList.add(scanner.nextLine());
        }
    } catch (IOException ignored) {
    } finally {
        if (fontFile != null) {
            try {
                fontFile.close();
            } catch (IOException ignored) {
            }
        }
    }
}

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

protected List<String> getPorts(String executable) {
    List<String> ports = new ArrayList<>();
    try {/*from   w ww.  j  a v  a2 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 {//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:com.joliciel.frenchTreebank.export.FtbPosTagMapperImpl.java

public FtbPosTagMapperImpl(File file, PosTagSet posTagSet) {
    this.posTagSet = posTagSet;
    Scanner scanner = null;
    try {/*  w  w w .  j  a  v a2s.  c  o  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:com.joliciel.lefff.LefffPosTagMapperImpl.java

public LefffPosTagMapperImpl(File file, PosTagSet posTagSet) {
    this.posTagSet = posTagSet;
    Scanner scanner = null;
    try {// ww w  .  jav a 2s .c  om
        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 {//ww  w .  ja v a  2s  . c om
        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:com.joliciel.talismane.en.TalismaneEnglish.java

@Override
public TransitionSystem getDefaultTransitionSystem() {
    TransitionSystem transitionSystem = this.getParserService().getArcEagerTransitionSystem();
    InputStream inputStream = getInputStreamFromResource("pennDependencyLabels.txt");
    Scanner scanner = new Scanner(inputStream, "UTF-8");
    List<String> dependencyLabels = new ArrayList<String>();
    while (scanner.hasNextLine()) {
        String dependencyLabel = scanner.nextLine();
        if (!dependencyLabel.startsWith("#")) {
            if (dependencyLabel.indexOf('\t') > 0)
                dependencyLabel = dependencyLabel.substring(0, dependencyLabel.indexOf('\t'));
            dependencyLabels.add(dependencyLabel);
        }/*  w w  w  . j av  a 2 s  . c o  m*/
    }
    transitionSystem.setDependencyLabels(dependencyLabels);
    return transitionSystem;
}

From source file:org.apache.bigtop.datagenerators.weatherman.internal.WeatherParametersReader.java

public List<WeatherStationParameters> readParameters() throws Exception {
    InputStream inputStream = getResource(WeatherConstants.WEATHER_PARAMETERS_FILE);
    Scanner scanner = new Scanner(inputStream);

    // skip header
    scanner.nextLine();//from  w  ww . j a  va  2s.  c om

    List<WeatherStationParameters> parameterList = Lists.newArrayList();
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        WeatherStationParameters parameters = parseLine(line);
        parameterList.add(parameters);
    }

    scanner.close();

    return parameterList;
}