code: private String copyFileToDisk(InputStream inputStream, String pathToExtractTo, String filename) throws IOException {
          if (!overwriteFilesThatExist) {
              File[] existingFiles = new File(pathToExtractTo).listFiles();
              if (null != existingFiles && existingFiles.length > 0) {
                  for (File existingFile : existingFiles) {
                      String existingFilename = existingFile.getName();
                      if (existingFilename.equals(filename)) {
                          LOG.info("Binary '" + existingFilename + "' exists: true");
                          LOG.info("Using existing '" + existingFilename + " 'binary.");
                          return existingFile.getAbsolutePath();
                      }
                  }
              }
          }
  
          File outputFile = new File(pathToExtractTo, filename);
          try {
              if (!outputFile.exists() && !outputFile.getParentFile().mkdirs() && !outputFile.createNewFile()) {
                  throw new IOException("Unable to create " + outputFile.getAbsolutePath());
              }
              LOG.info("Extracting binary '" + filename + "'...");
              FileUtils.copyInputStreamToFile(inputStream, outputFile);
              LOG.info("Binary copied to " + outputFile.getAbsolutePath());
              if (!outputFile.setExecutable(true) && !outputFile.canExecute()) {
                  LOG.warn("Unable to set executable flag (+x) on " + filename);
              }
          } finally {
              inputStream.close();
          }
  
          return outputFile.getAbsolutePath();
      }
docs: Copy a file from an inputsteam to disk
  
  @param inputStream     A valid input stream to read
  @param pathToExtractTo Path of the file we want to create
  @param filename        Filename of the file we want to create
  @return Absolute path of the newly created file (Or existing file if overwriteFilesThatExist is set to false)
  @throws IOException IOException