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.codenergic.theskeleton.gallery.impl.GalleryServiceImpl.java

private String saveImageToS3(String userId, GalleryEntity image)
        throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
        InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
        InternalException, InvalidArgumentException {
    String imageObjectName = StringUtils.join(userId, "/", Long.toHexString(Instant.now().toEpochMilli()), "-",
            UUID.randomUUID().toString());
    minioClient.putObject(GALLERY_BUCKET_NAME, imageObjectName, image.getImage(), image.getFormat());
    return minioClient.getObjectUrl(GALLERY_BUCKET_NAME, imageObjectName);
}

From source file:com.m3.openid4java.server.MemcachedServerAssociationStore.java

@Override
public Association generate(String type, int expiryIn) throws AssociationException {
    int attemptsLeft = 5;
    while (attemptsLeft > 0) {
        try {//from www. ja  v  a2  s .co  m
            String handle = Long.toHexString(random.nextLong());
            Association association = Association.generate(type, handle, expiryIn);
            String macKey = new String(Base64.encodeBase64(association.getMacKey().getEncoded()));
            saveAssociation(new ServerAssociation(handle, type, macKey, association.getExpiry()));
            return association;
        } catch (Exception e) {
            if (log.isDebugEnabled()) {
                log.debug("Failed to save a new association value.", e);
            }
            attemptsLeft--;
        }
    }
    throw new AssociationException("Error generating association.");
}

From source file:eu.openanalytics.rsb.config.PersistedConfigurationAdapter.java

private String getDefaultNodeName() {
    // find something unique about the running node like the location of resource
    final URL resourceUrl = getClass().getResource("/META-INF/spring/core-beans.xml");
    final String uniqueId = Long.toHexString(Math.abs((long) resourceUrl.toExternalForm().hashCode()));
    return StringUtils.lowerCase(Constants.HOST_NAME + "-" + uniqueId);
}

From source file:org.globus.gsi.util.CertificateIOUtil.java

private synchronized static String hash(byte[] data) {
    init();/*from w  w  w  .  ja v  a 2s  . c  om*/
    if (md5 == null) {
        return null;
    }

    md5.reset();
    md5.update(data);

    byte[] md = md5.digest();

    long ret = (fixByte(md[0]) | (fixByte(md[1]) << 8L));
    ret = ret | fixByte(md[2]) << 16L;
    ret = ret | fixByte(md[3]) << 24L;
    ret = ret & 0xffffffffL;

    return Long.toHexString(ret);
}

From source file:org.globus.security.util.CertificateIOUtil.java

private static String hash(byte[] data) {
    init();/*from  w w  w .  j  av a  2s.c o  m*/
    if (md5 == null) {
        return null;
    }

    md5.reset();
    md5.update(data);

    byte[] md = md5.digest();

    long ret = (fixByte(md[0]) | (fixByte(md[1]) << 8L));
    ret = ret | fixByte(md[2]) << 16L;
    ret = ret | fixByte(md[3]) << 24L;
    ret = ret & 0xffffffffL;

    return Long.toHexString(ret);
}

From source file:com.hpcloud.mon.resource.exception.Exceptions.java

/**
 * Builds and returns an error message containing an error code, and logs the message with the
 * corresponding error code.// w ww .j  ava  2 s. co m
 */
public static String buildLoggedErrorMessage(FaultType faultType, String message, @Nullable String details,
        @Nullable Throwable exception) {
    String errorCode = Long.toHexString(RANDOM.nextLong());

    if (faultType.loggable) {
        String withoutDetails = "{} {} - {}";
        String withDetails = "{} {} - {} {}";

        if (details == null) {
            if (exception == null)
                LOG.error(withoutDetails, faultType.name(), errorCode, message);
            else
                LOG.error(withoutDetails, faultType.name(), errorCode, message, exception);
        } else {
            if (exception == null)
                LOG.error(withDetails, faultType.name(), errorCode, message, details);
            else
                LOG.error(withDetails, faultType.name(), errorCode, message, details, exception);
        }
    }

    try {
        StringBuilder str = new StringBuilder("{\"");
        str.append(faultType.toString());
        str.append("\":");
        str.append(OBJECT_MAPPER
                .writeValueAsString(new ErrorMessage(faultType.statusCode, message, details, errorCode)));
        str.append("}");
        return str.toString();
    } catch (JsonProcessingException bestEffort) {
        return null;
    }
}

From source file:org.springframework.integration.smb.session.SmbShare.java

public String newTempFileSuffix() {
    return "-" + Long.toHexString(Double.doubleToLongBits(Math.random())) + ".tmp";
}

From source file:org.apache.accumulo.core.util.shell.commands.TraceCommand.java

public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws IOException {
    if (cl.getArgs().length == 1) {
        if (cl.getArgs()[0].equalsIgnoreCase("on")) {
            Trace.on("shell:" + shellState.getPrincipal());
        } else if (cl.getArgs()[0].equalsIgnoreCase("off")) {
            if (Trace.isTracing()) {
                final long trace = Trace.currentTrace().traceId();
                Trace.off();// w w w  . j  ava2 s.co m
                StringBuffer sb = new StringBuffer();
                int traceCount = 0;
                for (int i = 0; i < 30; i++) {
                    sb = new StringBuffer();
                    try {
                        final Map<String, String> properties = shellState.getConnector().instanceOperations()
                                .getSystemConfiguration();
                        final String table = properties.get(Property.TRACE_TABLE.getKey());
                        final String user = shellState.getConnector().whoami();
                        final Authorizations auths = shellState.getConnector().securityOperations()
                                .getUserAuthorizations(user);
                        final Scanner scanner = shellState.getConnector().createScanner(table, auths);
                        scanner.setRange(new Range(new Text(Long.toHexString(trace))));
                        final StringBuffer finalSB = sb;
                        traceCount = TraceDump.printTrace(scanner, new Printer() {
                            @Override
                            public void print(final String line) {
                                try {
                                    finalSB.append(line + "\n");
                                } catch (Exception ex) {
                                    throw new RuntimeException(ex);
                                }
                            }
                        });
                        if (traceCount > 0) {
                            shellState.getReader().print(sb.toString());
                            break;
                        }
                    } catch (Exception ex) {
                        shellState.printException(ex);
                    }
                    shellState.getReader().println("Waiting for trace information");
                    shellState.getReader().flush();
                    UtilWaitThread.sleep(500);
                }
                if (traceCount < 0) {
                    // display the trace even though there are unrooted spans
                    shellState.getReader().print(sb.toString());
                }
            } else {
                shellState.getReader().println("Not tracing");
            }
        } else
            throw new BadArgumentException("Argument must be 'on' or 'off'", fullCommand,
                    fullCommand.indexOf(cl.getArgs()[0]));
    } else if (cl.getArgs().length == 0) {
        shellState.getReader().println(Trace.isTracing() ? "on" : "off");
    } else {
        shellState.printException(new IllegalArgumentException(
                "Expected 0 or 1 argument. There were " + cl.getArgs().length + "."));
        printHelp(shellState);
        return 1;
    }
    return 0;
}

From source file:org.trancecode.xproc.step.HashStepProcessor.java

@Override
protected void execute(final StepInput input, final StepOutput output) {
    final XdmNode sourceDocument = input.readNode(XProcPorts.SOURCE);
    final String value = input.getOptionValue(XProcOptions.VALUE);
    assert value != null;
    LOG.trace("value = {}", value);
    final String algorithm = input.getOptionValue(XProcOptions.ALGORITHM);
    assert algorithm != null;
    LOG.trace("algorithm = {}", algorithm);
    final String match = input.getOptionValue(XProcOptions.MATCH);
    assert match != null;
    LOG.trace("match = {}", match);
    final String version = input.getOptionValue(XProcOptions.VERSION);
    LOG.trace("version = {}", version);

    final String hashValue;
    if (StringUtils.equalsIgnoreCase("crc", algorithm)) {
        if ("32".equals(version) || version == null) {
            final CRC32 crc32 = new CRC32();
            crc32.update(value.getBytes());
            hashValue = Long.toHexString(crc32.getValue());
        } else {//w ww  .  j a v a  2  s  .c om
            throw XProcExceptions.xc0036(input.getLocation());
        }
    } else if (StringUtils.equalsIgnoreCase("md", algorithm)) {
        if (version == null || "5".equals(version)) {
            hashValue = DigestUtils.md5Hex(value);
        } else {
            throw XProcExceptions.xc0036(input.getLocation());
        }
    } else if (StringUtils.equalsIgnoreCase("sha", algorithm)) {
        if (version == null || "1".equals(version)) {
            hashValue = DigestUtils.shaHex(value);
        } else if ("256".equals(version)) {
            hashValue = DigestUtils.sha256Hex(value);
        } else if ("384".equals(version)) {
            hashValue = DigestUtils.sha384Hex(value);
        } else if ("512".equals(version)) {
            hashValue = DigestUtils.sha512Hex(value);
        } else {
            throw XProcExceptions.xc0036(input.getLocation());
        }
    } else {
        throw XProcExceptions.xc0036(input.getLocation());
    }

    final SaxonProcessorDelegate hashDelegate = new AbstractSaxonProcessorDelegate() {
        @Override
        public boolean startDocument(final XdmNode node, final SaxonBuilder builder) {
            return true;
        }

        @Override
        public void endDocument(final XdmNode node, final SaxonBuilder builder) {
        }

        @Override
        public EnumSet<NextSteps> startElement(final XdmNode element, final SaxonBuilder builder) {
            builder.text(hashValue);
            return EnumSet.noneOf(NextSteps.class);
        }

        @Override
        public void endElement(final XdmNode node, final SaxonBuilder builder) {
            builder.endElement();
        }

        @Override
        public void attribute(final XdmNode node, final SaxonBuilder builder) {
            builder.attribute(node.getNodeName(), hashValue);
        }

        @Override
        public void comment(final XdmNode node, final SaxonBuilder builder) {
            builder.comment(hashValue);
        }

        @Override
        public void processingInstruction(final XdmNode node, final SaxonBuilder builder) {
            builder.processingInstruction(node.getNodeName().getLocalName(), hashValue);
        }

        @Override
        public void text(final XdmNode node, final SaxonBuilder builder) {
            builder.text(hashValue);
        }
    };

    final SaxonProcessor hashProcessor = new SaxonProcessor(input.getPipelineContext().getProcessor(),
            SaxonProcessorDelegates.forXsltMatchPattern(input.getPipelineContext().getProcessor(), match,
                    input.getStep().getNode(), hashDelegate, new CopyingSaxonProcessorDelegate()));

    final XdmNode result = hashProcessor.apply(sourceDocument);
    output.writeNodes(XProcPorts.RESULT, result);
}

From source file:com.threewks.thundr.util.Encoder.java

public Encoder crc32() {
    Checksum checksum = new CRC32();
    checksum.update(data, 0, data.length);
    long checksumValue = checksum.getValue();
    data = Long.toHexString(checksumValue).getBytes();
    return unhex();
}