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:se.sawano.java.security.otp.TOTPService.java

private static byte[] toHexBytes(final long value) {
    final String hexValue = StringUtils.leftPad(Long.toHexString(value), 16, '0');
    return CodecUtils.decodeHex(hexValue);
}

From source file:com.vaadin.tools.ReportUsage.java

private static String loadFirstLaunch() {
    Preferences prefs = Preferences.userNodeForPackage(CheckForUpdates.class);

    String firstLaunch = prefs.get(FIRST_LAUNCH, null);
    if (firstLaunch == null) {
        long currentTimeMillis = System.currentTimeMillis();
        firstLaunch = Long.toHexString(currentTimeMillis);
        prefs.put(FIRST_LAUNCH, firstLaunch);
    }// w  w w. j av  a2s  .  co m
    return firstLaunch;

}

From source file:com.igormaznitsa.j2z80.utils.Utils.java

/**
 * Convert a long into an ASM HEX representation
 *
 * @param value a long value to be converted
 * @return a hex string representation of the long
 *//*from   ww w  .  java  2 s  .co  m*/
public static String longToString(final long value) {
    final StringBuilder result = new StringBuilder();

    result.append(value).append("(#").append(Long.toHexString(value).toUpperCase()).append(')');

    return result.toString();
}

From source file:de.fu_berlin.inf.dpp.netbeans.feedback.FileSubmitter.java

private static String generateBoundary() {
    Random random = new Random();
    return Long.toHexString(random.nextLong()) + Long.toHexString(random.nextLong())
            + Long.toHexString(random.nextLong());
}

From source file:org.apache.bookkeeper.bookie.storage.ldb.LocationsIndexRebuildOp.java

public void initiate() throws IOException {
    LOG.info("Starting index rebuilding");

    // Move locations index to a backup directory
    String basePath = Bookie.getCurrentDirectory(conf.getLedgerDirs()[0]).toString();
    Path currentPath = FileSystems.getDefault().getPath(basePath, "locations");
    String timestamp = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date());
    Path backupPath = FileSystems.getDefault().getPath(basePath, "locations.BACKUP-" + timestamp);
    Files.move(currentPath, backupPath);

    LOG.info("Created locations index backup at {}", backupPath);

    long startTime = System.nanoTime();

    EntryLogger entryLogger = new EntryLogger(conf, new LedgerDirsManager(conf, conf.getLedgerDirs(),
            new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold())));
    Set<Long> entryLogs = entryLogger.getEntryLogsSet();

    String locationsDbPath = FileSystems.getDefault().getPath(basePath, "locations").toFile().toString();

    Set<Long> activeLedgers = getActiveLedgers(conf, KeyValueStorageRocksDB.factory, basePath);
    LOG.info("Found {} active ledgers in ledger manager", activeLedgers.size());

    KeyValueStorage newIndex = KeyValueStorageRocksDB.factory.newKeyValueStorage(locationsDbPath,
            DbConfigType.Huge, conf);//from  w  ww . j  av a  2s.  c  o  m

    int totalEntryLogs = entryLogs.size();
    int completedEntryLogs = 0;
    LOG.info("Scanning {} entry logs", totalEntryLogs);

    for (long entryLogId : entryLogs) {
        entryLogger.scanEntryLog(entryLogId, new EntryLogScanner() {
            @Override
            public void process(long ledgerId, long offset, ByteBuf entry) throws IOException {
                long entryId = entry.getLong(8);

                // Actual location indexed is pointing past the entry size
                long location = (entryLogId << 32L) | (offset + 4);

                if (LOG.isDebugEnabled()) {
                    LOG.debug("Rebuilding {}:{} at location {} / {}", ledgerId, entryId, location >> 32,
                            location & (Integer.MAX_VALUE - 1));
                }

                // Update the ledger index page
                LongPairWrapper key = LongPairWrapper.get(ledgerId, entryId);
                LongWrapper value = LongWrapper.get(location);
                newIndex.put(key.array, value.array);
            }

            @Override
            public boolean accept(long ledgerId) {
                return activeLedgers.contains(ledgerId);
            }
        });

        ++completedEntryLogs;
        LOG.info("Completed scanning of log {}.log -- {} / {}", Long.toHexString(entryLogId),
                completedEntryLogs, totalEntryLogs);
    }

    newIndex.sync();
    newIndex.close();

    LOG.info("Rebuilding index is done. Total time: {}", DurationFormatUtils
            .formatDurationHMS(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime)));
}

From source file:org.speechforge.cairo.server.resource.ResourceServerImpl.java

private synchronized String getNextChannelID() { // TODO: convert from synchronized to atomic
    return Long.toHexString(_channelID++);
}

From source file:org.apache.bookkeeper.bookie.CreateNewLogTest.java

/**
 * Checks if new log file id is verified against all directories.
 *
 * {@link https://issues.apache.org/jira/browse/BOOKKEEPER-465}
 *
 * @throws Exception/*from  ww w.  j av  a 2  s.  c om*/
 */
@Test
public void testCreateNewLog() throws Exception {
    ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();

    // Creating a new configuration with a number of
    // ledger directories.
    conf.setLedgerDirNames(ledgerDirs);
    LedgerDirsManager ledgerDirsManager = new LedgerDirsManager(conf, conf.getLedgerDirs(),
            new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold()));

    // Extracted from createNewLog()
    String logFileName = Long.toHexString(1) + ".log";
    File dir = ledgerDirsManager.pickRandomWritableDir();
    LOG.info("Picked this directory: {}", dir);
    File newLogFile = new File(dir, logFileName);
    newLogFile.createNewFile();

    EntryLogger el = new EntryLogger(conf, ledgerDirsManager);
    // Calls createNewLog, and with the number of directories we
    // are using, if it picks one at random it will fail.
    EntryLogManagerForSingleEntryLog entryLogManager = (EntryLogManagerForSingleEntryLog) el
            .getEntryLogManager();
    entryLogManager.createNewLog(0L);
    LOG.info("This is the current log id: {}", entryLogManager.getCurrentLogId());
    assertTrue("Wrong log id", entryLogManager.getCurrentLogId() > 1);
}

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

@Test(description = "Test failover functionality with multipart requests")
public void testMultiPart() throws IOException {
    String multipartDataBoundary = Long.toHexString(PlatformDependent.threadLocalRandom().nextLong());
    String multipartBody = "--" + multipartDataBoundary + "\r\n"
            + "Content-Disposition: form-data; name=\"foo\"" + "\r\n"
            + "Content-Type: text/plain; charset=UTF-8" + "\r\n" + "\r\n" + "Part1" + "\r\n" + "--"
            + multipartDataBoundary + "\r\n"
            + "Content-Disposition: form-data; name=\"filepart\"; filename=\"file-01.txt\"" + "\r\n"
            + "Content-Type: text/plain" + "\r\n" + "Content-Transfer-Encoding: binary" + "\r\n" + "\r\n"
            + "Part2" + StringUtil.NEWLINE + "\r\n" + "--" + multipartDataBoundary + "--" + "\r\n";
    Map<String, String> headers = new HashMap<>();
    headers.put(HttpHeaderNames.CONTENT_TYPE.toString(),
            "multipart/form-data; boundary=" + multipartDataBoundary);
    HttpResponse response = HttpClientRequest
            .doPost(serverInstance.getServiceURLHttp(9301, TYPICAL_SERVICE_PATH), multipartBody, headers);
    Assert.assertEquals(response.getResponseCode(), 200, "Response code mismatched");
    Assert.assertTrue(//from   w  ww  .j  a va 2  s  .co  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("form-data;name=\"foo\"content-id: 0Part1"),
            "Message content mismatched");
    Assert.assertTrue(
            response.getData()
                    .contains("form-data;name=\"filepart\";filename=\"file-01.txt\"content-id: 1Part2"),
            "Message content mismatched");
}

From source file:org.eclipse.gyrex.admin.ui.cloud.internal.zookeeper.ZooKeeperData.java

public Object getPropertyValue(final Object id) {
    if (id == PROP_PATH)
        return path;
    if (id == PROP_VERSION)
        return getStat().getVersion();
    if (id == PROP_CVERSION)
        return getStat().getCversion();
    if (id == PROP_EPHEMERAL_OWNER)
        return "0x" + Long.toHexString(getStat().getEphemeralOwner());
    if (id == PROP_DATA_LENGTH)
        return getStat().getDataLength();
    if (id == PROP_DATA)
        return getData();
    return null;//from w  w w .  j av  a 2s .c o  m
}

From source file:org.apache.bookkeeper.bookie.BookieJournalTest.java

private void writeJunkJournal(File journalDir) throws Exception {
    long logId = System.currentTimeMillis();
    File fn = new File(journalDir, Long.toHexString(logId) + ".txn");

    FileChannel fc = new RandomAccessFile(fn, "rw").getChannel();

    ByteBuffer zeros = ByteBuffer.allocate(512);
    fc.write(zeros, 4 * 1024 * 1024);//from   ww  w . jav  a 2s  . co  m
    fc.position(0);

    for (int i = 1; i <= 10; i++) {
        fc.write(ByteBuffer.wrap("JunkJunkJunk".getBytes()));
    }
}