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

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

Description

write Int

License

Open Source License

Declaration

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

Method Source Code


//package com.java2s;
/*//  ww  w  .  j a v  a  2 s .  c o m
 * Copyright (C) 2014 Markus Grieder
 *
 * 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/gpl-3.0.html>. 
 */

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

public class Main {
    private static final int BYTE1 = 8;
    private static final int BYTE2 = 16;
    private static final int BYTE3 = 24;
    private static final int BYTE_MASK = 0xFF;

    public static int writeInt(byte[] buffer, int value, int index) {
        int i = index;
        buffer[i++] = (byte) value;
        buffer[i++] = (byte) (value >>> BYTE1);
        buffer[i++] = (byte) (value >>> BYTE2);
        buffer[i++] = (byte) (value >>> BYTE3);
        return i;
    }

    public static void writeInt(OutputStream buffer, int value) throws IOException {
        buffer.write(value & BYTE_MASK);
        buffer.write((value >>> BYTE1) & BYTE_MASK);
        buffer.write((value >>> BYTE2) & BYTE_MASK);
        buffer.write((value >>> BYTE3) & BYTE_MASK);
    }
}

Related

  1. writeInt(final OutputStream outputStream, final int integer)
  2. writeInt(int data, int length, OutputStream out)
  3. writeInt(int v, OutputStream stream)
  4. writeInt(int v, OutputStream stream)
  5. writeInt(OutputStream buffer, int val)
  6. writeInt(OutputStream dest, int val)
  7. writeInt(OutputStream file, int value)
  8. writeInt(OutputStream os, int n)
  9. writeInt(OutputStream os, int v)