Java OutputStream Write Endian writeInt24(OutputStream out, int value)

Here you can find the source of writeInt24(OutputStream out, int value)

Description

Writes a 24 bit integer to specified output stream.

License

Open Source License

Parameter

Parameter Description
out The output stream to write to.
value The value to write.

Return

The actual number of bytes written.

Declaration

public static int writeInt24(OutputStream out, int value) throws IOException 

Method Source Code

//package com.java2s;
// See LICENSE.txt for license information

import java.io.IOException;

import java.io.OutputStream;

public class Main {
    /**/* w  w  w .ja  va2  s  . c om*/
     * Writes a 24 bit integer to specified output stream.
     * @param out The output stream to write to.
     * @param value The value to write.
     * @return The actual number of bytes written.
     */
    public static int writeInt24(OutputStream out, int value) throws IOException {
        int res = 0;
        if (out != null) {
            for (int i = 0, shift = 0; i < 3; i++, shift += 8) {
                out.write((value >>> shift) & 0xff);
                res++;
            }
        }
        return res;
    }
}

Related

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