Writes the package parts to a zip archive.
 @param [Zip::OutputStream] zip
 @return [Zip::OutputStream]
439716
def write_parts(zip)
      p = parts
      p.each do |part|
        unless part[:doc].nil?
          zip.put_next_entry(zip_entry_for_part(part))
          part[:doc].to_xml_string(zip)
        end
        unless part[:path].nil?
          zip.put_next_entry(zip_entry_for_part(part))
          zip.write IO.read(part[:path])
        end
      end
      zip
    end
609780
private synchronized static void unzip(InputStream zipFileInputStream, String destinationDir) throws IOException {
        // Create output directory if it doesn't exist
        File dir = new File(destinationDir);
        if (!dir.exists()) dir.mkdirs();

        // Buffer for read and write data to file
        byte[] buffer = new byte[1024];
        ZipInputStream zis = new ZipInputStream(zipFileInputStream);
        ZipEntry ze = zis.getNextEntry();
        while (ze != null) {
            String fileName = ze.getName();
            File newFile = new File(destinationDir + File.separator + fileName);

            // Check if it's a Directory entry
            if (ze.isDirectory()) {
                newFile.mkdirs();
            } else {
                // Save file to disk
                FileOutputStream fos = new FileOutputStream(newFile);
                int len;
                while ((len = zis.read(buffer)) > 0) {
                    fos.write(buffer, 0, len);
                }
                fos.close();
            }

            // Close current entry and move to next entry
            zis.closeEntry();
            ze = zis.getNextEntry();
        }

        // Close last entry
        zis.closeEntry();
        zis.close();
    }
265624
def extract
      Zip::File.open(package_file) do |zip|
        batch_size = [1, (zip.size / 100).to_i].max
        dots = 0
        zip.each do |file|
          @output.print "." if (dots % batch_size).zero?
          file.restore_permissions = true
          file.extract { accept_all }
          dots += 1
        end
      end
    end
816841
public static void zip(File destination, File[] source)
            throws FileNotFoundException, IOException {
        FileOutputStream dest = new FileOutputStream(destination);
        ZipOutputStream zout =
                new ZipOutputStream(new BufferedOutputStream(dest));
        for (File element : source) {
            zip(null, element, zout);
        }
        zout.close();
    }
107047
def files
      if File.directory?(@package)
        Dir.glob(File.join(File.join(File.expand_path(@package), '**'), '*')).reject {|f|
          File.directory?(f) }.map {|f| f.sub(/^#{File.expand_path(@package)}\/?/, '') }
      else
        entries = []
        Zip::ZipFile::foreach(@package) do |entry|
          entries << entry.name unless entry.name[-1..-1] == '/'
        end
        entries
      end
    end
1004996
def stream
      stream = Zip::OutputStream.write_buffer { |zipstream|
        self.rels_hash = {}
        self.relationship_container.owner = self
        collect_related_objects.compact.each { |obj|
          puts "<-- DEBUG: adding relationship to #{obj.class}" if @@debug
          obj.root = self if obj.respond_to?(:root=)
          self.rels_hash[obj.class] ||= []
          self.rels_hash[obj.class] << obj
        }

        self.rels_hash.keys.sort_by{ |c| c::SAVE_ORDER }.each { |klass|
          puts "<-- DEBUG: saving related #{klass} files" if @@debug
          self.rels_hash[klass].select! { |obj|
            puts "<-- DEBUG:   > #{obj.xlsx_path}" if @@debug
            obj.add_to_zip(zipstream)
          }
        }
      }
      stream.rewind
      stream
    end
1326570
def write(key_hash, value)
      return value if value.nil? || value.empty?
      File.open(key_path(key_hash), 'wb') do |f|
        Marshal.dump(value, f)
      end

      value
    end
70437
def zip(zipfile_name)
      return unless zipfile_name
      zipfile_name += '.zip' unless zipfile_name.end_with? '.zip'

      Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
        selected_items.each do |item|
          next if item.symlink?
          if item.directory?
            Dir[item.join('**/**')].each do |file|
              zipfile.add file.sub("#{current_dir}/", ''), file
            end
          else
            zipfile.add item.name, item
          end
        end
      end
      ls
    end
713562
def save(path)
      update
      Zip::OutputStream.open(path) do |out|
        zip.each do |entry|
          next unless entry.file?
          out.put_next_entry(entry.name)

          if @replace[entry.name]
            out.write(@replace[entry.name])
          else
            out.write(zip.read(entry.name))
          end
        end
      end
      zip.close
    end
1353948
public static byte[] zip(List<String> fileNames, List<byte[]> fileContents) throws IOException {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        // Create the ZIP file
        ZipOutputStream out = new ZipOutputStream(baos);

        for (int i=0, size=fileNames.size(); i<size; i++) {
            String name = fileNames.get(i);
            byte[] content = fileContents.get(i);

            // Add ZIP entry to output stream.
            ZipEntry entry = new ZipEntry(name);
            entry.setSize(content.length);            
            out.putNextEntry(entry);
            out.write(content);
            // Complete the entry
            out.closeEntry();
        }
        out.close();
        return baos.toByteArray();
    }
1043818
def WriteFileChunk(self, chunk):
    """"""
    precondition.AssertType(chunk, bytes)

    if not self._stream:
      raise ArchiveAlreadyClosedError(
          "Attempting to write to a ZIP archive that was already closed.")

    self.cur_file_size += len(chunk)
    # TODO(user):pytype: crc32 is not visible outside of zipfile.
    # pytype: disable=module-attr
    self.cur_crc = zipfile.crc32(chunk, self.cur_crc) & 0xffffffff
    # pytype: enable=module-attr

    if self.cur_cmpr:
      chunk = self.cur_cmpr.compress(chunk)
      self.cur_compress_size += len(chunk)

    self._stream.write(chunk)
    return self._stream.GetValueAndReset()
905099
def zip
      return nil unless zip5 && !zip5.empty?
      [zip5, zip4].select { |z| z && !z.empty? }.join('-')
    end
1229735
def get_contents_from_zip zip_file
        contents = {}
        Zip::File.open(zip_file) do |zip|
          zip.each_entry do |entry|
            entry.get_input_stream do |entryfile|
              contents[entry.name] = entryfile.read
            end
          end
        end
        return contents
      end
148688
private void zipDir(String dir2zip, ZipOutputStream zos) throws IOException
  {
    try
    {
      //create a new File object based on the directory we have to zip.
      File zipDir = new File(dir2zip);
      //get a listing of the directory content
      String[] dirList = zipDir.list();
      byte[] readBuffer = new byte[4096];
      int bytesIn = 0;
      //loop through dirList, and zip the files
      for(int i=0; i<dirList.length; i++)
      {
        File f = new File(zipDir, dirList[i]);
        if(f.isDirectory())
        {
          //if the File object is a directory, call this
          //function again to add its content recursively
          String filePath = f.getPath();
          zipDir(filePath, zos);
          //loop again
          continue;
        }
        //if we reached here, the File object f was not a directory
        //create a FileInputStream on top of f
        FileInputStream fis = new FileInputStream(f);
        // create a new zip entry
        ZipEntry anEntry = new ZipEntry(f.getPath());
        anEntry.setTime(f.lastModified());
        //place the zip entry in the ZipOutputStream object
        zos.putNextEntry(anEntry);
        //now write the content of the file to the ZipOutputStream

        boolean stopEarlyBecauseTooMuchData = false;
        while((bytesIn = fis.read(readBuffer)) != -1)
        {
          zos.write(readBuffer, 0, bytesIn);
          if (baos.size() > MAX_SIZE) {
            stopEarlyBecauseTooMuchData = true;
            break;
          }
        }
        //close the Stream
        fis.close();
        zos.closeEntry();

        if (stopEarlyBecauseTooMuchData) {
          Log.warn("LogCollectorTask stopEarlyBecauseTooMuchData");
          break;
        }
      }
    }
    catch(Exception e)
    {
      //handle exception
    }
  }
1325000
def cache(package, extension, contents, output_dir, suffix=nil, mtime=nil)
      FileUtils.mkdir_p(output_dir) unless File.exists?(output_dir)
      raise OutputNotWritable, "Jammit doesn't have permission to write to \"#{output_dir}\"" unless File.writable?(output_dir)
      mtime ||= latest_mtime package_for(package, extension.to_sym)[:paths]
      files = []
      files << file_name = File.join(output_dir, Jammit.filename(package, extension, suffix))
      File.open(file_name, 'wb+') {|f| f.write(contents) }
      if Jammit.gzip_assets
        files << zip_name = "#{file_name}.gz"
        Zlib::GzipWriter.open(zip_name, Zlib::BEST_COMPRESSION) {|f| f.write(contents) }
      end
      File.utime(mtime, mtime, *files)
    end
961840
public static void mapZipFile(final byte[] zipFile, final Map<String, byte[]> output, final String keyPrefix,
            final String keyUnPrefix) {
        try {
            final String fixedKeyPrefix = keyPrefix == null ? "" : keyPrefix;
            final String fixedKeyUnPrefix = keyUnPrefix == null ? "" : keyUnPrefix;
            final ZipInputStream zf = new ZipInputStream(new ByteArrayInputStream(zipFile));

            ZipEntry ze = null;
            while ((ze = zf.getNextEntry()) != null) {
                final String name = ze.getName();
                final long size = ze.getSize();

                // see if we are working with a file or a directory
                if (size != 0) {
                    byte[] fileContents = new byte[0];
                    final byte[] fileBuffer = new byte[BUFFER_SIZE];

                    int bytesRead = 0;
                    while ((bytesRead = zf.read(fileBuffer, 0, BUFFER_SIZE)) != -1) fileContents = ArrayUtils.addAll(fileContents,
                            bytesRead == BUFFER_SIZE ? fileBuffer : ArrayUtils.subarray(fileBuffer, 0, bytesRead));

                    output.put(fixedKeyPrefix + name.replace(fixedKeyUnPrefix, ""), fileContents);
                }
            }

        } catch (final IOException ex) {
           LOG.error("Unable to read file contents", ex);
        }
    }
793032
def puts_rack_output
      return unless File.exist?(JETS_OUTPUT)
      puts IO.readlines(JETS_OUTPUT)
      File.truncate(JETS_OUTPUT, 0)
    end