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.wwpass.connection.WWPassConnection.java

/**
 * <p>Calls to this function check the authentication of the ticket.</p>
 *
 * @param ticket The ticket to validate.
 * @param auth_type Defines which credentials will be asked of the user to authorize this ticket. 
 * Currently only two values supported: 'p': to ask for PassKey and password; empty string to ask 
 * for PassKey only (default).//from  w  ww.j a  v a 2 s .  com
 * @param ttl The period in seconds for the ticket to remain valid since issuance. The default 
 * value is 120 seconds.
 * @return Returns current ticket or newly issued ticket. The new ticket should be used in future 
 * operations with the SPFE.
 * @throws IOException
 * @throws WWPassProtocolException
 */
public String putTicket(String ticket, String auth_type, int ttl) throws IOException, WWPassProtocolException {
    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put("ticket", ticket);
    parameters.put("auth_type", auth_type);
    parameters.put("ttl", Integer.toString(ttl));

    Scanner scanner = new Scanner(makeRequest("GET", "put", parameters));
    StringBuilder sb = new StringBuilder();

    while (scanner.hasNextLine()) {
        sb.append(scanner.nextLine());
    }
    scanner.close();
    return sb.toString();
}

From source file:com.wwpass.connection.WWPassConnection.java

/**
 * <p>Calls to this function request string data stored in the user's data container.</p>
 *
 * @param ticket The authenticated ticket issued by the SPFE.
 * @return Returns the data stored in the user's data container. Returns "None" character sequence if the data
 * container does not exist./*from w w w  .  ja  v  a2s .c o  m*/
 * @throws IOException
 * @throws WWPassProtocolException
 */
public String readDataAsString(String ticket) throws IOException, WWPassProtocolException {
    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put("ticket", ticket);

    Scanner scanner = new Scanner(makeRequest("GET", "read", parameters));
    StringBuilder sb = new StringBuilder();

    while (scanner.hasNextLine()) {
        sb.append(scanner.nextLine());
    }
    scanner.close();

    return sb.toString();
}

From source file:com.wwpass.connection.WWPassConnection.java

/**
 * <p>Gets an id of the user from the Service Provider Front End. This ID is unique for one 
 * Service Provider, and different for different Service Providers.</p>
 *
 * @param ticket Ticket issued by the SPFE
 * @param auth_type Defines which credentials should have been asked of the user to authenticate 
 * this ticket. Currently, only two values are supported: 'p' for a PassKey and access code, 
 * '' (empty string) for a PassKey only (default).
 * @return PUID issued by the SPFE//ww  w  .jav a 2 s.com
 * @throws IOException
 * @throws WWPassProtocolException
 */
public String getPUID(String ticket, String auth_type) throws IOException, WWPassProtocolException {
    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put("ticket", ticket);
    parameters.put("auth_type", auth_type);

    Scanner scanner = new Scanner(makeRequest("GET", "puid", parameters));
    StringBuilder sb = new StringBuilder();

    while (scanner.hasNextLine()) {
        sb.append(scanner.nextLine());
    }
    scanner.close();
    return sb.toString();

}

From source file:com.wwpass.connection.WWPassConnection.java

/**
 * <p>Calls to this function request String data stored in the user's data container.</p>
 *
 * @param ticket The authenticated ticket issued by the SPFE.
 * @param container Arbitrary string (only the first 32 bytes matter) that identifies the user's data container.
 * @return Returns the data stored in the user's data container. Returns "None" character sequence if the data
 * container does not exist.//from  ww  w. j a  va 2s.co  m
 * @throws IOException
 * @throws WWPassProtocolException
 */
public String readDataAsString(String ticket, String container) throws IOException, WWPassProtocolException {
    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put("ticket", ticket);
    parameters.put("container", container);

    Scanner scanner = new Scanner(makeRequest("GET", "read", parameters));
    StringBuilder sb = new StringBuilder();

    while (scanner.hasNextLine()) {
        sb.append(scanner.nextLine());
    }
    scanner.close();

    return sb.toString();
}

From source file:com.microfocus.application.automation.tools.results.RunResultRecorder.java

/**
 * Scan the LRA folder from slave to find the report containting Transaction Summary
 * as title (or title variants based on language packs)
 *///from w w  w. j  a  v  a  2  s . c om
private FilePath getTransactionSummaryReport(FilePath htmlReportPath) throws IOException, InterruptedException {
    String[] transactionSummaryNames = { "Transaction Summary", //eng
            " ", //jpn
            " ", //kor
            "?", //chs
            "Transaktionsbersicht", //deu
            "Resumen de transacciones", //spn
            "Riepilogo transazioni", //ita
            "Rcapitulatif des transactions", //fr
            " ", //rus
    };

    FileFilter reportFileFilter = new WildcardFileFilter("Report*.html");
    List<FilePath> reportFiles = htmlReportPath.list(reportFileFilter);
    for (FilePath fileToCopy : reportFiles) {
        Scanner scanner = new Scanner(fileToCopy.read()).useDelimiter("\\A");

        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            for (String transactionSummaryName : transactionSummaryNames) {
                if (line.contains(transactionSummaryName)) {
                    return fileToCopy;
                }
            }
        }
    }

    return null;
}

From source file:com.wwpass.connection.WWPassConnection.java

/**
 * <p>Calls to this function request string data stored in the user's data container and lock it.</p>
 *
 * @param ticket The authenticated ticket issued by the SPFE.
 * @param lockTimeout The period in seconds for the data container to remain protected from the new data being
 * accessed.// www  .ja  v a2 s  .  co  m
 * @return Returns the data stored in the user's data container, represented as String. Returns "None" character sequence if the data
 * container does not exist.
 * @throws IOException
 * @throws WWPassProtocolException
 */
public String readDataAsStringAndLock(String ticket, int lockTimeout)
        throws IOException, WWPassProtocolException {
    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put("ticket", ticket);
    parameters.put("to", Integer.toString(lockTimeout));
    parameters.put("lock", "1");

    Scanner scanner = new Scanner(makeRequest("GET", "read", parameters));
    StringBuilder sb = new StringBuilder();

    while (scanner.hasNextLine()) {
        sb.append(scanner.nextLine());
    }
    scanner.close();

    return sb.toString();
}

From source file:com.wwpass.connection.WWPassConnection.java

/**
 * <p>Calls to this function request string data stored in the Service 
 * Provider data container.</p>//from w ww.  ja  v a2 s.co m
 *
 * @param pfid The data container identifier as returned by createPFID.
 * @return Returns the data stored in the Service Provider data container, represented as String. Returns "None"
 * character sequence if the data container does not exist.
 * @throws IOException
 * @throws WWPassProtocolException
 */
public String readDataSPasString(byte[] pfid) throws IOException, WWPassProtocolException {
    HashMap<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("pfid", pfid);

    Scanner scanner = new Scanner(makeRequest("GET", "sp/read", parameters));
    StringBuilder sb = new StringBuilder();

    while (scanner.hasNextLine()) {
        sb.append(scanner.nextLine());
    }
    scanner.close();

    return sb.toString();
}

From source file:com.wwpass.connection.WWPassConnection.java

/**
 * <p>Calls to this function request string data stored in the user's data container and lock it.</p>
 *
 * @param ticket The authenticated ticket issued by the SPFE.
 * @param container Arbitrary string (only the first 32 bytes matter) that identifies the user's data container.
 * @param lockTimeout The period in seconds for the data container to remain protected from the new data being
 * accessed./*from w  w  w .j a va 2 s. c o  m*/
 * @return Returns the data stored in the user's data container, represented as String. Returns "None" character
 * sequence if the data container does not exist.
 * @throws IOException
 * @throws WWPassProtocolException
 */
public String readDataAsStringAndLock(String ticket, String container, int lockTimeout)
        throws IOException, WWPassProtocolException {
    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put("ticket", ticket);
    parameters.put("container", container);
    parameters.put("to", Integer.toString(lockTimeout));
    parameters.put("lock", "1");

    Scanner scanner = new Scanner(makeRequest("GET", "read", parameters));
    StringBuilder sb = new StringBuilder();

    while (scanner.hasNextLine()) {
        sb.append(scanner.nextLine());
    }
    scanner.close();

    return sb.toString();
}

From source file:com.wwpass.connection.WWPassConnection.java

/**
 * <p>Calls to this function request the string data stored in the Service 
 * Provider's Data Container and try to atomically lock an associated lock.</p>
 *
 * @param pfid The data container identifier as returned by createPFID.
 * @param lockTimeout The period in seconds for the data container to remain protected from 
 * the new data being accessed.//w w w. j  a  va2 s .c om
 * @return Returns the data stored in the Service Provider data container. Returns "False" character sequence if
 * the data container does not exist.
 * @throws IOException
 * @throws WWPassProtocolException
 */
public String readDataSPasStringAndLock(byte[] pfid, int lockTimeout)
        throws IOException, WWPassProtocolException {
    HashMap<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("pfid", pfid);
    parameters.put("to", Integer.toString(lockTimeout));
    parameters.put("lock", "1");

    Scanner scanner = new Scanner(makeRequest("GET", "sp/read", parameters));
    StringBuilder sb = new StringBuilder();

    while (scanner.hasNextLine()) {
        sb.append(scanner.nextLine());
    }
    scanner.close();

    return sb.toString();
}

From source file:HackathonSupporter.java

@Override
/**//from ww w .j a v a  2  s  . c  o m
 * Returns the banner after searching in the file.
 * @param advId The forced advertisement id you get from GET request
 * @param width the requested width
 * @param height the request height
 * @param segmentId the segment ID you get by reading the cookie
 * @context object of ServletContext which is needed to read the config.properties file
 */
public String readFromFile(String advId, int width, int height, int segmentId, ServletContext context,
        int callingFlag) {
    File file = null;
    Scanner fis = null;
    String banner = null;
    try {
        //read the filename and mappingFilename form the config.properties file
        Properties prop = new Properties();
        if (callingFlag == 0) {
            prop.load(new InputStreamReader(context.getResourceAsStream("/WEB-INF/config.properties")));
        } else if (callingFlag == 1) {
            prop.load(new FileReader(
                    "/home/sankalpkulshrestha/NetBeansProjects/AdServer/web/WEB-INF/config.properties"));
        } else {
            return DEFAULT_BANNER;
        }
        //filename contains the list of advId, width, height, banner,segmentID. The filename is input.txt
        String filename = prop.getProperty("filename");
        //mappingFilename contains the mapping of the advId and the default banner address
        String mappingFilename = prop.getProperty("mappingFilename");

        file = new File(filename);
        fis = new Scanner(file);
        String line = null;
        //read the each line of input.txt, split it by comma and store it in param String array
        String[] param = new String[5];
        //w and h hold the width and height respectively.
        //flag keeps track of whether a corresponding advId is found for a segnment ID, in case the advId is null
        int w = -1, h = -1, flag = 0;
        while (fis.hasNextLine()) {
            //read each line and split by comma
            line = fis.nextLine();
            param = line.split(",");
            //read the width and height from the input.txt
            w = Integer.parseInt(param[1]);
            h = Integer.parseInt(param[2]);
            //in case we are not getting and forced advertisement ID, we keep searching for the corresponding advId is found for a segnment ID
            if ((advId == null || advId.length() == 0) && flag == 0
                    && segmentId == Integer.parseInt(param[4])) {
                flag = 1;
                advId = param[0];
            }
            //in case segment ID is not 0 and segmentId is same as the segment ID found from the file of same width
            //and height as the requested width and height, we set the corresponding banner from the file and break away
            if (segmentId != 0 && segmentId == Integer.parseInt(param[4]) && w == width && h == height) {
                banner = param[3];
                break;
            }
        }
        //close the input.txt file
        if (fis != null) {
            fis.close();
        }

        //if till now the banner is still null and the advId is not null
        //then we check the mapping.txt file for finding the default banner of the campaign 
        //the advId points to
        if (banner == null && advId != null) {
            File file2 = new File(mappingFilename);
            Scanner fis2 = null;
            fis2 = new Scanner(file2);
            param = new String[2];
            while (fis2.hasNextLine()) {
                line = fis2.nextLine();
                param = line.split(",");
                if (param[0].equals(advId)) {
                    banner = param[1];
                    break;
                }
            }
            //close the mapping.txt file
            if (fis2 != null) {
                fis2.close();
            }
        } else if (banner == null && advId == null) {
            //in case the banner is null and the advId is null, we return the default banner
            return DEFAULT_BANNER;
        }
    } catch (IOException e) {
        //in case of any exception, we return the default banner
        return DEFAULT_BANNER;
    } finally {
        //close the file
        if (fis != null) {
            fis.close();
        }
    }
    return banner;
}