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

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

Description

Write an int.

License

Open Source License

Parameter

Parameter Description
out The OutputStream to write the int to
value The int to write

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

import java.io.OutputStream;
import java.util.Arrays;

public class Main {
    private static final byte[] buffer = new byte[1024];

    /**/*from www  .  j  a  v a 2 s.  c o  m*/
     * Write an int.
     *
     * @param out   The OutputStream to write the int to
     * @param value The int to write
     */
    public static void writeInt(OutputStream out, int value) throws IOException {
        out.write(value >> 24);
        out.write(value >> 16);
        out.write(value >> 8);
        out.write(value);
    }

    /**
     * Write a number of bytes
     *
     * @param out  The OutputStream to write to
     * @param data The bytes to write
     * @throws IOException
     */
    public static void write(OutputStream out, byte[] data) throws IOException {
        out.write(data);
    }

    /**
     * Write a repeated byte value.
     *
     * @param out   The OutputStream to write to
     * @param value The value to write
     * @param count Number of times to write the value
     */
    public static void write(final OutputStream out, final int value, final int count) throws IOException {
        if (count > buffer.length) {
            // Fallback
            for (int i = 0; i < count; i++) {
                writeByte(out, value);
            }
        } else {
            Arrays.fill(buffer, (byte) value);
            out.write(buffer, 0, count);
        }
    }

    /**
     * Write a byte.
     *
     * @param out   The OutputStream to write the byte to
     * @param value The byte to write
     * @throws IOException
     */
    public static void writeByte(OutputStream out, int value) throws IOException {
        out.write(value);
    }
}

Related

  1. writeInt(OutputStream out, int i)
  2. writeInt(OutputStream out, int v)
  3. writeInt(OutputStream out, int v)
  4. writeInt(OutputStream out, int value)
  5. writeInt(OutputStream out, int value)
  6. writeInt(OutputStream out, int value)
  7. writeInt(OutputStream out, int x)
  8. writeInt(OutputStream out, int x)
  9. writeInt(OutputStream output, int value)