Example usage for java.lang Integer parseUnsignedInt

List of usage examples for java.lang Integer parseUnsignedInt

Introduction

In this page you can find the example usage for java.lang Integer parseUnsignedInt.

Prototype

public static int parseUnsignedInt(String s, int radix) throws NumberFormatException 

Source Link

Document

Parses the string argument as an unsigned integer in the radix specified by the second argument.

Usage

From source file:dumpsection.util.Util.java

public static Set<Integer> stringArrayToUnsignedIntegerSet(String[] src, int radix) {
    Set<Integer> x = new HashSet<>();
    List<String> ls = new ArrayList<>();
    ls.addAll(Arrays.asList(src));
    for (String s : ls) {
        try {/*from   www .j  a  v  a2 s.  com*/
            x.add(Integer.parseUnsignedInt(s, radix));
        } catch (NumberFormatException e) {
            throw e;
        }
    }
    return Collections.unmodifiableSet(x);
}

From source file:org.eclipse.winery.accountability.model.BlockchainElement.java

@Override
public int hashCode() {
    if (this.getTransactionHash() != null) {
        return Integer.parseUnsignedInt(this.getTransactionHash()
                .subSequence(2, Math.min(9, this.getTransactionHash().length())).toString(), 16);
    }//from  w w  w .  ja  v a2  s  .  co  m

    return (int) getUnixTimestamp();
}

From source file:javarestart.WebClassLoader.java

private void preLoadInitial() {
    preloading = true;/*from   w ww.j a  va  2  s. c  om*/
    Thread thread = new Thread() {
        @Override
        public void run() {
            try {
                InputStream in = new URL(baseURL.getProtocol(), baseURL.getHost(), baseURL.getPort(),
                        baseURL.getPath() + "?bundle=initial").openStream();
                while (true) {
                    int nameLength = Integer.parseInt(Utils.readAsciiLine(in), 16);
                    if (nameLength == 0) {
                        return;
                    }
                    String name = Utils.readAsciiLine(in); //TODO: name can be not Ascii
                    curLoading = name;
                    int resLength = Integer.parseUnsignedInt(Utils.readAsciiLine(in), 16);
                    if (resLength != -1) {
                        final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                        Utils.copy(in, buffer, resLength);
                        initialBundle.put(name, buffer.toByteArray());
                        Utils.readAsciiLine(in);
                    } else {
                        initialBundle.put(name, null);
                    }

                    ResourceRequest resourceRequest = WebClassLoader.this.resourceRequest.get();
                    if ((resourceRequest != null) && isPreLoaded(resourceRequest.getRequest())) {
                        resourceRequest.contentReady(getPreloadResource(resourceRequest.getRequest()));
                        WebClassLoader.this.resourceRequest.compareAndSet(resourceRequest, null);
                    }
                }

            } catch (Throwable e) {
                e.printStackTrace();
            } finally {
                preloading = false;
                curLoading = null;
            }
        }
    };
    thread.setDaemon(true);
    thread.start();
}

From source file:dumptspacket.Main.java

public void start(String[] args) throws org.apache.commons.cli.ParseException {
    final String fileName;
    final Long limit;
    final Set<Integer> pids;

    System.out.println("args   : " + dumpArgs(args));

    final Option fileNameOption = Option.builder("f").required().longOpt("filename").desc("ts??")
            .hasArg().type(String.class).build();

    final Option limitOption = Option.builder("l").required(false).longOpt("limit")
            .desc("??(???????EOF??)").hasArg()
            .type(Long.class).build();

    final Option pidsOption = Option.builder("p").required().longOpt("pids")
            .desc("pid(?16?)").type(String.class).hasArgs().build();

    Options opts = new Options();
    opts.addOption(fileNameOption);/*from   w ww . java 2 s.  co  m*/
    opts.addOption(limitOption);
    opts.addOption(pidsOption);
    CommandLineParser parser = new DefaultParser();
    CommandLine cl;
    HelpFormatter help = new HelpFormatter();

    try {

        // parse options
        cl = parser.parse(opts, args);

        // handle interface option.
        fileName = cl.getOptionValue(fileNameOption.getOpt());
        if (fileName == null) {
            throw new ParseException("????????");
        }

        // handlet destination option.
        Long xl = null;
        try {
            xl = Long.parseUnsignedLong(cl.getOptionValue(limitOption.getOpt()));
        } catch (NumberFormatException e) {
            xl = null;
        } finally {
            limit = xl;
        }

        Set<Integer> x = new HashSet<>();
        List<String> ls = new ArrayList<>();
        ls.addAll(Arrays.asList(cl.getOptionValues(pidsOption.getOpt())));
        for (String s : ls) {
            try {
                x.add(Integer.parseUnsignedInt(s, 16));
            } catch (NumberFormatException e) {
                throw new ParseException(e.getMessage());
            }
        }
        pids = Collections.unmodifiableSet(x);

        System.out.println("Starting application...");
        System.out.println("filename   : " + fileName);
        System.out.println("limit : " + limit);
        System.out.println("pids : " + dumpSet(pids));

        // your code
        TsReader reader;
        if (limit == null) {
            reader = new TsReader(new File(fileName), pids);
        } else {
            reader = new TsReader(new File(fileName), pids, limit);
        }

        Map<Integer, List<TsPacketParcel>> ret = reader.getPackets();
        try {
            for (Integer pid : ret.keySet()) {

                FileWriter writer = new FileWriter(fileName + "_" + Integer.toHexString(pid) + ".txt");

                for (TsPacketParcel par : ret.get(pid)) {
                    String text = Hex.encodeHexString(par.getPacket().getData());
                    writer.write(text + "\n");

                }
                writer.flush();
                writer.close();
            }
        } catch (IOException ex) {
            LOG.fatal("", ex);
        }

    } catch (ParseException e) {
        // print usage.
        help.printHelp("My Java Application", opts);
        throw e;
    } catch (FileNotFoundException ex) {
        LOG.fatal("", ex);
    }
}