Hi All,
The following are the steps i followed for a requirement of mine.
1) Obtained multiple byte arrays containing contents and packed them all inside an arraylist.These byte arrays are of the documents inside my Cabinet which were multiselected.
byte[] inOnclick;
ArrayList<byte[]> bcontainer = new ArrayList<byte[]>();
public void onClickSendToServices(Control control, ArgumentList args)
{
for( int k=0;k<vals.length;k++)
{
System.out.println("This is value of k " + k );
// Get ByteArray for each file and assign it into created ArrayList Object ABC
inOnclick = getContent(m_sessionManager,reponame,vals[k]);
// ArrayList.Add(ByteArray [i] file
bcontainer.add(inOnclick);
}
2) This Arraylist 'bcontainer' was then converted onto a byte array since i needed to zip this (collection of bytearray contents) and the zip functionality needed byte array as input parameter.
String tempStringFrmArrList ;
byte[] test;
tempStringFrmArrList = bcontainer.toString();
test = tempStringFrmArrList.getBytes();
3) Then i passed a filename and the above generated byte array 'test' onto a function zipping it by the call
byte[] collectzip;
String testfilename="TestFile.zip"
collectzip = zipBytes(testfilename,test);
4) This is the zipBytes function.
public static byte[] zipBytes(String filename,byte[] input) throws IOException { System.out.println("This is inside the zipBytes function"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(baos); ZipEntry entry = new ZipEntry(filename); entry.setSize(input.length); zos.putNextEntry(entry); zos.write(input); zos.closeEntry(); zos.close(); return baos.toByteArray(); }5) Now i want to unzip the byte array recieved post the zipping namely " collectzip" to emulate a subsequent functionality and here is my question.
How can i unzip this bytearray to iteratively list down each bytearray contained inside it. i.e. list out the contents i had packed into the ArrayList to ulimately save them as separate files in a folder inside the CMS?
Will the name of the zipfile "testfilename" suffice to obtain the individual contents inside them?
Looking forward for your valuable suggestions.
Thank You
Regards