Example usage for java.util Scanner reset

List of usage examples for java.util Scanner reset

Introduction

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

Prototype

public Scanner reset() 

Source Link

Document

Resets this scanner.

Usage

From source file:Main.java

public static void main(String[] args) {

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

    Scanner scanner = new Scanner(s);

    System.out.println(scanner.nextLine());

    // change the locale of this scanner
    scanner.useLocale(Locale.US);

    // change the radix of this scanner
    scanner.useRadix(30);//  w  ww.  j a  v  a 2s.  c  o  m

    // reset and check the values for radix and locale, which are the default
    scanner.reset();
    System.out.println(scanner.radix());
    System.out.println(scanner.locale());

    scanner.close();
}

From source file:com.vmware.fdmsecprotomgmt.PasswdEncrypter.java

/**
 * Decrypt the original password by using the secretKey and encrypted string
 *//*  ww  w . j a v  a  2 s . c  om*/
public static List<String> decryptValueWithUserEnteredKey(String encryptedStr) {
    boolean validVals = false;
    String secretKey = "";
    List<String> decryptedStrList = null;

    try {
        Scanner in = new Scanner(System.in);
        System.out.print(
                "For decrypting ESXi password, Please Enter SecretKey (16 characters) that was used earlier: ");

        secretKey = in.nextLine().trim();
        if (secretKey.length() == STD_KEYSIZE) {
            validVals = true;
        } else {
            System.out.println("Invalid secretKey, please try again");
        }

        // reset the scanner
        in.reset();

        // Go for encrypting the password with provided SecretKey
        if (validVals) {
            if ((!encryptedStr.equals(""))) {
                // Validate that on decrypt, you would receive the same
                // password
                String tempDecryptedStr = decrypt(secretKey, encryptedStr);
                if (!tempDecryptedStr.equals("")) {
                    System.out.println(
                            "Successfully decrypted ESXi password with provided secretKey: " + secretKey);
                    decryptedStrList = new ArrayList<String>();
                    decryptedStrList.add(secretKey);
                    decryptedStrList.add(tempDecryptedStr);
                } else {
                    System.err.println("Failed to decrypt the encrypted string: " + encryptedStr
                            + ", with provided secretkey: " + secretKey);
                    System.err.println(
                            "Please review the secretkey provided. It has to be the same as the one provided during"
                                    + " encrypted the original password");

                }
            } else {
                System.err.println("Encrypted Value provided is empty/null");
            }
        }
    } catch (Exception e) {
        System.err.println("Caught exception while decrypting ESXi password");
        decryptedStrList = null;
    }

    return decryptedStrList;
}

From source file:com.joey.software.MoorFLSI.RepeatImageTextReader.java

public void loadTextDataFluxSingle(File file) {
    try {//from   w w  w . j a v a 2s.  c o  m
        RandomAccessFile in = new RandomAccessFile(file, "r");

        // Skip header
        in.readLine();
        in.readLine();
        in.readLine();

        // Skip Subject Information
        in.readLine();
        in.readLine();
        in.readLine();
        in.readLine();
        in.readLine();
        in.readLine();
        String startTimeInput = in.readLine();
        String commentsInput = in.readLine();

        String data = in.readLine();
        while (!data.startsWith("2) System Configuration")) {
            commentsInput += data;
            data = in.readLine();
        }
        // System configuration

        // in.readLine();
        in.readLine();
        String timeCounstantInput = in.readLine();
        String cameraGainInput = in.readLine();
        String exposureTimeInput = in.readLine();
        in.readLine();
        in.readLine();
        in.readLine();
        String resolutionInput = in.readLine();

        // in.readLine();
        // System.out.println(in.readLine());
        // in.readLine();

        // Parse important Size

        high = (new Scanner(resolutionInput.split(":")[1])).nextInt();
        wide = (new Scanner(resolutionInput.split(",")[1])).nextInt();
        int tot = 1;
        while (!data.startsWith("3) Flux Image Data")) {
            System.out.println(data);
            data = in.readLine();
        }
        in.readLine();
        // Parse Image Data
        /*
         * Close Random access file and switch to scanner first store pos
         * then move to correct point.
         */
        long pos = in.getFilePointer();
        in.close();

        FileInputStream fIn = new FileInputStream(file);
        fIn.skip(pos);

        BufferedInputStream bIn = new BufferedInputStream(fIn);
        Scanner sIn = new Scanner(bIn);

        short[][] holder = new short[wide][high];

        JFrame f = new JFrame();
        f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

        StatusBarPanel stat = new StatusBarPanel();
        stat.setMaximum(high);
        f.getContentPane().setLayout(new BorderLayout());
        f.getContentPane().add(stat, BorderLayout.CENTER);
        f.setSize(200, 60);
        f.setVisible(true);

        // Skip over the heading values

        sIn.reset();

        for (int y = 0; y < high; y++) {
            System.out.println(sIn.nextInt());
            try {
                for (int x = 0; x < wide; x++) {
                    holder[x][y] = sIn.nextShort();
                }
            } catch (Throwable e) {

            }

        }
        addData(new Date(), holder);

        FrameFactroy.getFrame(new DynamicRangeImage(holder));
        // Start Image Data

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.joey.software.MoorFLSI.RepeatImageTextReader.java

public void loadTextData(File file) {
    try {/*  ww  w  .  j a v  a  2s .co m*/
        RandomAccessFile in = new RandomAccessFile(file, "r");

        // Skip header
        in.readLine();
        in.readLine();
        in.readLine();

        // Skip Subject Information
        in.readLine();
        in.readLine();
        in.readLine();
        in.readLine();
        in.readLine();
        in.readLine();
        String startTimeInput = in.readLine();
        String commentsInput = in.readLine();

        String data = in.readLine();
        while (!data.startsWith("2) System Configuration")) {
            commentsInput += data;
            data = in.readLine();
        }
        // System configuration

        // in.readLine();
        in.readLine();
        String timeCounstantInput = in.readLine();
        String cameraGainInput = in.readLine();
        String exposureTimeInput = in.readLine();
        in.readLine();
        in.readLine();
        in.readLine();
        String resolutionInput = in.readLine();

        // Time Data
        in.readLine();
        String timeDataInput = in.readLine();
        String totalImagesInput = in.readLine();
        in.readLine();
        in.readLine();
        // in.readLine();
        // System.out.println(in.readLine());
        // in.readLine();

        // Parse important Size

        high = (new Scanner(resolutionInput.split(":")[1])).nextInt();
        wide = (new Scanner(resolutionInput.split(",")[1])).nextInt();
        int tot = 1;
        try {
            tot = (new Scanner(totalImagesInput.split(":")[1])).nextInt();
        } catch (Exception e) {

        }
        System.out.println(wide + "," + high);
        // Parse timeInformation
        SimpleDateFormat format = new SimpleDateFormat("hh:mm:ss (dd/MM/yy)");
        Date startTime = null;
        try {
            startTime = format.parse(startTimeInput.split(": ")[1]);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        String[] frameTimeData = timeDataInput.split("information:")[1].split(",");

        Date[] timeInfo = new Date[tot];
        for (int i = 0; i < frameTimeData.length - 1; i++) {
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTime(startTime);
            String dat = (frameTimeData[i]);
            String[] timeVals = dat.split(":");

            int hour = Integer.parseInt(StringOperations.removeNonNumber(timeVals[0]));
            int min = Integer.parseInt(StringOperations.removeNonNumber(timeVals[1]));
            int sec = Integer.parseInt(StringOperations.removeNonNumber(timeVals[2]));
            int msec = Integer.parseInt(StringOperations.removeNonNumber(timeVals[3]));

            cal.add(Calendar.HOUR_OF_DAY, hour);
            cal.add(Calendar.MINUTE, min);
            cal.add(Calendar.SECOND, sec);
            cal.add(Calendar.MILLISECOND, msec);
            timeInfo[i] = cal.getTime();
        }

        // Parse Image Data
        /*
         * Close Random access file and switch to scanner first store pos
         * then move to correct point.
         */
        long pos = in.getFilePointer();
        in.close();

        FileInputStream fIn = new FileInputStream(file);
        fIn.skip(pos);

        BufferedInputStream bIn = new BufferedInputStream(fIn);
        Scanner sIn = new Scanner(bIn);

        short[][][] holder = new short[tot][wide][high];

        JFrame f = new JFrame();
        f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

        StatusBarPanel stat = new StatusBarPanel();
        stat.setMaximum(high);
        f.getContentPane().setLayout(new BorderLayout());
        f.getContentPane().add(stat, BorderLayout.CENTER);
        f.setSize(200, 60);
        f.setVisible(true);

        for (int i = 0; i < tot; i++) {
            // Skip over the heading values
            stat.setStatusMessage("Loading " + i + " of " + tot);
            sIn.useDelimiter("\n");
            sIn.next();
            sIn.next();
            sIn.next();
            if (i != 0) {
                sIn.next();
            }
            sIn.reset();
            for (int y = 0; y < high; y++) {
                stat.setValue(y);
                sIn.nextInt();
                for (int x = 0; x < wide; x++) {
                    holder[i][x][y] = sIn.nextShort();
                }

            }
            addData(timeInfo[i], holder[i]);
        }

        // FrameFactroy.getFrame(new DynamicRangeImage(data[0]));
        // Start Image Data

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}