Exemple #1
0
        private void saveStreamToZip(string name, System.IO.Stream data, java.util.zip.ZipOutputStream zos)
        {
            java.util.zip.ZipEntry ze = new java.util.zip.ZipEntry(name);
            zos.putNextEntry(ze);

            byte[] buffer = new byte[1024];
            int ReadBytes;
            while ((ReadBytes = data.Read(buffer, 0, 1024)) > 0)
                try
                {
                    byte[] b2 = new byte[ReadBytes];
                    for (int i = 0; i < ReadBytes; i++) b2[i] = (byte)buffer[i];
                    zos.write(b2, 0, ReadBytes);
                }
                catch (System.IO.IOException e) {
                    File.AppendAllText("log_SAve.txt", DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ": " + name + Environment.NewLine);
                    break;
                }

            zos.closeEntry();
        }
Exemple #2
0
        private bool AddToZip(java.io.FileOutputStream fos, java.util.zip.ZipOutputStream zos, string sourceFile, string destName)
        {
            try
            {

                Thread.Sleep(6000);
                java.io.FileInputStream fis = new java.io.FileInputStream(sourceFile);
                java.util.zip.ZipEntry ze = new java.util.zip.ZipEntry(destName);
                zos.putNextEntry(ze);

                byte[] buffer = new byte[1024];
                int len;
                while ((len = fis.read(buffer)) >= 0)
                {
                    zos.write(buffer, 0, len);
                }
                zos.closeEntry();
                fis.close();
            }
            catch (Exception)
            {
                File.AppendAllText("log_save.txt", DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ": " + sourceFile + Environment.NewLine);
                AddToZip( fos,  zos,  sourceFile,  destName);
            }

            return true;
        }