BinaryWriter implements AutoCloseable { public void writeUInt32(long v) throws IOException { if (v < 0 || v >= (long) Math.pow(2, 32)) { throw new IllegalArgumentException("Value of 32-bit unsigned integer was not in " + "interval [0, 2^32)."); } buffer.putLong(0, v); writer.write(array, 0, 4); } BinaryWriter(OutputStream stream); @Override void close(); void flush(); void write(byte[] buffer); void write(byte[] buffer, int index, int length); void writeBoolean(boolean v); void writeByte(byte v); void writeDouble(double v); void writeECPoint(ECPoint v); void writeFixedString(String v, int length); void writeFloat(float v); void writeInt32(int v); void writeInt64(long v); void writeUInt32(long v); void writeSerializableVariableBytes(NeoSerializable v); void writeSerializableVariable(List<? extends NeoSerializable> v); void writeSerializableVariableBytes(List<? extends NeoSerializable> v); void writeSerializableFixed(NeoSerializable v); void writeSerializableFixed(List<? extends NeoSerializable> v); void writeUInt16(int v); void writeVarBytes(byte[] v); void writeVarInt(long v);  }
@Test public void writeUInt32() throws IOException { long uint = (long) Math.pow(2, 32) - 1; writer.writeUInt32(uint); assertAndResetStreamContents( new byte[]{(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}); uint = 0L; writer.writeUInt32(uint); assertAndResetStreamContents(new byte[]{0, 0, 0, 0}); uint = 12345L; writer.writeUInt32(uint); assertAndResetStreamContents(new byte[]{0x39, 0x30, 0, 0}); }
@Test public void failWritingUInt32NotInRange() throws IOException { try { Long uint = (long) Math.pow(2, 32); writer.writeUInt32(uint); fail(); } catch (IllegalArgumentException ignored) { } try { Long uint = -1L; writer.writeUInt32(uint); fail(); } catch (IllegalArgumentException ignored) { } }