Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**
     * Takes the 8 bytes and converts them to an integer.
     *
     * @param buffer 8 bytes containing the long
     * @return the long from the buffer.
     */
    public static long longFromBuffer(byte[] buffer) {
        return longFromBuffer(buffer, 0);
    }

    /**
     * Takes the 8 bytes and converts them to an integer.
     *
     * @param buffer offset + 8 bytes containing the long
     * @param offset the index where the long start in the buffer
     * @return the long from the buffer.
     */
    public static long longFromBuffer(byte[] buffer, int offset) {
        long result = 0;
        for (int i = 0; i < Long.SIZE / Byte.SIZE; i++) {
            result <<= Byte.SIZE;
            result |= (buffer[offset + i] & 0xFF);
        }
        return result;
    }
}