Here you can find the source of writeInt(OutputStream file, int value)
Parameter | Description |
---|---|
file | a parameter |
Parameter | Description |
---|---|
IOException | if any error occur while writing |
public static void writeInt(OutputStream file, int value) throws IOException
//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); } }