Here you can find the source of writeInt(OutputStream buffer, int value)
public static void writeInt(OutputStream buffer, int value) throws IOException
//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); } }