Example usage for java.lang Long toHexString

List of usage examples for java.lang Long toHexString

Introduction

In this page you can find the example usage for java.lang Long toHexString.

Prototype

public static String toHexString(long i) 

Source Link

Document

Returns a string representation of the long argument as an unsigned integer in base 16.

Usage

From source file:Main.java

public static void main(String[] args) {
    System.out.println(Long.toHexString(15));
}

From source file:IntToLongCompressor.java

public static void main(String[] args) {
    int x = -23664;
    int y = -6543;

    System.out.println("x=    " + Integer.toHexString(x));
    System.out.println("y=    " + Integer.toHexString(y));

    long pack = pack(x, y);
    System.out.println("pack= " + Long.toHexString(pack));

    int x2 = unpackX(pack);
    System.out.println("x2=   " + Integer.toHexString(x2));

    int y2 = unpackY(pack);
    System.out.println("y2=   " + Integer.toHexString(y2));

    testAll();//www  .  ja v  a  2 s .  co m
}

From source file:Y2038.java

public static void main(String[] a) {

    // This should yield 2038AD, the hour of doom for the
    // last remaining 32-bit UNIX systems (there will be
    // millions of 64-bit UNIXes by then).

    long expiry = 0x7FFFFFFFL;

    System.out.println(/*  w  w w .ja  v  a  2s  .co  m*/
            "32-bit UNIX expires on " + Long.toHexString(expiry) + " or " + new java.util.Date(expiry * 1000));
}

From source file:org.apache.hadoop.hbase.regionserver.transactional.IdTm.java

/**
 * main//w w w  .  j  av a 2  s . c o m
 *
 * @param args arguments
 */
public static void main(String[] args) {
    boolean cb = false;
    int loop = 1;

    for (int arg = 0; arg < args.length; arg++) {
        String sarg = args[arg];
        if (sarg.equals("-cb")) {
            cb = true;
        } else if (sarg.equals("-loop")) {
            if ((arg + 1) < args.length) {
                arg++;
                sarg = args[arg];
                loop = Integer.parseInt(sarg);
            } else {
                System.out.println("expecting <loop-count>");
                Runtime.getRuntime().exit(1);
            }
        }
    }

    IdTm cli = new IdTm(cb);
    if (LOG.isDebugEnabled())
        LOG.debug("IdTm begin, loop=" + loop);

    for (int inx = 0; inx < loop; inx++) {
        try {
            cli.ping(TO);
        } catch (IdTmException exc) {
            LOG.error("ping threw exc=" + exc);
        }
        try {
            IdTmId id = new IdTmId();
            cli.id(TO, id);
            if (LOG.isDebugEnabled())
                LOG.debug("id ret=0x" + Long.toHexString(id.val));
        } catch (IdTmException exc) {
            LOG.error("id threw exc=" + exc);
        }
    }
    if (LOG.isDebugEnabled())
        LOG.debug("IdTm done");
}

From source file:Pong.java

public static void main(String... args) throws Exception {
    System.setProperty("os.max.pid.bits", "16");

    Options options = new Options();
    options.addOption("i", true, "Input chronicle path");
    options.addOption("n", true, "Number of entries to write");
    options.addOption("w", true, "Number of writer threads");
    options.addOption("r", true, "Number of reader threads");
    options.addOption("x", false, "Delete the output chronicle at startup");

    CommandLine cmd = new DefaultParser().parse(options, args);
    final Path output = Paths.get(cmd.getOptionValue("o", "/tmp/__test/chr"));
    final long maxCount = Long.parseLong(cmd.getOptionValue("n", "10000000"));
    final int writerThreadCount = Integer.parseInt(cmd.getOptionValue("w", "4"));
    final int readerThreadCount = Integer.parseInt(cmd.getOptionValue("r", "4"));
    final boolean deleteOnStartup = cmd.hasOption("x");

    if (deleteOnStartup) {
        FileUtil.removeRecursive(output);
    }/*from ww w .java 2s  .  c om*/

    final Chronicle chr = ChronicleQueueBuilder.vanilla(output.toFile()).build();

    final ExecutorService executor = Executors.newFixedThreadPool(4);
    final List<Future<?>> futures = new ArrayList<>();

    final long totalCount = writerThreadCount * maxCount;
    final long t0 = System.nanoTime();

    for (int i = 0; i != readerThreadCount; ++i) {
        final int tid = i;
        futures.add(executor.submit((Runnable) () -> {
            try {
                IntLongMap counts = HashIntLongMaps.newMutableMap();
                ExcerptTailer tailer = chr.createTailer();

                final StringBuilder sb1 = new StringBuilder();
                final StringBuilder sb2 = new StringBuilder();

                long count = 0;
                while (count != totalCount) {
                    if (!tailer.nextIndex())
                        continue;
                    final int id = tailer.readInt();
                    final long val = tailer.readStopBit();
                    final long longValue = tailer.readLong();
                    sb1.setLength(0);
                    sb2.setLength(0);
                    tailer.read8bitText(sb1);
                    tailer.read8bitText(sb2);
                    if (counts.addValue(id, 1) - 1 != val || longValue != 0x0badcafedeadbeefL
                            || !StringInterner.isEqual("FooBar", sb1)
                            || !StringInterner.isEqual("AnotherFooBar", sb2)) {
                        System.out.println("Unexpected value " + id + ", " + val + ", "
                                + Long.toHexString(longValue) + ", " + sb1.toString() + ", " + sb2.toString());
                        return;
                    }
                    ++count;
                    if (count % 1_000_000 == 0) {
                        long t1 = System.nanoTime();
                        System.out.println(tid + " " + (t1 - t0) / 1e6 + " ms");
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }));
    }
    for (Future f : futures) {
        f.get();
    }
    executor.shutdownNow();

    final long t1 = System.nanoTime();
    System.out.println("Done. Rough time=" + (t1 - t0) / 1e6 + " ms");
}

From source file:com.revo.deployr.client.example.data.io.auth.discrete.exec.RepoFileInRepoFileOut.java

public static void main(String args[]) throws Exception {

    RClient rClient = null;/*from  w w w.j a v a 2s  . c o m*/

    try {

        /*
         * Determine DeployR server endpoint.
         */
        String endpoint = System.getProperty("endpoint");
        log.info("[ CONFIGURATION  ] Using endpoint=" + endpoint);

        /*
         * Establish RClient connection to DeployR server.
         *
         * An RClient connection is the mandatory starting
         * point for any application using the client library.
         */
        rClient = RClientFactory.createClient(endpoint);

        log.info("[   CONNECTION   ] Established anonymous " + "connection [ RClient ].");

        /*
         * Build a basic authentication token.
         */
        RAuthentication rAuth = new RBasicAuthentication(System.getProperty("username"),
                System.getProperty("password"));

        /*
         * Establish an authenticated handle with the DeployR
         * server, rUser. Following this call the rClient 
         * connection is operating as an authenticated connection
         * and all calls on rClient inherit the access permissions
         * of the authenticated user, rUser.
         */
        RUser rUser = rClient.login(rAuth);
        log.info("[ AUTHENTICATION ] Upgraded to authenticated " + "connection [ RUser ].");

        /*
         * Create the AnonymousProjectExecutionOptions object
         * to specify data inputs and output to the script.
         *
         * This options object can be used to pass standard
         * execution model parameters on execution calls. All
         * fields are optional.
         *
         * See the Standard Execution Model chapter in the
         * Client Library Tutorial on the DeployR website for
         * further details.
         */
        AnonymousProjectExecutionOptions options = new AnonymousProjectExecutionOptions();

        /* 
         * Preload from the DeployR repository the following
         * data input file:
         * /testuser/example-data-io/hipStar.dat
         */
        ProjectPreloadOptions preloadDirectory = new ProjectPreloadOptions();
        preloadDirectory.filename = "hipStar.dat";
        preloadDirectory.directory = "example-data-io";
        preloadDirectory.author = "testuser";
        options.preloadDirectory = preloadDirectory;

        log.info("[   DATA INPUT   ] Repository data file input "
                + "set on execution, [ ProjectExecutionOptions.preloadDirectory ].");

        /* 
         * Request storage of entire workspace as a
         * binary rData file to the DeployR-repository
         * following the execution.
         *
         * Alternatively, you could use storageOptions.objects
         * to store individual objects from the workspace.
         */
        ProjectStorageOptions storageOptions = new ProjectStorageOptions();
        // Use random file name for this example.
        storageOptions.workspace = Long.toHexString(Double.doubleToLongBits(Math.random()));
        storageOptions.directory = "example-data-io";
        options.storageOptions = storageOptions;

        log.info("[  EXEC OPTION   ] Repository storage request "
                + "set on execution [ ProjectExecutionOptions.storageOptions ].");

        /*
         * Execute an analytics Web service as an authenticated
         * user based on a repository-managed R script:
         * /testuser/example-data-io/dataIO.R
         */
        RScriptExecution exec = rClient.executeScript("dataIO.R", "example-data-io", "testuser", null, options);

        log.info("[   EXECUTION    ] Discrete R script " + "execution completed [ RScriptExecution ].");

        /*
         * Retrieve repository-managed file(s) that were 
         * generated by the execution per ProjectStorageOptions.
         *
         * Outputs generated by an execution can be used in any
         * number of ways by client applications, including:
         *
         * 1. Use output data to perform further calculations.
         * 2. Display output data to an end-user.
         * 3. Write output data to a database.
         * 4. Pass output data along to another Web service.
         * 5. etc.
         */
        List<RRepositoryFile> repoFiles = exec.about().repositoryFiles;

        for (RRepositoryFile repoFile : repoFiles) {
            log.info("[  DATA OUTPUT   ] Retrieved repository " + "file output " + repoFile.about().filename
                    + " [ RRepositoryFile ].");
            InputStream fis = null;
            try {
                fis = repoFile.download();
            } catch (Exception ex) {
                log.warn("Repository-managed file download " + ex);
            } finally {
                IOUtils.closeQuietly(fis);
                try { // Clean-up after example.
                    repoFile.delete();
                } catch (Exception dex) {
                    log.warn("Repository-managed file delete " + dex);
                }
            }
        }

    } catch (Exception ex) {
        log.warn("Unexpected runtime exception=" + ex);
    } finally {
        try {
            if (rClient != null) {
                /*
                 * Release rClient connection before application exits.
                 */
                rClient.release();
            }
        } catch (Exception fex) {
        }
    }

}

From source file:com.revo.deployr.client.example.data.io.auth.stateful.exec.RepoFileInRepoFileOut.java

public static void main(String args[]) throws Exception {

    RClient rClient = null;/*from   w w  w  .j  a  v  a 2  s. c o  m*/
    RProject rProject = null;

    try {

        /*
         * Determine DeployR server endpoint.
         */
        String endpoint = System.getProperty("endpoint");
        log.info("[ CONFIGURATION  ] Using endpoint=" + endpoint);

        /*
         * Establish RClient connection to DeployR server.
         *
         * An RClient connection is the mandatory starting
         * point for any application using the client library.
         */
        rClient = RClientFactory.createClient(endpoint);

        log.info("[   CONNECTION   ] Established anonymous " + "connection [ RClient ].");

        /*
         * Build a basic authentication token.
         */
        RAuthentication rAuth = new RBasicAuthentication(System.getProperty("username"),
                System.getProperty("password"));

        /*
         * Establish an authenticated handle with the DeployR
         * server, rUser. Following this call the rClient 
         * connection is operating as an authenticated connection
         * and all calls on rClient inherit the access permissions
         * of the authenticated user, rUser.
         */
        RUser rUser = rClient.login(rAuth);
        log.info("[ AUTHENTICATION ] Upgraded to authenticated " + "connection [ RUser ].");

        /*
         * Create a temporary project (R session).
         *
         * Optionally:
         * ProjectCreationOptions options =
         * new ProjectCreationOptions();
         *
         * Populate options as needed, then:
         *
         * rProject = rUser.createProject(options);
         */
        rProject = rUser.createProject();

        log.info("[  GO STATEFUL   ] Created stateful temporary " + "R session [ RProject ].");

        /*
         * Create a ProjectExecutionOptions instance
         * to specify data inputs and output to the
         * execution of the repository-managed R script.
         *
         * This options object can be used to pass standard
         * execution model parameters on execution calls. All
         * fields are optional.
         *
         * See the Standard Execution Model chapter in the
         * Client Library Tutorial on the DeployR website for
         * further details.
         */
        ProjectExecutionOptions options = new ProjectExecutionOptions();

        /* 
         * Preload from the DeployR repository the following
         * binary R object input file:
         * /testuser/example-data-io/hipStar.rData
         */
        ProjectPreloadOptions preloadWorkspace = new ProjectPreloadOptions();
        preloadWorkspace.filename = "hipStar.rData";
        preloadWorkspace.directory = "example-data-io";
        preloadWorkspace.author = "testuser";
        options.preloadWorkspace = preloadWorkspace;

        log.info("[   DATA INPUT   ] Repository binary file input "
                + "set on execution, [ ProjectExecutionOptions.preloadWorkspace ].");

        /* 
         * Request storage of entire workspace as a
         * binary rData file to the DeployR-repository
         * following the execution.
         *
         * Alternatively, you could use storageOptions.objects
         * to store individual objects from the workspace.
         */
        ProjectStorageOptions storageOptions = new ProjectStorageOptions();
        // Use random file name for this example.
        storageOptions.workspace = Long.toHexString(Double.doubleToLongBits(Math.random()));
        storageOptions.directory = "example-data-io";
        options.storageOptions = storageOptions;

        log.info("[  EXEC OPTION   ] Repository storage request "
                + "set on execution [ ProjectExecutionOptions.storageOptions ].");

        /*
         * Execute a public analytics Web service as an authenticated
         * user based on a repository-managed R script:
         * /testuser/example-data-io/dataIO.R
         */
        RProjectExecution exec = rProject.executeScript("dataIO.R", "example-data-io", "testuser", null,
                options);

        log.info("[   EXECUTION    ] Stateful R script " + "execution completed [ RProjectExecution ].");

        /*
         * Retrieve repository-managed file(s) that were 
         * generated by the execution per ProjectStorageOptions.
         *
         * Outputs generated by an execution can be used in any
         * number of ways by client applications, including:
         *
         * 1. Use output data to perform further calculations.
         * 2. Display output data to an end-user.
         * 3. Write output data to a database.
         * 4. Pass output data along to another Web service.
         * 5. etc.
         */
        List<RRepositoryFile> repoFiles = exec.about().repositoryFiles;

        for (RRepositoryFile repoFile : repoFiles) {
            log.info("[  DATA OUTPUT   ] Retrieved repository " + "file output " + repoFile.about().filename
                    + " [ RRepositoryFile ].");
            InputStream fis = null;
            try {
                fis = repoFile.download();
            } catch (Exception ex) {
                log.warn("Repository-managed file download " + ex);
            } finally {
                IOUtils.closeQuietly(fis);
                try { // Clean-up after example.
                    repoFile.delete();
                } catch (Exception dex) {
                    log.warn("Repository-managed file delete " + dex);
                }
            }
        }

    } catch (Exception ex) {
        log.warn("Unexpected runtime exception=" + ex);
    } finally {
        try {
            if (rProject != null) {
                /*
                 * Close rProject before application exits.
                 */
                rProject.close();
            }
        } catch (Exception fex) {
        }
        try {
            if (rClient != null) {
                /*
                 * Release rClient connection before application exits.
                 */
                rClient.release();
            }
        } catch (Exception fex) {
        }
    }

}

From source file:com.revo.deployr.client.example.data.io.auth.stateful.preload.RepoFileInRepoFileOut.java

public static void main(String args[]) throws Exception {

    RClient rClient = null;/*  w ww. j av a 2s  .  c  o  m*/
    RProject rProject = null;

    try {

        /*
         * Determine DeployR server endpoint.
         */
        String endpoint = System.getProperty("endpoint");
        log.info("[ CONFIGURATION  ] Using endpoint=" + endpoint);

        /*
         * Establish RClient connection to DeployR server.
         *
         * An RClient connection is the mandatory starting
         * point for any application using the client library.
         */
        rClient = RClientFactory.createClient(endpoint);

        log.info("[   CONNECTION   ] Established anonymous " + "connection [ RClient ].");

        /*
         * Build a basic authentication token.
         */
        RAuthentication rAuth = new RBasicAuthentication(System.getProperty("username"),
                System.getProperty("password"));

        /*
         * Establish an authenticated handle with the DeployR
         * server, rUser. Following this call the rClient 
         * connection is operating as an authenticated connection
         * and all calls on rClient inherit the access permissions
         * of the authenticated user, rUser.
         */
        RUser rUser = rClient.login(rAuth);
        log.info("[ AUTHENTICATION ] Upgraded to authenticated " + "connection [ RUser ].");

        /*
         * Create a ProjectCreationOptions instance
         * to specify data inputs that "pre-heat" the R session
         * workspace or working directory for your project.
         */
        ProjectCreationOptions creationOpts = new ProjectCreationOptions();

        /* 
         * Preload from the DeployR repository the following
         * binary R object input file:
         * /testuser/example-data-io/hipStar.rData
         */
        ProjectPreloadOptions preloadWorkspace = new ProjectPreloadOptions();
        preloadWorkspace.filename = "hipStar.rData";
        preloadWorkspace.directory = "example-data-io";
        preloadWorkspace.author = "testuser";
        creationOpts.preloadWorkspace = preloadWorkspace;

        log.info("[ PRELOAD INPUT  ] Repository binary file input "
                + "set on project creation, [ ProjectCreationOptions.preloadWorkspace ].");

        /*
         * Create a temporary project (R session) passing a 
         * ProjectCreationOptions to "pre-heat" data into the
         * workspace and/or working directory.
         */
        rProject = rUser.createProject(creationOpts);

        log.info("[  GO STATEFUL   ] Created stateful temporary " + "R session [ RProject ].");

        /*
         * Create a ProjectExecutionOptions instance
         * to specify data inputs and output to the
         * execution of the repository-managed R script.
         *
         * This options object can be used to pass standard
         * execution model parameters on execution calls. All
         * fields are optional.
         *
         * See the Standard Execution Model chapter in the
         * Client Library Tutorial on the DeployR website for
         * further details.
         */
        ProjectExecutionOptions execOpts = new ProjectExecutionOptions();

        /* 
         * Request storage of entire workspace as a
         * binary rData file to the DeployR-repository
         * following the execution.
         *
         * Alternatively, you could use storageOptions.objects
         * to store individual objects from the workspace.
         */
        ProjectStorageOptions storageOptions = new ProjectStorageOptions();
        // Use random file name for this example.
        storageOptions.workspace = Long.toHexString(Double.doubleToLongBits(Math.random()));
        storageOptions.directory = "example-data-io";
        execOpts.storageOptions = storageOptions;

        log.info("[  EXEC OPTION   ] Repository storage request "
                + "set on execution [ ProjectExecutionOptions.storageOptions ].");

        /*
         * Execute a public analytics Web service as an authenticated
         * user based on a repository-managed R script:
         * /testuser/example-data-io/dataIO.R
         */
        RProjectExecution exec = rProject.executeScript("dataIO.R", "example-data-io", "testuser", null,
                execOpts);

        log.info("[   EXECUTION    ] Stateful R script " + "execution completed [ RProjectExecution ].");

        /*
         * Retrieve repository-managed file(s) that were 
         * generated by the execution per ProjectStorageOptions.
         *
         * Outputs generated by an execution can be used in any
         * number of ways by client applications, including:
         *
         * 1. Use output data to perform further calculations.
         * 2. Display output data to an end-user.
         * 3. Write output data to a database.
         * 4. Pass output data along to another Web service.
         * 5. etc.
         */
        List<RRepositoryFile> repoFiles = exec.about().repositoryFiles;

        for (RRepositoryFile repoFile : repoFiles) {
            log.info("[  DATA OUTPUT   ] Retrieved repository " + "file output " + repoFile.about().filename
                    + " [ RRepositoryFile ].");
            InputStream fis = null;
            try {
                fis = repoFile.download();
            } catch (Exception ex) {
                log.warn("Repository-managed file download " + ex);
            } finally {
                IOUtils.closeQuietly(fis);
                try { // Clean-up after example.
                    repoFile.delete();
                } catch (Exception dex) {
                    log.warn("Repository-managed file delete " + dex);
                }
            }
        }

    } catch (Exception ex) {
        log.warn("Unexpected runtime exception=" + ex);
    } finally {
        try {
            if (rProject != null) {
                /*
                 * Close rProject before application exits.
                 */
                rProject.close();
            }
        } catch (Exception fex) {
        }
        try {
            if (rClient != null) {
                /*
                 * Release rClient connection before application exits.
                 */
                rClient.release();
            }
        } catch (Exception fex) {
        }
    }

}

From source file:MainGeneratePicasaIniFile.java

public static void main(String[] args) {
    try {/*  w  w w . j a  v  a 2  s.  com*/

        Calendar start = Calendar.getInstance();

        start.set(1899, 11, 30, 0, 0);

        PicasawebService myService = new PicasawebService("My Application");
        myService.setUserCredentials(args[0], args[1]);

        // Get a list of all entries
        URL metafeedUrl = new URL("http://picasaweb.google.com/data/feed/api/user/" + args[0] + "?kind=album");
        System.out.println("Getting Picasa Web Albums entries...\n");
        UserFeed resultFeed = myService.getFeed(metafeedUrl, UserFeed.class);

        // resultFeed.

        File root = new File(args[2]);
        File[] albuns = root.listFiles();

        int j = 0;
        List<GphotoEntry> entries = resultFeed.getEntries();
        for (int i = 0; i < entries.size(); i++) {
            GphotoEntry entry = entries.get(i);
            String href = entry.getHtmlLink().getHref();

            String name = entry.getTitle().getPlainText();

            for (File album : albuns) {
                if (album.getName().equals(name) && !href.contains("02?")) {
                    File picasaini = new File(album, "Picasa.ini");

                    if (!picasaini.exists()) {
                        StringBuilder builder = new StringBuilder();

                        builder.append("\n");
                        builder.append("[Picasa]\n");
                        builder.append("name=");
                        builder.append(name);
                        builder.append("\n");
                        builder.append("location=");
                        Collection<Extension> extensions = entry.getExtensions();

                        for (Extension extension : extensions) {

                            if (extension instanceof GphotoLocation) {
                                GphotoLocation location = (GphotoLocation) extension;
                                if (location.getValue() != null) {
                                    builder.append(location.getValue());
                                }
                            }
                        }
                        builder.append("\n");
                        builder.append("category=Folders on Disk");
                        builder.append("\n");
                        builder.append("date=");
                        String source = name.substring(0, 10);

                        DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");

                        Date date = formater.parse(source);

                        Calendar end = Calendar.getInstance();

                        end.setTime(date);

                        builder.append(daysBetween(start, end));
                        builder.append(".000000");
                        builder.append("\n");
                        builder.append(args[0]);
                        builder.append("_lh=");
                        builder.append(entry.getGphotoId());
                        builder.append("\n");
                        builder.append("P2category=Folders on Disk");
                        builder.append("\n");

                        URL feedUrl = new URL("https://picasaweb.google.com/data/feed/api/user/" + args[0]
                                + "/albumid/" + entry.getGphotoId());

                        AlbumFeed feed = myService.getFeed(feedUrl, AlbumFeed.class);

                        for (GphotoEntry photo : feed.getEntries()) {
                            builder.append("\n");
                            builder.append("[");
                            builder.append(photo.getTitle().getPlainText());
                            builder.append("]");
                            builder.append("\n");
                            long id = Long.parseLong(photo.getGphotoId());

                            builder.append("IIDLIST_");
                            builder.append(args[0]);
                            builder.append("_lh=");
                            builder.append(Long.toHexString(id));
                            builder.append("\n");
                        }

                        System.out.println(builder.toString());
                        IOUtils.write(builder.toString(), new FileOutputStream(picasaini));
                        j++;
                    }
                }

            }

        }
        System.out.println(j);
        System.out.println("\nTotal Entries: " + entries.size());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.tiempometa.thingmagic.ReadTest.java

public static void main(String argv[]) {
    // Program setup
    Reader r = null;//w  ww .j  a  v  a2  s.c om
    int nextarg = 0;
    boolean trace = false;

    if (argv.length < 1)
        usage();

    if (argv[nextarg].equals("-v")) {
        trace = true;
        nextarg++;
    }

    // Create Reader object, connecting to physical device
    try {

        TagReadData[] tagReads;
        String uri = argv[nextarg];
        System.out.println("Creating reader with " + uri);
        r = Reader.create(uri);
        System.out.println("Setting trace...");

        // if (trace) {
        // setTrace(r, new String[] { "on" });
        // }
        System.out.println("Connecting...");
        r.connect();
        System.out.println("Connected!");
        if (Reader.Region.UNSPEC == (Reader.Region) r.paramGet("/reader/region/id")) {
            Reader.Region[] supportedRegions = (Reader.Region[]) r
                    .paramGet(TMConstants.TMR_PARAM_REGION_SUPPORTEDREGIONS);
            if (supportedRegions.length < 1) {
                throw new Exception("Reader doesn't support any regions");
            } else {
                r.paramSet("/reader/region/id", supportedRegions[0]);
            }
        }
        r.addReadListener(new TagReadListener());
        int count = 0;
        while (runMe) {
            // Read tags
            tagReads = r.read(500);
            // Print tag reads
            Long password = null;
            Long killword = null;
            for (TagReadData tr : tagReads) {
                p(tr.toString());
                try {
                    String accessCode = readAccess(tr, r);
                    password = Long.parseLong(accessCode, 16);
                    p("Password " + password);
                    p("--" + Long.toHexString(password));
                    accessCode = readKill(tr, r);
                    killword = Long.parseLong(accessCode, 16);
                    p("Killword " + killword);
                    p("--" + Long.toHexString(killword));
                    // if (password == 0) {
                    p("Setting password");
                    password = 0xAFCC01ACl;
                    short[] access = new short[2];
                    access[1] = (short) 0x01AC;
                    access[0] = (short) 0xAFCC;
                    p("Setting password to ");
                    for (short word : access) {
                        System.out.printf("%04X", word);
                    }
                    p("\n");
                    writeAccess(access, tr, r);
                    // }
                    // if (killword == 0) {
                    p("Setting killword");
                    killword = 0xADD001ACl;
                    access = new short[2];
                    access[1] = (short) 0x01AC;
                    access[0] = (short) 0xADD0;
                    p("Setting killword to ");
                    for (short word : access) {
                        System.out.printf("%04X", word);
                    }
                    p("\n");
                    writeKill(access, tr, r);

                    // }
                    if (count < 10) {
                        p("Waiting to lock " + (10 - count));
                    } else if (count == 10) {
                        p("Locking..." + password.intValue());
                        p("--" + Long.toHexString(password));
                        lockTag(password.intValue(), new LockAction(LockAction.KILL_LOCK), tr, r);
                        p("Locked kill");
                        lockTag(password.intValue(), new LockAction(LockAction.ACCESS_LOCK), tr, r);
                        p("Locked access");
                    } else {
                        p("Done with this tag");
                    }
                    count++;
                } catch (ReaderException e) {
                    System.out.println("Exception : " + e.getMessage());
                    killword = 0xADD001ACl;
                    password = 0xAFCC01ACl;
                    if (count < 20) {
                        p("Waiting to unlock " + (20 - count));
                    } else if (count == 20) {
                        p("Unlocking...");
                        p("Password :" + password.intValue());
                        p("--" + Integer.toHexString(password.intValue()));
                        lockTag(password.intValue(), new LockAction(LockAction.ACCESS_UNLOCK), tr, r);
                        p("Unlocked access");
                        lockTag(password.intValue(), new LockAction(LockAction.KILL_UNLOCK), tr, r);
                        p("Unlocked kill");
                        p("***Unlocked");
                        p("Locking...");
                        p("Password :" + password.intValue());
                        lockTag(password.intValue(), new LockAction(LockAction.KILL_LOCK), tr, r);
                        p("Locked kill");
                        lockTag(password.intValue(), new LockAction(LockAction.ACCESS_LOCK), tr, r);
                        p("Locked access");
                    } else if (count == 30) {
                        p("Killing");
                        p("Unlocking access");
                        lockTag(password.intValue(), new LockAction(LockAction.KILL_UNLOCK), tr, r);
                        p("Issuing kill command");
                        killTag(killword.intValue(), tr, r);
                    } else {
                        p("Waiting to kill");
                    }
                    count++;
                }
            }
        }
        // Shut down reader
        r.destroy();
    } catch (ReaderException re) {
        System.out.println("Reader Exception : " + re.getMessage());
    } catch (Exception re) {
        System.out.println("Exception : " + re.getLocalizedMessage());
        System.out.println("Exception : " + re.getMessage());
    } finally {
        r.destroy();
    }
}