1 7 8 package org.gjt.jclasslib.bytecode; 9 10 import org.gjt.jclasslib.io.ByteCodeInput; 11 import org.gjt.jclasslib.io.ByteCodeOutput; 12 13 import java.io.IOException ; 14 15 23 public class PaddedInstruction extends AbstractInstruction { 24 25 29 public PaddedInstruction(int opcode) { 30 super(opcode); 31 } 32 33 38 public int getPaddedSize(int offset) { 39 return getSize() + paddingBytes(offset + 1); 40 } 41 42 public void read(ByteCodeInput in) throws IOException { 43 super.read(in); 44 45 int bytesToRead = paddingBytes(in.getBytesRead()); 46 for (int i = 0; i < bytesToRead; i++) { 47 in.readByte(); 48 } 49 } 50 51 public void write(ByteCodeOutput out) throws IOException { 52 super.write(out); 53 54 int bytesToWrite = paddingBytes(out.getBytesWritten()); 55 for (int i = 0; i < bytesToWrite; i++) { 56 out.writeByte(0); 57 } 58 } 59 60 private int paddingBytes(int bytesCount) { 61 62 int bytesToPad = 4 - bytesCount % 4; 63 return (bytesToPad == 4) ? 0 : bytesToPad; 64 } 65 } 66 | Popular Tags |