@Test public void testWriteInt() { try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); IOUtil.writeInt(bout, 3); IOUtil.writeInt(bout, 4); IOUtil.writeInt(bout, 0xFF0000AA); IOUtil.writeInt(bout, 0xAABBCCDD); ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); long a = IOUtil.readInt(bin); assertEquals(a, 3); long b = IOUtil.readInt(bin); assertEquals(b, 4); long c = IOUtil.readInt(bin); assertEquals(c, 0xFF0000AA); long d = IOUtil.readInt(bin); assertEquals(d, 0xAABBCCDD); } catch (IOException e) { fail("Exception thrown: "+e); } }
public static void writeInt(OutputStream output, int value) throws IOException { byte[] writeBuffer = new byte[4]; writeBuffer[0] = (byte) (value & 0xFF); writeBuffer[1] = (byte) ((value>>8) & 0xFF); writeBuffer[2] = (byte) ((value>>16) & 0xFF); writeBuffer[3] = (byte) ((value>>24) & 0xFF); output.write(writeBuffer,0,4); }
IOUtil { public static void writeInt(OutputStream output, int value) throws IOException { byte[] writeBuffer = new byte[4]; writeBuffer[0] = (byte) (value & 0xFF); writeBuffer[1] = (byte) ((value>>8) & 0xFF); writeBuffer[2] = (byte) ((value>>16) & 0xFF); writeBuffer[3] = (byte) ((value>>24) & 0xFF); output.write(writeBuffer,0,4); } }
IOUtil { public static void writeInt(OutputStream output, int value) throws IOException { byte[] writeBuffer = new byte[4]; writeBuffer[0] = (byte) (value & 0xFF); writeBuffer[1] = (byte) ((value>>8) & 0xFF); writeBuffer[2] = (byte) ((value>>16) & 0xFF); writeBuffer[3] = (byte) ((value>>24) & 0xFF); output.write(writeBuffer,0,4); } private  IOUtil(); }
IOUtil { public static void writeInt(OutputStream output, int value) throws IOException { byte[] writeBuffer = new byte[4]; writeBuffer[0] = (byte) (value & 0xFF); writeBuffer[1] = (byte) ((value>>8) & 0xFF); writeBuffer[2] = (byte) ((value>>16) & 0xFF); writeBuffer[3] = (byte) ((value>>24) & 0xFF); output.write(writeBuffer,0,4); } private  IOUtil(); static InputStream getFileInputStream(String fileName); static BufferedReader getFileReader(String fileName); static String readLine(InputStream in, char character); static String readChars(InputStream in, int numChars); static void writeString(OutputStream out, String str); static void writeBuffer(OutputStream output, byte [] buffer, int offset, int length, ProgressListener listener); static void copyStream(InputStream in, OutputStream out); static void copyStream(InputStream in, OutputStream out, long n); static void copyFile(File src, File dst); static void moveFile(File src, File dst); static void decompressGzip(File src, File trgt); static void writeLong(OutputStream output, long value); static long readLong(InputStream input); static void writeInt(OutputStream output, int value); static byte[] intToByteArray(int value); static int readInt(InputStream in); static int byteArrayToInt(byte[] value); static byte[] readBuffer(InputStream input, int length, ProgressListener listener); static CharSequence toBinaryString(long val); static CharSequence toBinaryString(int val); static void printBitsln(long val, int bits); static void printBits(long val, int bits); static short readShort(InputStream in); static void writeShort(OutputStream out, short value); static byte readByte(InputStream in); static void writeByte(OutputStream out, byte value); static void skip(InputStream in, long n); static void closeQuietly(Closeable output); }
IOUtil { public static void writeInt(OutputStream output, int value) throws IOException { byte[] writeBuffer = new byte[4]; writeBuffer[0] = (byte) (value & 0xFF); writeBuffer[1] = (byte) ((value>>8) & 0xFF); writeBuffer[2] = (byte) ((value>>16) & 0xFF); writeBuffer[3] = (byte) ((value>>24) & 0xFF); output.write(writeBuffer,0,4); } private  IOUtil(); static InputStream getFileInputStream(String fileName); static BufferedReader getFileReader(String fileName); static String readLine(InputStream in, char character); static String readChars(InputStream in, int numChars); static void writeString(OutputStream out, String str); static void writeBuffer(OutputStream output, byte [] buffer, int offset, int length, ProgressListener listener); static void copyStream(InputStream in, OutputStream out); static void copyStream(InputStream in, OutputStream out, long n); static void copyFile(File src, File dst); static void moveFile(File src, File dst); static void decompressGzip(File src, File trgt); static void writeLong(OutputStream output, long value); static long readLong(InputStream input); static void writeInt(OutputStream output, int value); static byte[] intToByteArray(int value); static int readInt(InputStream in); static int byteArrayToInt(byte[] value); static byte[] readBuffer(InputStream input, int length, ProgressListener listener); static CharSequence toBinaryString(long val); static CharSequence toBinaryString(int val); static void printBitsln(long val, int bits); static void printBits(long val, int bits); static short readShort(InputStream in); static void writeShort(OutputStream out, short value); static byte readByte(InputStream in); static void writeByte(OutputStream out, byte value); static void skip(InputStream in, long n); static void closeQuietly(Closeable output);  }