DexDataWriter extends BufferedOutputStream { public void align() throws IOException { int zeros = (-getPosition()) & 3; if (zeros > 0) { write(zeroBuf, 0, zeros); } } DexDataWriter(@Nonnull OutputStream output, int filePosition);  DexDataWriter(@Nonnull OutputStream output, int filePosition, int bufferSize); @Override void write(int b); @Override void write(byte[] b); @Override void write(byte[] b, int off, int len); void writeLong(long value); static void writeInt(OutputStream out, int value); void writeInt(int value); void writeShort(int value); void writeUshort(int value); void writeUbyte(int value); static void writeUleb128(OutputStream out, int value); void writeUleb128(int value); static void writeSleb128(OutputStream out, int value); void writeSleb128(int value); void writeEncodedValueHeader(int valueType, int valueArg); void writeEncodedInt(int valueType, int value); void writeEncodedLong(int valueType, long value); void writeEncodedUint(int valueType, int value); void writeEncodedFloat(int valueType, float value); void writeEncodedDouble(int valueType, double value); void writeString(String string); void align(); int getPosition();  }
@Test public void testAlign() throws IOException { startPosition = 0; writer = new DexDataWriter(output, startPosition, 256); writer.align(); writer.write(1); writer.align(); writer.align(); writer.write(1); writer.write(2); writer.align(); writer.write(1); writer.write(2); writer.write(3); writer.align(); writer.align(); writer.write(1); writer.write(2); writer.write(3); writer.write(4); writer.align(); writer.align(); writer.align(); writer.align(); writer.write(1); writer.align(); expectData(0x01, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x04, 0x01, 0x00, 0x00, 0x00); }