diff options
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java index 07f7990b7b..5a56a0621e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java @@ -103,6 +103,39 @@ public final class NB { } /** + * Convert sequence of 8 bytes (network byte order) into signed value. + * + * @param intbuf + * buffer to acquire the 8 bytes of data from. + * @param offset + * position within the buffer to begin reading from. This + * position and the next 7 bytes after it (for a total of 8 + * bytes) will be read. + * @return signed integer value that matches the 64 bits read. + */ + public static long decodeInt64(final byte[] intbuf, final int offset) { + long r = intbuf[offset] << 8; + + r |= intbuf[offset + 1] & 0xff; + r <<= 8; + + r |= intbuf[offset + 2] & 0xff; + r <<= 8; + + r |= intbuf[offset + 3] & 0xff; + r <<= 8; + + r |= intbuf[offset + 4] & 0xff; + r <<= 8; + + r |= intbuf[offset + 5] & 0xff; + r <<= 8; + + r |= intbuf[offset + 6] & 0xff; + return (r << 8) | (intbuf[offset + 7] & 0xff); + } + + /** * Convert sequence of 4 bytes (network byte order) into unsigned value. * * @param intbuf @@ -186,7 +219,7 @@ public final class NB { * Write a 64 bit integer as a sequence of 8 bytes (network byte order). * * @param intbuf - * buffer to write the 48bytes of data into. + * buffer to write the 8 bytes of data into. * @param offset * position within the buffer to begin writing to. This position * and the next 7 bytes after it (for a total of 8 bytes) will be |