Returns the zip entry for a file in the archive.
@param filename the file name
@return the zip entry for the file with the provided name
@throws ZipException thrown if the file is not in the zip archive
481646
protected ZipEntry getZipEntry(String filename) throws ZipException {

        // yes
        ZipEntry entry = getZipFile().getEntry(filename);
        // path to file might be relative, too
        if ((entry == null) && filename.startsWith("/")) {
            entry = m_zipFile.getEntry(filename.substring(1));
        }
        if (entry == null) {
            throw new ZipException(
                Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_FILE_NOT_FOUND_IN_ZIP_1, filename));
        }
        return entry;
    }
574644
public static void create(String zipFilename, String... filenames)
            throws IOException {

        try (FileSystem zipFileSystem = createZipFileSystem(zipFilename, true)) {
            final Path root = zipFileSystem.getPath("/");

            //iterate over the files we need to add
            for (String filename : filenames) {
                final Path src = Paths.get(filename);

                //add a file to the zip file system
                if(!Files.isDirectory(src)){
                    final Path dest = zipFileSystem.getPath(root.toString(),
                            src.toString());
                    final Path parent = dest.getParent();
                    if(Files.notExists(parent)){
                        if(logger.isDebugEnabled()) logger.debug("Creating directory %s", parent);
                        Files.createDirectories(parent);
                    }
                    Files.copy(src, dest, StandardCopyOption.REPLACE_EXISTING);
                }
                else{
                    //for directories, walk the file tree
                    Files.walkFileTree(src, new SimpleFileVisitor<Path>(){
                        @Override
                        public FileVisitResult visitFile(Path file,
                                                         BasicFileAttributes attrs) throws IOException {
                            final Path dest = zipFileSystem.getPath(root.toString(),
                                    file.toString());
                            Files.copy(file, dest, StandardCopyOption.REPLACE_EXISTING);
                            return FileVisitResult.CONTINUE;
                        }

                        @Override
                        public FileVisitResult preVisitDirectory(Path dir,
                                                                 BasicFileAttributes attrs) throws IOException {
                            final Path dirToCreate = zipFileSystem.getPath(root.toString(),
                                    dir.toString());
                            if(Files.notExists(dirToCreate)){
                                if(logger.isDebugEnabled()) logger.debug("Creating directory %s\n", dirToCreate);
                                Files.createDirectories(dirToCreate);
                            }
                            return FileVisitResult.CONTINUE;
                        }
                    });
                }
            }
        }
    }
210878
public function getFileData($fileName)
    {
        $data = $this->cab->getFileData($fileName);

        return new ArchiveEntry($fileName, $data->packedSize, $data->size, $data->unixtime, $data->is_compressed);
    }
875430
public static void extractFile(final ZipInputStream in, final File outdir, final String name) throws IOException {
        byte[] buffer = new byte[BUFFER_SIZE];
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(outdir, name)));
        int count = -1;
        while ((count = in.read(buffer)) != -1) {
            out.write(buffer, 0, count);
        }
        out.close();
    }
1073170
@GET
    @javax.ws.rs.Path("/zip/{path : .*}")
    @Produces("application/zip")
    public Response getDocumentsAsZip(
            @DefaultValue("") @PathParam ("path") final String  pathAsString,
                              @Context            final UriInfo uriInfo) throws IOException {

        final StreamingOutput streamingOutput = new StreamingOutput() {
            @Override
            public void write(OutputStream output) throws IOException, WebApplicationException {
                try {
                    final List<Path> list = documentHelper.list( pathAsString.length() == 0 ? get("/") : get(pathAsString));

                    try (ZipOutputStream zipOutputStream = new ZipOutputStream(new BufferedOutputStream(output))) {
                        zipOutputStream.setLevel(9);
                        for (Path path : list) {
                            Path relativized = documentHelper.relativize(path);

                            zipOutputStream.putNextEntry(new ZipEntry(relativized.toString()));

                            Serioulizer.Stream stream = documentHelper.getStream(relativized);
                            if (stream != null) {
                                pipe(stream.getInputStream(), zipOutputStream);
                            }
                            zipOutputStream.closeEntry();
                        }
                    }
                } catch (Exception e) {
                    throw new WebApplicationException(e);
                }
            }
        };

        String filenameWithoutExtension = Joiner.on('-')
                                                .skipNulls()
                                                .join( uriInfo.getBaseUri()
                                                              .getHost(),
                                                       "stnemucod",
                                                       Strings.emptyToNull( pathAsString.replace('/', ' ')
                                                                                        .replace('\\', ' ')
                                                                                        .trim()
                                                                                        .replace(' ', '_')));

        return ok(streamingOutput)
               .type("application/zip")
               .header("Content-Disposition",  "attachment; filename=\"" + filenameWithoutExtension + ".zip\"")
               .build();
    }
819436
public static boolean isZip(String fName)
  {
    if (Strings.isNullOrEmpty(fName)) {
      return false;
    }
    return fName.endsWith(ZIP_SUFFIX); // Technically a file named `.zip` would be fine
  }
736827
public String getStoredFile(String filename) {
        try {
            File stored = new File(temporaryStorage.toFile(), filename);

            if (!stored.exists()) {
                throw new CitrusRuntimeException("Failed to access stored file: " + stored.getCanonicalPath());
            }

            return stored.getCanonicalPath();
        } catch (IOException e) {
            throw new CitrusRuntimeException("Failed to retrieve file: " + filename, e);
        }
    }
315136
public static String getFileNameWithoutExtenxion(String fileName) {
		if (fileName==null){
			return null;
		} else {
			int number=fileName.lastIndexOf('.');
			
			if (number>=0){
				return fileName.substring(0, number);
			} else {
				return fileName;
			}
		}		
	}
409692
boolean archiveFile(File logFile) {

		FileOutputStream fOut;
		ZipOutputStream zOut;

		// necessary because of possible IOException
		try {
			fOut = new FileOutputStream(logFile.getPath() + ".zip");
			zOut = new ZipOutputStream(fOut);

			FileInputStream fIn = new FileInputStream(logFile);
			BufferedInputStream bIn = new BufferedInputStream(fIn);

			// new ZipEntry to put into the archive
			ZipEntry entry = new ZipEntry(logFile.getCanonicalFile().getName());
			zOut.putNextEntry(entry);

			// create a byte array
			byte[] barray = new byte[1024];
			// byte count variable
			int bytes;

			// read the BufferedInputStream and write it entirely to the archive
			while ((bytes = bIn.read(barray, 0, 1024)) > -1) {
				zOut.write(barray, 0, bytes);
			}

			// clean up
			zOut.flush();
			zOut.close();
			fOut.close();

			return true;

		} catch (IOException ioE) {
			return false;
		}

	}
604366
public static void zipCompress(String filename) throws IOException {
    FileOutputStream fos = new FileOutputStream(filename + COMPRESSION_SUFFIX);
    CheckedOutputStream csum = new CheckedOutputStream(fos, new CRC32());
    ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(csum));
    out.setComment("Failmon records.");

    BufferedReader in = new BufferedReader(new FileReader(filename));
    out.putNextEntry(new ZipEntry(new File(filename).getName()));
    int c;
    while ((c = in.read()) != -1)
      out.write(c);
    in.close();

    out.finish();
    out.close();
  }
68657
public boolean containsEntry(String name) {
    if (src == null) {
      throw new IllegalStateException("Source is not given");
    }
    return ZipUtil.containsEntry(src, name);
  }
1349179
public static Observable<String> getFileExtension(final String fileName) {
    return Observable.fromCallable(new Func0<String>() {
      @Override
      public String call() {
        return fileName.substring((fileName.lastIndexOf('.')) + 1);
      }
    });
  }
617403
public ZipFile getZipFile(final File file) throws IOException {
        try {
            if (System.getSecurityManager() == null)
                return new ZipFile(file);
            try {
                return AccessController.doPrivileged(new PrivilegedExceptionAction<ZipFile>() {
                    @Override
                    public ZipFile run() throws IOException {
                        return new ZipFile(file);
                    }
                }, controlContext);
            } catch (PrivilegedActionException e) {
                if (e.getException() instanceof IOException)
                    throw (IOException) e.getException();
                throw (RuntimeException) e.getException();
            }
        } catch (ZipException e) {
            ZipException zipNameException = new ZipException("Exception in opening zip file: " + file.getPath()); //$NON-NLS-1$
            zipNameException.initCause(e);
            throw zipNameException;
        } catch (IOException e) {
            throw new IOException("Exception in opening zip file: " + file.getPath(), e); //$NON-NLS-1$
        }
    }
860091
public static OutputStream getFileOutputStream(String filename) throws IOException {
    OutputStream out = new FileOutputStream(filename);
    if (filename.endsWith(".gz")) {
      out = new GZIPOutputStream(out);
    } else if (filename.endsWith(".bz2")) {
      //out = new CBZip2OutputStream(out);
      out = getBZip2PipedOutputStream(filename);
    }
    return out;
  }
565986
public static boolean isArchiveFileName(String fileName) {
        String extension = getExtension(fileName);
        return ARCHIVE_EXTENSION_SET.contains(extension);
    }
234784
public ZipFile getZipFile()
    throws IOException
  {
    isCacheValid();

    ZipFile zipFile = _zipFileRef.getAndSet(null);

    if (zipFile != null) {
      return zipFile;
    }

    if (_backingIsFile) {
      try {
        zipFile = new ZipFile(getBacking().getNativePath());

        /*
        if (_backing.getNativePath().indexOf("cssparser") >= 0) {
          System.out.println("ZIP: " + _backing.getNativePath() + " " + zipFile);
          Thread.dumpStack();
        }
        */
      }
      catch (IOException ex) {
        if (log.isLoggable(Level.FINE))
          log.log(Level.FINE, L.l("Error opening jar file '{0}'", getBacking().getNativePath()));

        throw ex;
      }

      getLastModifiedImpl();
    }

    return zipFile;
  }
466737
private byte[] getHeader(Entry entry) throws IOException {
        zipRandomFile.seek(entry.offset);
        byte[] header = new byte[30];
        zipRandomFile.readFully(header);
        if (get4ByteLittleEndian(header, 0) != 0x04034b50)
            throw new ZipException("corrupted zip file");
        if ((get2ByteLittleEndian(header, 6) & 1) != 0)
            throw new ZipException("encrypted zip file"); // offset 6 in the header of the ZipFileEntry
        return header;
    }