1 package org.jbpm.bytes; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.List ; 6 7 11 public abstract class ByteBlockChopper { 12 13 private static final int BLOCKSIZE = 1024; 14 15 public static List chopItUp(byte[] byteArray) { 16 List bytes = null; 17 if ( (byteArray!=null) 18 && (byteArray.length>0) ){ 19 bytes = new ArrayList (); 20 int index = 0; 21 while ( (byteArray.length-index) > BLOCKSIZE ) { 22 byte[] byteBlock = new byte[BLOCKSIZE]; 23 System.arraycopy(byteArray, index, byteBlock, 0, BLOCKSIZE); 24 bytes.add(byteBlock); 25 index+=BLOCKSIZE; 26 } 27 byte[] byteBlock = new byte[byteArray.length-index]; 28 System.arraycopy(byteArray, index, byteBlock, 0, byteArray.length-index); 29 bytes.add(byteBlock); 30 } 31 return bytes; 32 } 33 34 public static byte[] glueChopsBackTogether(List bytes) { 35 byte[] value = null; 36 37 if (bytes!=null) { 38 Iterator iter = bytes.iterator(); 39 while (iter.hasNext()) { 40 byte[] byteBlock = (byte[]) iter.next(); 41 if (value==null) { 42 value = byteBlock; 43 } else { 44 byte[] oldValue = value; 45 value = new byte[value.length+byteBlock.length]; 46 System.arraycopy(oldValue, 0, value, 0, oldValue.length); 47 System.arraycopy(byteBlock, 0, value, oldValue.length, byteBlock.length); 48 } 49 } 50 } 51 52 return value; 53 } 54 } 55 | Popular Tags |