2. How to split array into array of arrays & join them back
public static ArrayList<byte[]>
{
if(bytes == null || bytes.length <= 0) return null;
int offset = 0;
ArrayList
while (offset < bytes.length)
{
byte[] outputBytes;
if(bytes.length - offset < size )
{
outputBytes = new byte[bytes.length - offset];
System.arraycopy(bytes, offset, outputBytes, 0, bytes.length - offset);
splittedByteArray.add(outputBytes);
break;
}
outputBytes = new byte[size];
System.arraycopy(bytes, offset, outputBytes, 0, size);
splittedByteArray.add(outputBytes);
offset += size ;
}
return splittedByteArray;
}
public static byte[] Join(ArrayList<byte[]> bytes)
{
if(bytes == null || bytes.size() <= 0) return null;
int finalByteSize = 0;
for(int index = 0; index < bytes.size(); index++)
{
finalByteSize += bytes.get(index).length;
}
byte[] outputBytes = new byte[finalByteSize];
int desPos = 0;
for(int index = 0; index < bytes.size(); index++)
{
byte[] data = bytes.get(index);
System.arraycopy(bytes.get(index), 0, outputBytes, desPos, data.length);
desPos += data.length;
}
return outputBytes;
}
3. ConvertToBase64 & ConvertFromBase64
public static ArrayList
{
if(byteArray == null || byteArray.isEmpty()) return null;
ArrayList
for(int index = 0; index < byteArray.size(); index++)
{
String base64encoded = new String(com.lowagie.text.pdf.codec.Base64.encodeBytes(byteArray.get(index)));
base64EncodedStrings.add(base64encoded);
}
return base64EncodedStrings;
}
public static ArrayList
{
if(base64encodedArray == null || base64encodedArray.isEmpty()) return null;
ArrayList
for(int index = 0; index < base64encodedArray.size(); index++)
{
byte[] base64decodedArray = com.lowagie.text.pdf.codec.Base64.decode(base64encodedArray.get(index));
base64decodedArrays.add(base64decodedArray);
}
return base64decodedArrays;
}
byte[] bytes = data.getBytes("US-ASCII");