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 4 bytes and converts them to an integer.
     *
     * @param buffer 4 bytes
     * @return the integer from the buffer.
     */
    public static int intFromBuffer(byte[] buffer) {
        return intFromBuffer(buffer, 0);
    }

    /**
     * Calculates the integer at the position <code>offset</code> in the buffer
     * @param buffer the offset of the integer
     * @param offset the buffer holding the integer.
     *
     * @return the calculated integer
     */
    public static int intFromBuffer(byte[] buffer, int offset) {
        int result = 0;
        for (int i = 0; i < Integer.SIZE / Byte.SIZE; i++) {
            result <<= Byte.SIZE;
            result |= (buffer[offset + i] & 0xFF);
        }
        return result;
    }
}