Example usage for java.util Scanner ioException

List of usage examples for java.util Scanner ioException

Introduction

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

Prototype

public IOException ioException() 

Source Link

Document

Returns the IOException last thrown by this Scanner 's underlying Readable .

Usage

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 1 + 1 = 2.0 ";

    Scanner scanner = new Scanner(s);

    // print the line
    System.out.println(scanner.nextLine());

    // check if there is an IO exception
    System.out.println(scanner.ioException());

    scanner.close();//from  w  w  w .  java 2  s  .com
}

From source file:org.apache.accumulo.core.client.mapreduce.lib.util.ConfiguratorBase.java

/**
 * Reads from the token file in distributed cache. Currently, the token file stores data separated by colons e.g. principal:token_class:token
 * //from   ww w.j a  v  a  2s  . c  om
 * @param conf
 *          the Hadoop context for the configured job
 * @return path to the token file as a String
 * @since 1.6.0
 * @see #setConnectorInfo(Class, Configuration, String, AuthenticationToken)
 */
public static AuthenticationToken getTokenFromFile(Configuration conf, String principal, String tokenFile) {
    FSDataInputStream in = null;
    try {
        URI[] uris = DistributedCacheHelper.getCacheFiles(conf);
        Path path = null;
        for (URI u : uris) {
            if (u.toString().equals(tokenFile)) {
                path = new Path(u);
            }
        }
        if (path == null) {
            throw new IllegalArgumentException(
                    "Couldn't find password file called \"" + tokenFile + "\" in cache.");
        }
        FileSystem fs = FileSystem.get(conf);
        in = fs.open(path);
    } catch (IOException e) {
        throw new IllegalArgumentException("Couldn't open password file called \"" + tokenFile + "\".");
    }
    java.util.Scanner fileScanner = new java.util.Scanner(in);
    try {
        while (fileScanner.hasNextLine()) {
            Credentials creds = Credentials.deserialize(fileScanner.nextLine());
            if (principal.equals(creds.getPrincipal())) {
                return creds.getToken();
            }
        }
        throw new IllegalArgumentException(
                "Couldn't find token for user \"" + principal + "\" in file \"" + tokenFile + "\"");
    } finally {
        if (fileScanner != null && fileScanner.ioException() == null)
            fileScanner.close();
        else if (fileScanner.ioException() != null)
            throw new RuntimeException(fileScanner.ioException());
    }
}

From source file:org.kalypso.grid.AsciiGridReader.java

private void readAsciiGridHeader(final Scanner scanner) throws IOException {
    m_headerKeys = new String[6];
    m_headerData = new String[6];

    String line;//from w w  w .  j  a v  a2s  .  c om

    // reading header data
    for (int i = 0; i < 6; i++) {
        line = scanner.nextLine();

        if (line.startsWith("/*")) {
            i--;
            continue;
        }

        final String[] values = line.split("\\s+");

        m_headerKeys[i] = values[0].trim();
        m_headerData[i] = values[1].trim();
    }

    if (scanner.ioException() != null)
        throw scanner.ioException();
}