public static byte[] copyWithLength(byte[] orig,int length){
  byte[] result=new byte[length];
  int howMuchToCopy=length < orig.length ? length : orig.length;
  System.arraycopy(orig,0,result,0,howMuchToCopy);
  return result;
}

public static byte [ ] copyWithLength ( byte [ ] orig , int length ) { byte [ ] result = new byte [ length ] ; int howMuchToCopy = length < orig . length ? length : orig . length ; System . arraycopy ( orig , 0 , result , 0 , howMuchToCopy ) ; return result ; }
copies the original byte array content to a new byte array . the resulting byte array is always " length " size . if length is smaller than the original byte array , the resulting byte array is truncated . if length is bigger than the original byte array , the resulting byte array is filled with zero bytes .
