code: private static void extractFile(ArchiveInputStream input, File destination,
              FilenameFilter filter, ArchiveEntry entry) throws ExtractionException {
          final File file = new File(destination, entry.getName());
          try {
              if (filter.accept(file.getParentFile(), file.getName())) {
                  final String destPath = destination.getCanonicalPath();
                  if (!file.getCanonicalPath().startsWith(destPath)) {
                      final String msg = String.format(
                              "Archive contains a file (%s) that would be extracted outside of the target directory.",
                              file.getAbsolutePath());
                      throw new ExtractionException(msg);
                  }
                  LOGGER.debug("Extracting '{}'", file.getPath());
                  createParentFile(file);
  
                  try (FileOutputStream fos = new FileOutputStream(file)) {
                      IOUtils.copy(input, fos);
                  } catch (FileNotFoundException ex) {
                      LOGGER.debug("", ex);
                      final String msg = String.format("Unable to find file '%s'.", file.getName());
                      throw new ExtractionException(msg, ex);
                  }
              }
          } catch (IOException ex) {
              LOGGER.debug("", ex);
              final String msg = String.format("IO Exception while parsing file '%s'.", file.getName());
              throw new ExtractionException(msg, ex);
          }
      }
docs: Extracts a file from an archive (input stream) and correctly builds the
  directory structure.
  
  @param input the archive input stream
  @param destination where to write the file
  @param filter the file filter to apply to the files being extracted
  @param entry the entry from the archive to extract
  @throws ExtractionException thrown if there is an error reading from the
  archive stream