Get the auto generated DDL from the catalog jar.

@param jarfile in-memory catalog jar file
@return Auto generated DDL stored in catalog.jar
@throws IOException If the catalog or the auto generated ddl cannot be loaded.
519278
public static String getAutoGenDDLFromJar(InMemoryJarfile jarfile)
            throws IOException
    {
        // Read the raw auto generated ddl bytes.
        byte[] ddlBytes = jarfile.get(VoltCompiler.AUTOGEN_DDL_FILE_NAME);
        if (ddlBytes == null) {
            throw new IOException("Auto generated schema DDL not found - please make sure the database is initialized with valid schema.");
        }
        String ddl = new String(ddlBytes, StandardCharsets.UTF_8);
        return ddl.trim();
    }
1368655
public static URL[] getLibJars(Configuration conf) throws IOException {
    String jars = conf.get("tmpjars");
    if(jars==null) {
      return null;
    }
    String[] files = jars.split(",");
    URL[] cp = new URL[files.length];
    for (int i=0;i<cp.length;i++) {
      Path tmp = new Path(files[i]);
      cp[i] = FileSystem.getLocal(conf).pathToFile(tmp).toURI().toURL();
    }
    return cp;
  }
445265
public static String findSingleMainClass(JarFile jarFile, String classesLocation)
            throws IOException {
        MainClassesCallback callback = new MainClassesCallback();
        MainClassFinder.doWithMainClasses(jarFile, classesLocation, callback);
        return callback.getMainClass();
    }
100177
public boolean compileDDLString(String ddl, String jarPath) {
        final File schemaFile = VoltProjectBuilder.writeStringToTempFile(ddl);
        schemaFile.deleteOnExit();
        final String schemaPath = schemaFile.getPath();

        return compileFromDDL(jarPath, schemaPath);
    }
28477
public static synchronized File getJarResources()
    {
        if (!loader.isPresent())
        {
            throw new LionEngineException(JAR_LOADER_ERROR);
        }

        final Media media = Medias.create(Constant.EMPTY_STRING);
        final String path = media.getFile().getPath().replace(File.separator, Constant.SLASH);
        final String prefix = loader.get().getPackage().getName().replace(Constant.DOT, Constant.SLASH);
        final int jarSeparatorIndex = path.indexOf(prefix);
        final String jar = path.substring(0, jarSeparatorIndex);

        return new File(jar);
    }
983469
public final void findCallingMethodsInJar(final File file) throws IOException {

        try (final JarFile jarFile = new JarFile(file)) {

            final Enumeration<JarEntry> entries = jarFile.entries();

            while (entries.hasMoreElements()) {
                final JarEntry entry = entries.nextElement();

                if (entry.getName().endsWith(".class")) {
                    final InputStream in = new BufferedInputStream(jarFile.getInputStream(entry), 1024);
                    try {
                        new ClassReader(in).accept(cv, 0);
                    } finally {
                        in.close();
                    }
                }
            }

        }
    }
1211633
private File getJarPath() {
        String decodedPath = ".";
        String jarPath = "";
        final ProtectionDomain domain = Settings.class.getProtectionDomain();
        if (domain != null && domain.getCodeSource() != null && domain.getCodeSource().getLocation() != null) {
            jarPath = Settings.class.getProtectionDomain().getCodeSource().getLocation().getPath();
        }
        try {
            decodedPath = URLDecoder.decode(jarPath, StandardCharsets.UTF_8.name());
        } catch (UnsupportedEncodingException ex) {
            LOGGER.trace("", ex);
        }

        final File path = new File(decodedPath);
        if (path.getName().toLowerCase().endsWith(".jar")) {
            return path.getParentFile();
        } else {
            return new File(".");
        }
    }
866604
private String getHalDocsDomainPath(ZipFile jarFile) throws IOException {
    ZipEntry manifestEntry = jarFile.getEntry("META-INF/MANIFEST.MF");
    if (manifestEntry != null) {
      try (InputStream is = jarFile.getInputStream(manifestEntry)) {
        Manifest manifest = new Manifest(is);
        return manifest.getMainAttributes().getValue(JsonSchemaBundleTracker.HEADER_DOMAIN_PATH);
      }
    }
    return null;
  }
622028
public static String getJarHome(Object o)
    {
        String path = o.getClass().getProtectionDomain()
                    .getCodeSource().getLocation().getFile();
        File jarFile = new File(path);
        return jarFile.getParentFile().getAbsolutePath();
    }
773530
protected String getExecutableJar() throws IOException {
        Manifest manifest = new Manifest();
        manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
        manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, MAIN);
        manifest.getMainAttributes().put(Attributes.Name.CLASS_PATH, getClasspath());

        Path jar = createTempDirectory("exec").resolve("generate.jar");
        try (JarOutputStream output = new JarOutputStream(Files.newOutputStream(jar), manifest)) {
            output.putNextEntry(new JarEntry("allure.properties"));
            Path allureConfig = PROPERTIES.getAllureConfig();
            if (Files.exists(allureConfig)) {
                byte[] bytes = Files.readAllBytes(allureConfig);
                output.write(bytes);
            }
            output.closeEntry();
        }

        return jar.toAbsolutePath().toString();
    }
341932
public void setJarFile(IPath jarFile) {
		if (!Objects.equal(jarFile, this.jarFile)) {
			final PropertyChangeEvent event = new PropertyChangeEvent(this, ISREInstallChangedListener.PROPERTY_JAR_FILE,
					this.jarFile, jarFile);
			this.jarFile = jarFile;
			setDirty(true);
			if (getNotify()) {
				SARLRuntime.fireSREChanged(event);
			}
		}
	}
1098455
private void loadJar(final JarFileInfo jarFileInfo) {
        final String JAR_SUFFIX = ".jar";

        jarFiles.add(jarFileInfo);
        jarFileInfo.getJarFile()
                .stream()
                .parallel()
                .filter(je -> !je.isDirectory() && je.getName().toLowerCase().endsWith(JAR_SUFFIX))
                .forEach(je -> {
                    try {
                        JarEntryInfo jarEntryInfo = new JarEntryInfo(jarFileInfo, je);
                        File tempFile = createJarFile(jarEntryInfo);

                        debug(String.format("Loading inner JAR %s from temp file %s", jarEntryInfo.getJarEntry(), getFilenameForLog(tempFile)));

                        // Construct ProtectionDomain for this inner JAR:
                        URL url = tempFile.toURI().toURL();
                        ProtectionDomain pdParent = jarFileInfo.getProtectionDomain();
                        // 'csParent' is never null: top JAR has it, classloader creates it for child JAR:
                        CodeSource csParent = pdParent.getCodeSource();
                        Certificate[] certParent = csParent.getCertificates();
                        CodeSource csChild = certParent == null
                                ? new CodeSource(url, csParent.getCodeSigners())
                                : new CodeSource(url, certParent);
                        ProtectionDomain pdChild = new ProtectionDomain(csChild, pdParent.getPermissions(), pdParent.getClassLoader(), pdParent.getPrincipals());
                        loadJar(new JarFileInfo(new JarFile(tempFile), jarEntryInfo.getName(), jarFileInfo, pdChild, tempFile));
                    } catch (IOException e) {
                        throw new RuntimeException(String.format("Cannot load jar entries from jar %s", je.getName().toLowerCase()), e);
                    } catch (EeClassLoaderException e) {
                        throw new RuntimeException("ERROR on loading inner JAR: " + e.getMessageAll());
                    }
                });
    }
763248
public void writeEntries(JarFile jarFile) throws IOException {
        Enumeration<JarEntry> entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            JarEntry entry = entries.nextElement();
            ZipHeaderPeekInputStream inputStream = new ZipHeaderPeekInputStream(
                    jarFile.getInputStream(entry));
            try {
                if (inputStream.hasZipHeader() && entry.getMethod() != ZipEntry.STORED) {
                    new CrcAndSize(inputStream).setupStoredEntry(entry);
                    inputStream.close();
                    inputStream = new ZipHeaderPeekInputStream(
                            jarFile.getInputStream(entry));
                }
                EntryWriter entryWriter = new InputStreamEntryWriter(inputStream, true);
                writeEntry(entry, entryWriter);
            } finally {
                inputStream.close();
            }
        }
    }
1065758
public static void unJar(File jarFile, File toDir) throws IOException {
    JarFile jar = new JarFile(jarFile);
    try {
      Enumeration entries = jar.entries();
      while (entries.hasMoreElements()) {
        JarEntry entry = (JarEntry)entries.nextElement();
        if (!entry.isDirectory()) {
          InputStream in = jar.getInputStream(entry);
          try {
            File file = new File(toDir, entry.getName());
            if (!file.getParentFile().mkdirs()) {
              if (!file.getParentFile().isDirectory()) {
                throw new IOException("Mkdirs failed to create " + 
                                      file.getParentFile().toString());
              }
            }
            OutputStream out = new FileOutputStream(file);
            try {
              byte[] buffer = new byte[8192];
              int i;
              while ((i = in.read(buffer)) != -1) {
                out.write(buffer, 0, i);
              }
            } finally {
              out.close();
            }
          } finally {
            in.close();
          }
        }
      }
    } finally {
      jar.close();
    }
  }
253937
static private String getRequiredBundles(File file) throws IOException {
        JarFile jar = new JarFile(file);
        Attributes attr = jar.getManifest().getMainAttributes();
        jar.close();
        return attr.getValue("Require-Bundle");
    }
473592
public boolean compileFromDDL(final String jarOutputPath, final String... ddlFilePaths) {
        if (ddlFilePaths.length == 0) {
            compilerLog.error("At least one DDL file is required.");
            return false;
        }
        List<VoltCompilerReader> ddlReaderList;
        try {
            ddlReaderList = DDLPathsToReaderList(ddlFilePaths);
        }
        catch (VoltCompilerException e) {
            compilerLog.error("Unable to open DDL file.", e);
            return false;
        }
        return compileInternalToFile(jarOutputPath, null, null, ddlReaderList, null);
    }
939000
public static File getFile(String resourceOrFile, Class<?> cls,
            boolean deleteTmpOnExit) throws FileNotFoundException {
        try {

            // jar:file:/home/.../blue.jar!/path/to/file.xml
            URI uri = getURL(resourceOrFile, cls).toURI();
            String uriStr = uri.toString();
            if (uriStr.startsWith("jar")) {

                if (uriStr.endsWith("/")) {
                    throw new UnsupportedOperationException(
                            "cannot unjar directories, only files");
                }

                String jarPath = uriStr.substring(4, uriStr.indexOf("!"))
                        .replace("file:", "");
                String filePath = uriStr.substring(uriStr.indexOf("!") + 2);

                JarFile jarFile = new JarFile(jarPath);
                assert (jarFile.size() > 0) : "no jarFile at " + jarPath;

                Enumeration<JarEntry> entries = jarFile.entries();

                while (entries.hasMoreElements()) {

                    JarEntry jarEntry = entries.nextElement();
                    if (jarEntry.toString().equals(filePath)) {
                        InputStream input = jarFile.getInputStream(jarEntry);
                        assert (input != null) : "empty is for " + jarEntry;
                        return tmpFileFromStream(input, filePath,
                                deleteTmpOnExit);
                    }
                }
                assert (false) : "file" + filePath + " not found in " + jarPath;
                return null;
            } else {
                return new File(uri);
            }

        } catch (URISyntaxException e) {
            throw new FileNotFoundException(resourceOrFile);
        } catch (IOException e) {
            throw new FileNotFoundException(resourceOrFile);
        }
    }