Java OutputStream Write Int writeInt(OutputStream file, int value)

Here you can find the source of writeInt(OutputStream file, int value)

Description

The "writeInt" function of java writes in BigEndian mode but we need LittleEndian so i made a custom function for that

License

Open Source License

Parameter

Parameter Description
file a parameter

Exception

Parameter Description
IOException if any error occur while writing

Declaration

public static void writeInt(OutputStream file, int value)
        throws IOException 

Method Source Code

//package com.java2s;
/*  MHTools - MH Utilities
 Copyright (C) 2011 Codestation//from  w w  w. j av a2  s.com

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program 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 General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.IOException;

import java.io.OutputStream;
import java.io.RandomAccessFile;

public class Main {
    /**
     * The "writeInt" function of java writes in BigEndian mode but we need
     * LittleEndian so i made a custom function for that
     * 
     * @param file
     * @throws IOException
     *             if any error occur while writing
     */
    public static void writeInt(OutputStream file, int value)
            throws IOException {
        int ch1 = (byte) (value >>> 24);
        int ch2 = (byte) (value >>> 16);
        int ch3 = (byte) (value >>> 8);
        int ch4 = (byte) value;
        file.write(ch4);
        file.write(ch3);
        file.write(ch2);
        file.write(ch1);
    }

    public static void writeInt(RandomAccessFile file, int value)
            throws IOException {
        int ch1 = (byte) (value >>> 24);
        int ch2 = (byte) (value >>> 16);
        int ch3 = (byte) (value >>> 8);
        int ch4 = (byte) value;
        file.write(ch4);
        file.write(ch3);
        file.write(ch2);
        file.write(ch1);
    }
}

Related

  1. writeInt(int v, OutputStream stream)
  2. writeInt(int v, OutputStream stream)
  3. writeInt(OutputStream buffer, int val)
  4. writeInt(OutputStream buffer, int value)
  5. writeInt(OutputStream dest, int val)
  6. writeInt(OutputStream os, int n)
  7. writeInt(OutputStream os, int v)
  8. writeInt(OutputStream os, int val)
  9. writeInt(OutputStream os, int value)