Java OutputStream Write Endian writeInt32(OutputStream in_stream, int in_value)

Here you can find the source of writeInt32(OutputStream in_stream, int in_value)

Description

Writes a signed 32-bit integer value to the given output stream.

License

Open Source License

Parameter

Parameter Description
in_stream - The stream to write the value to.
in_value - The value to write to the stream.

Exception

Parameter Description
IOException - Any IO Exception thrown by the given stream.

Declaration

public static void writeInt32(OutputStream in_stream, int in_value)
        throws IOException 

Method Source Code

//package com.java2s;
/**//from   w ww .  j av  a 2  s . com
 * LittleEndianWriterUtils.java
 * ChilliSource
 * Created by Ian Copland on 24/10/2014
 * 
 * The MIT License (MIT)
 * 
 * Copyright (c) 2014 Tag Games Limited
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

import java.io.IOException;
import java.io.OutputStream;

public class Main {
    /**
     * Writes a signed 32-bit integer value to the given output stream. The value 
     * will be converted to little endian before being written.
     * 
     * @param in_stream - The stream to write the value to.
     * @param in_value - The value to write to the stream.
     * 
     * @throws IOException - Any IO Exception thrown by the given stream.
     */
    public static void writeInt32(OutputStream in_stream, int in_value)
            throws IOException {
        byte[] bytes = new byte[4];

        bytes[0] = (byte) (in_value & 0xFF);
        bytes[1] = (byte) (in_value >>> 8 & 0xFF);
        bytes[2] = (byte) (in_value >>> 16 & 0xFF);
        bytes[3] = (byte) (in_value >>> 24 & 0xFF);

        in_stream.write(bytes);
    }
}

Related

  1. writeInt16(OutputStream out, int i)
  2. writeInt24(OutputStream os, int value)
  3. writeInt24(OutputStream out, int value)
  4. writeInt2BE(OutputStream out, int v)
  5. writeInt2BE(OutputStream out, int v)
  6. writeInt32BE(OutputStream os, int val)