Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Creative Commons License 

import java.io.IOException;
import java.io.RandomAccessFile;

public class Main {
    /**
     * Reads 4 bytes from file and interprets them as UINT32.<br>
     * 
     * @param raf
     *            file to read from.
     * @return UINT32 value
     * @throws IOException
     *             on I/O Errors.
     */
    public static long readUINT32(RandomAccessFile raf) throws IOException {
        long result = 0;
        for (int i = 0; i < 4; i++) {
            // Warning, always cast to long here. Otherwise it will be
            // shifted as int, which may produce a negative value, which will
            // then be extended to long and assign the long variable a negative
            // value.
            result <<= 8;
            result |= (long) raf.read();
        }
        return result;
    }
}