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:org.lnicholls.galleon.util.Tools.java

public static String dateToHex(Date date) {
    if (date != null)
        return Long.toHexString(date.getTime() / 1000).toUpperCase();
    else/*from  w w  w  . ja  v  a  2s . co  m*/
        return "";
}

From source file:org.openhab.binding.ihc.internal.ChannelUtils.java

private static void addRFDeviceChannels(Thing thing, NodeList nodes, List<Channel> thingChannels) {
    if (thing != null && nodes != null && thingChannels != null) {
        for (int i = 0; i < nodes.getLength(); i++) {
            Element element = (Element) nodes.item(i);
            Long serialNumber = Long.parseLong(element.getAttribute("serialnumber").replace("_0x", ""), 16);
            if (serialNumber != 0) {
                String name = element.getAttribute("name");
                String position = element.getAttribute("position");

                String serialNumberHex = Long.toHexString(serialNumber);
                Configuration configuration = new Configuration();
                configuration.put("serialNumber", serialNumber);

                // low battery
                String channelId = String.format("%s-lowBattery", serialNumberHex);
                String label = createDescription(position, name, serialNumberHex, "Low Battery");

                Channel channel = ChannelBuilder.create(new ChannelUID(thing.getUID(), channelId), "Switch")
                        .withType(new ChannelTypeUID(BINDING_ID, CHANNEL_TYPE_RF_LOW_BATTERY))
                        .withConfiguration(configuration).withLabel(label).build();
                addOrUpdateChannel(channel, thingChannels);

                // signal level
                channelId = String.format("%s-signalStrength", serialNumberHex);
                label = createDescription(position, name, serialNumberHex, "Signal Strength");

                channel = ChannelBuilder.create(new ChannelUID(thing.getUID(), channelId), "String")
                        .withType(new ChannelTypeUID(BINDING_ID, CHANNEL_TYPE_RF_SIGNAL_STRENGTH))
                        .withConfiguration(configuration).withLabel(label).build();
                addOrUpdateChannel(channel, thingChannels);
            }//from  w  w w .  ja  v  a  2  s.  c o  m
        }
    }
}

From source file:edu.umd.cs.buildServer.BuildServerDaemon.java

@Override
public void initConfig() throws IOException {
    // TODO: Verify that all the important parameters are set, and FAIL
    // EARLY is necessary
    // TODO: Make getter methods in Config for the required params
    // (build.directory, test.files.directory, etc)
    InputStream defaultConfig = BuildServerDaemon.class.getResourceAsStream("defaultConfig.properties");
    getConfig().load(defaultConfig);/* w w w . j a  va 2 s .  com*/
    if (configFile == null) {
        File root = BuildServerConfiguration.getBuildServerRootFromCodeSource();

        if (root == null) {
            throw new IllegalStateException(
                    "No config file specified and could not determine buildserver root");

        }
        File localConfig = new File(root, "config.properties");
        if (!localConfig.exists() || !localConfig.canRead())
            throw new IllegalStateException("No config file specified and not found at " + localConfig);

        configFile = localConfig.getAbsolutePath();
    }

    getConfig().load(new BufferedInputStream(new FileInputStream(configFile)));

    // I'm setting the clover binary database in this method rather than in
    // the config.properties file because it always goes into /tmp and I
    // need
    // a unique name in case there are multiple buildServers on the same
    // host

    // TODO move the location of the Clover DB to the build directory.
    // NOTE: This requires changing the security.policy since Clover needs
    // to be able
    // to read, write and create files in the directory.
    //
    // String cloverDBPath =
    // getConfig().getRequiredProperty(BUILD_DIRECTORY) +"/myclover.db";
    String cloverDBPath = "/tmp/myclover.db." + Long.toHexString(nextRandomLong());
    getConfig().setProperty(CLOVER_DB, cloverDBPath);
}

From source file:ClientManager.java

private void getConfig() throws IOException, MalformedContentNameStringException {
    Properties confFile = new Properties();
    FileInputStream confStream = new FileInputStream("config.properties");
    confFile.load(confStream);//from w  w  w  .  ja v  a2  s. c  o m

    dpid = Long.decode(confFile.getProperty("dpid"));
    ip = InetAddress.getByName(confFile.getProperty("ip"));

    out.println("Datapath ID dpid=" + Long.toHexString(dpid));
    controller = confFile.getProperty("server");
    controller_port = Integer.decode(confFile.getProperty("port", "6635"));
    out.println("Found server address: " + controller + ":" + controller_port);

    content = new HashMap<ContentName, ContentProps>();

    String entrypoint;
    for (int i = 0; (entrypoint = confFile.getProperty("entry." + i)) != null; i++) {
        int cost = Integer.parseInt(confFile.getProperty("entry." + i + ".cost", "0"));
        int priority = Integer.parseInt(confFile.getProperty("entry." + i + ".priority", "0"));

        content.put(ContentName.fromURI(entrypoint), new ContentProps(cost, priority));

        out.println("Found entrypoint  " + entrypoint + " @ cost=" + cost + " and priority=" + priority);
    }
}

From source file:org.apache.accumulo.core.trace.TraceDump.java

public static int printTrace(Scanner scanner, final Printer out) {
    int count = 0;
    SpanTree tree = new SpanTree();
    long start = Long.MAX_VALUE;
    for (Entry<Key, Value> entry : scanner) {
        RemoteSpan span = TraceFormatter.getRemoteSpan(entry);
        tree.addNode(span);/*from  ww  w .  j  ava  2  s  . c o m*/
        start = min(start, span.start);
        if (span.parentId <= 0)
            count++;
    }
    out.print(String.format("Trace started at %s", TraceFormatter.formatDate(new Date(start))));
    out.print("Time  Start  Service@Location       Name");

    final long finalStart = start;
    Set<Long> visited = tree.visit(new SpanTreeVisitor() {
        @Override
        public void visit(int level, RemoteSpan parent, RemoteSpan node, Collection<RemoteSpan> children) {
            String fmt = "%5d+%-5d %" + (level * 2 + 1) + "s%s@%s %s";
            out.print(String.format(fmt, node.stop - node.start, node.start - finalStart, "", node.svc,
                    node.sender, node.description));
        }
    });
    tree.nodes.keySet().removeAll(visited);
    if (!tree.nodes.isEmpty()) {
        out.print("Warning: the following spans are not rooted!");
        for (RemoteSpan span : sortByStart(tree.nodes.values())) {
            out.print(String.format("%s %s %s", Long.toHexString(span.spanId), Long.toHexString(span.parentId),
                    span.description));
        }
    }
    return count;
}

From source file:com.netflix.spinnaker.halyard.config.model.v1.node.Node.java

public void stageLocalFiles(Path outputPath) {
    if (!GlobalApplicationOptions.getInstance().isUseRemoteDaemon()) {
        return;//ww w . j  a  va2s.  c om
    }
    localFiles().forEach(f -> {
        try {
            f.setAccessible(true);
            String fContent = (String) f.get(this);
            if (fContent != null) {
                CRC32 crc = new CRC32();
                crc.update(fContent.getBytes());
                String fPath = Paths
                        .get(outputPath.toAbsolutePath().toString(), Long.toHexString(crc.getValue()))
                        .toString();
                FileUtils.writeStringToFile(new File(fPath), fContent);
                f.set(this, fPath);
            }
        } catch (IllegalAccessException | IOException e) {
            throw new RuntimeException("Failed to get local files for node " + this.getNodeName(), e);
        } finally {
            f.setAccessible(false);
        }
    });
}

From source file:cx.ring.model.CallContact.java

public ArrayList<String> getIds() {
    ArrayList<String> ret = new ArrayList<>(1 + phones.size());
    if (id != UNKNOWN_ID)
        ret.add("c:" + Long.toHexString(id));
    for (Phone p : phones)
        ret.add(p.getNumber().getRawUriString());
    return ret;//from  w w w .ja  va  2  s. c  om
}

From source file:org.ballerinalang.test.service.resiliency.HttpResiliencyTest.java

@Test(description = "Test failover functionality when request has nested body parts")
public void testNestedMultiPart() throws IOException {
    String multipartDataBoundary = Long.toHexString(PlatformDependent.threadLocalRandom().nextLong());
    String multipartMixedBoundary = Long.toHexString(PlatformDependent.threadLocalRandom().nextLong());
    String nestedMultipartBody = "--" + multipartDataBoundary + "\r\n"
            + "Content-Disposition: form-data; name=\"parent1\"" + "\r\n"
            + "Content-Type: text/plain; charset=UTF-8" + "\r\n" + "\r\n" + "Parent Part" + "\r\n" + "--"
            + multipartDataBoundary + "\r\n" + "Content-Disposition: form-data; name=\"parent2\"" + "\r\n"
            + "Content-Type: multipart/mixed; boundary=" + multipartMixedBoundary + "\r\n" + "\r\n" + "--"
            + multipartMixedBoundary + "\r\n" + "Content-Disposition: attachment; filename=\"file-02.txt\""
            + "\r\n" + "Content-Type: text/plain" + "\r\n" + "Content-Transfer-Encoding: binary" + "\r\n"
            + "\r\n" + "Child Part 1" + StringUtil.NEWLINE + "\r\n" + "--" + multipartMixedBoundary + "\r\n"
            + "Content-Disposition: attachment; filename=\"file-02.txt\"" + "\r\n" + "Content-Type: text/plain"
            + "\r\n" + "Content-Transfer-Encoding: binary" + "\r\n" + "\r\n" + "Child Part 2"
            + StringUtil.NEWLINE + "\r\n" + "--" + multipartMixedBoundary + "--" + "\r\n" + "--"
            + multipartDataBoundary + "--" + "\r\n";
    String expectedChildPart1 = "Content-Transfer-Encoding: binary" + "content-type: text/plain"
            + "content-disposition: attachment;filename=\"file-02.txt\"content-id: 0" + "Child Part 1";
    String expectedChildPart2 = "Content-Transfer-Encoding: binary" + "content-type: text/plain"
            + "content-disposition: attachment;filename=\"file-02.txt\"content-id: 1" + "Child Part 2";
    Map<String, String> headers = new HashMap<>();
    headers.put(HttpHeaderNames.CONTENT_TYPE.toString(),
            "multipart/form-data; boundary=" + multipartDataBoundary);
    HttpResponse response = HttpClientRequest
            .doPost(serverInstance.getServiceURLHttp(9302, TYPICAL_SERVICE_PATH), nestedMultipartBody, headers);
    Assert.assertEquals(response.getResponseCode(), 200, "Response code mismatched");
    Assert.assertTrue(/*from  ww w  . ja v  a 2 s.  c  o  m*/
            response.getHeaders().get(HttpHeaderNames.CONTENT_TYPE.toString())
                    .contains("multipart/form-data;boundary=" + multipartDataBoundary),
            "Response is not form of multipart");
    Assert.assertTrue(response.getData().contains(expectedChildPart1), "Message content mismatched");
    Assert.assertTrue(response.getData().contains(expectedChildPart2), "Message content mismatched");
}

From source file:org.lilyproject.tools.generatesplitkeys.GenerateSplitKeys.java

private String toFixedLengthHex(long value, int length) {
    String hex = Long.toHexString(value);
    if (hex.length() > length) {
        throw new RuntimeException("Unexpected: hex representation is longer than it should be: " + hex
                + ", expected only " + length + " characters");
    }//ww w. j a v a 2 s.c  om
    return Strings.repeat("0", length - hex.length()) + hex;
}

From source file:com.mellanox.jxio.MsgPool.java

public String toString() {
    StringBuffer sb = new StringBuffer();
    sb.append("jxio.MsgPool(" + Long.toHexString(refToCObject) + ")");
    sb.append("[count=" + count());
    sb.append(", capacity=" + capacity);
    sb.append(", inSize=" + inSize);
    sb.append(", outSize=" + outSize + "]");
    return sb.toString();
}