MCPcopy Create free account
hub / github.com/OpenTSDB/opentsdb / longToUID

Method longToUID

src/uid/UniqueId.java:1477–1490  ·  view source on GitHub ↗

Converts a Long to a byte array with the proper UID width @param uid The UID to convert @param width The width of the UID in bytes @return The UID as a byte array @throws IllegalStateException if the UID is larger than the width would allow @since 2.1

(final long uid, final short width)

Source from the content-addressed store, hash-verified

1475 * @since 2.1
1476 */
1477 public static byte[] longToUID(final long uid, final short width) {
1478 // Verify that we're going to drop bytes that are 0.
1479 final byte[] padded = Bytes.fromLong(uid);
1480 for (int i = 0; i < padded.length - width; i++) {
1481 if (padded[i] != 0) {
1482 final String message = "UID " + Long.toString(uid) +
1483 " was too large for " + width + " bytes";
1484 LOG.error("OMG " + message);
1485 throw new IllegalStateException(message);
1486 }
1487 }
1488 // Shrink the ID on the requested number of bytes.
1489 return Arrays.copyOfRange(padded, padded.length - width, padded.length);
1490 }
1491
1492 /**
1493 * Appends the given UID to the given string buffer, followed by "\\E".

Callers 5

longToUIDMethod · 0.95
longToUIDTooBigMethod · 0.95
TestTsdbTSConfigClass · 0.95
getScannerMethod · 0.95
getScannerMethod · 0.95

Calls 2

errorMethod · 0.80
toStringMethod · 0.45

Tested by 2

longToUIDMethod · 0.76
longToUIDTooBigMethod · 0.76