Java File Read via ByteBuffer readUint32(final DataInput di)

Here you can find the source of readUint32(final DataInput di)

Description

Read a 32-bit big-endian unsigned integer using a DataInput.

License

Open Source License

Declaration

public static long readUint32(final DataInput di) throws IOException 

Method Source Code


//package com.java2s;
/*//  w w  w.  j  a va2  s .  c o  m
 * Copyright (c) 2017 Eric A. Snell
 *
 * This file is part of eAlvaTag.
 *
 * eAlvaTag is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser
 * General Public License as published by the Free Software Foundation, either version 3 of the License,
 * or (at your option) any later version.
 *
 * eAlvaTag is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with eAlvaTag.  If not,
 * see <http://www.gnu.org/licenses/>.
 */

import java.io.DataInput;

import java.io.IOException;
import java.nio.ByteBuffer;

public class Main {
    /**
     * Read a 32-bit big-endian unsigned integer using a DataInput.
     * <p>
     * Reads 4 bytes but returns as long
     */
    public static long readUint32(final DataInput di) throws IOException {
        final byte[] buf8 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
        di.readFully(buf8, 4, 4);
        return ByteBuffer.wrap(buf8).getLong();
    }
}

Related

  1. readStringInUTF8(DataInput in)
  2. readToBuffer(final String filename)
  3. readToByteArray(String fname)
  4. readTwoByteInt(byte[] array, int start)
  5. readTxtFromFile(File file)
  6. readUint32AsInt(DataInput di)
  7. readUintLE(byte[] bytes, int pointer, int size)
  8. readUnsignedInt(InputStream is)
  9. readUnsignedInt24(InputStream is)