G
Guest
I am trying to make a minor modification to the code below and need some
assistance. Currently this code is using the java.util, java.util.zip, and
java.io assemblies from the vjslib.dll assembly. This code works fine by
taking file(s) from
disk and creating a zip file to disk. I need to modify this code to read a
file from a byte array and then output the zip file to a byte array (all done
in memory instead of disk). The reason for the byte array is that all the
files are being stored in the database in a BLOB field. Any assistance is
appreciated!
private static void Zip(string zipFileName, string[] sourceFile)
{
// TODO: this contains the file retrieved from the database.
Need to load this into the FileOutputStream.
byte[] ba = GetBlob(13); // getblob is a method that queries the DB
// this prepares a zip file for output to disk
FileOutputStream filOpStrm = new FileOutputStream(zipFileName);
ZipOutputStream zipOpStrm = new ZipOutputStream(filOpStrm);
FileInputStream filIpStrm = null;
foreach(string strFilName in sourceFile)
{
// load the file contents into a system.io.filestream
filIpStrm = new FileInputStream(strFilName);
ZipEntry ze = new ZipEntry(Path.GetFileName(strFilName));
zipOpStrm.putNextEntry(ze);
sbyte[] buffer = new sbyte[1024];
int len = 0;
while ((len = filIpStrm.read(buffer)) >= 0)
{
// this writes zip file to disk
//TODO: need to write this stream to a byte array instead of
disk, which I'll insert into the BLOB field.
zipOpStrm.write(buffer, 0, len);
}
}
zipOpStrm.closeEntry();
filIpStrm.close();
zipOpStrm.close();
filOpStrm.close();
}
assistance. Currently this code is using the java.util, java.util.zip, and
java.io assemblies from the vjslib.dll assembly. This code works fine by
taking file(s) from
disk and creating a zip file to disk. I need to modify this code to read a
file from a byte array and then output the zip file to a byte array (all done
in memory instead of disk). The reason for the byte array is that all the
files are being stored in the database in a BLOB field. Any assistance is
appreciated!
private static void Zip(string zipFileName, string[] sourceFile)
{
// TODO: this contains the file retrieved from the database.
Need to load this into the FileOutputStream.
byte[] ba = GetBlob(13); // getblob is a method that queries the DB
// this prepares a zip file for output to disk
FileOutputStream filOpStrm = new FileOutputStream(zipFileName);
ZipOutputStream zipOpStrm = new ZipOutputStream(filOpStrm);
FileInputStream filIpStrm = null;
foreach(string strFilName in sourceFile)
{
// load the file contents into a system.io.filestream
filIpStrm = new FileInputStream(strFilName);
ZipEntry ze = new ZipEntry(Path.GetFileName(strFilName));
zipOpStrm.putNextEntry(ze);
sbyte[] buffer = new sbyte[1024];
int len = 0;
while ((len = filIpStrm.read(buffer)) >= 0)
{
// this writes zip file to disk
//TODO: need to write this stream to a byte array instead of
disk, which I'll insert into the BLOB field.
zipOpStrm.write(buffer, 0, len);
}
}
zipOpStrm.closeEntry();
filIpStrm.close();
zipOpStrm.close();
filOpStrm.close();
}