Java RandomAccessFile Read readLongLittleEndian( RandomAccessFile randomAccessFile)

Here you can find the source of readLongLittleEndian( RandomAccessFile randomAccessFile)

Description

read Long Little Endian

License

Open Source License

Declaration

public static long readLongLittleEndian(
            RandomAccessFile randomAccessFile) throws IOException 

Method Source Code

//package com.java2s;
/*//from   w w  w .  ja  va2  s.  com
 * ====================================================================
 * Copyright (c) 2004-2012 TMate Software Ltd.  All rights reserved.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.  The terms
 * are also available at http://svnkit.com/license.html.
 * If newer versions of this license are posted there, you may use a
 * newer version instead, at your option.
 * ====================================================================
 */

import java.io.IOException;

import java.io.RandomAccessFile;

public class Main {
    private static final int BYTES_IN_LONG = Long.SIZE / 8;
    private static final byte[] BUFFER = new byte[BYTES_IN_LONG];

    public static long readLongLittleEndian(
            RandomAccessFile randomAccessFile) throws IOException {
        final int bytesRead = randomAccessFile.read(BUFFER, 0,
                BYTES_IN_LONG);
        if (bytesRead < 0) {
            return bytesRead;
        }
        long value = 0;
        for (int i = BYTES_IN_LONG - 1; i >= 0; i--) {
            value = (value << 8) + (BUFFER[i] & 0xffL);
        }
        return value;
    }
}

Related

  1. readFile(String filePath)
  2. readFileByRandomAccess(String fileName)
  3. readFileBytes(final File file)
  4. readFileFully(File f)
  5. readLine(RandomAccessFile file, long position, int trim)