public static byte[] replace(byte[] originalBytes,int offset,int length,byte[] replaceBytes){
  byte[] newBytes=new byte[originalBytes.length + (replaceBytes.length - length)];
  System.arraycopy(originalBytes,0,newBytes,0,offset);
  System.arraycopy(replaceBytes,0,newBytes,offset,replaceBytes.length);
  System.arraycopy(originalBytes,offset + length,newBytes,offset + replaceBytes.length,originalBytes.length - offset - length);
  return newBytes;
}

public static byte [ ] replace ( byte [ ] originalBytes , int offset , int length , byte [ ] replaceBytes ) { byte [ ] newBytes = new byte [ originalBytes . length + ( replaceBytes . length - length ) ] ; System . arraycopy ( originalBytes , 0 , newBytes , 0 , offset ) ; System . arraycopy ( replaceBytes , 0 , newBytes , offset , replaceBytes . length ) ; System . arraycopy ( originalBytes , offset + length , newBytes , offset + replaceBytes . length , originalBytes . length - offset - length ) ; return newBytes ; }
replaces bytes in the specified sub array .
