Gets a static resource from a plugin

@param pluginName - Name of the plugin(defined in the plugin manifest)
@param fileName - Filename to fetch
@return byte array of the resource
@throws Exception exception
335553
public byte[] getResource(String pluginName, String fileName) throws Exception {
        // TODO: This is going to be slow.. future improvement is to cache the data instead of searching all jars
        for (String jarFilename : jarInformation) {
            JarFile jarFile = new JarFile(new File(jarFilename));
            Enumeration<?> enumer = jarFile.entries();

            // Use the Plugin-Name manifest entry to match with the provided pluginName
            String jarPluginName = jarFile.getManifest().getMainAttributes().getValue("Plugin-Name");

            if (!jarPluginName.equals(pluginName)) {
                continue;
            }

            while (enumer.hasMoreElements()) {
                Object element = enumer.nextElement();
                String elementName = element.toString();

                // Skip items in the jar that don't start with "resources/"
                if (!elementName.startsWith("resources/")) {
                    continue;
                }

                elementName = elementName.replace("resources/", "");
                if (elementName.equals(fileName)) {
                    // get the file from the jar
                    ZipEntry ze = jarFile.getEntry(element.toString());

                    InputStream fileStream = jarFile.getInputStream(ze);
                    byte[] data = new byte[(int) ze.getSize()];
                    DataInputStream dataIs = new DataInputStream(fileStream);
                    dataIs.readFully(data);
                    dataIs.close();
                    return data;
                }
            }
        }
        throw new FileNotFoundException("Could not find resource");
    }
242746
static InputStream getFileAsStream(File resourceFile) throws ConfigurationException {
        try {
            return new FileInputStream(resourceFile);
        } catch (FileNotFoundException e) {
            Log.error("File Resource could not be resolved. Given Resource:" + resourceFile, e);
            throw new ConfigurationException("File Resource could not be resolve", FILE_NOT_FOUND_EXCEPTION_ID,e);
        }
    }
1056202
public static MediaType getFileMediaType(String fileName) {
        String extension = getUrlExtension(fileName);
        if (!MimeTypeMap.getSingleton().hasExtension(extension)) {
            return MediaType.APPLICATION_OCTET_STREAM;
        }

        String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        try {
            return MediaType.parseMediaType(mimeType);
        } catch (Exception e) {
            return MediaType.APPLICATION_OCTET_STREAM;
        }
    }
661094
public void loadClass(String className) throws Exception {
        ClassInformation classInfo = classInformation.get(className);

        logger.info("Loading plugin.: {}, {}", className, classInfo.pluginPath);

        // get URL for proxylib
        // need to load this also otherwise the annotations cannot be found later on
        File libFile = new File(proxyLibPath);
        URL libUrl = libFile.toURI().toURL();

        // store the last modified time of the plugin
        File pluginDirectoryFile = new File(classInfo.pluginPath);
        classInfo.lastModified = pluginDirectoryFile.lastModified();

        // load the plugin directory
        URL classURL = new File(classInfo.pluginPath).toURI().toURL();

        URL[] urls = new URL[] {classURL};
        URLClassLoader child = new URLClassLoader(urls, this.getClass().getClassLoader());

        // load the class
        Class<?> cls = child.loadClass(className);

        // put loaded class into classInfo
        classInfo.loadedClass = cls;
        classInfo.loaded = true;

        classInformation.put(className, classInfo);

        logger.info("Loaded plugin: {}, {} method(s)", cls.toString(), cls.getDeclaredMethods().length);
    }
75306
public static String loadFile(String filename) {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        InputStream is = classLoader.getResourceAsStream(filename);
        if (is == null) {
            throw new IllegalArgumentException("Unable to locate: " + filename);
        }
        return streamToString(is, filename);
    }
1363359
public String getDataImage(boolean forceUpdate, final Map<String, File> pluginFiles, String imageName)
            throws IOException, SettingsBuildingException, InterruptedException {
        String existedDataImage = null;

        final List<Image> images = getDockerCli().listImagesCmd()
                .withShowAll(true)
                .exec();
        OUTER:
        for (Image image : images) {
            final String[] repoTags = image.getRepoTags();
            if (nonNull(repoTags)) {
                for (String repoTag : repoTags) {
                    if (repoTag.equals(imageName)) {
                        existedDataImage = image.getId();
                        break OUTER;
                    }
                }
            }
        }

        if (nonNull(existedDataImage) && (forceUpdate || !isActualDataImage(pluginFiles, existedDataImage))) {
            LOG.info("Removing data-image.");
            //TODO https://github.com/docker-java/docker-java/issues/398
            getDockerCli().removeImageCmd(existedDataImage).withForce(true).exec();
            existedDataImage = null;
        }

        if (isNull(existedDataImage)) {
            LOG.debug("Preparing plugin files for");

//            final Set<Artifact> artifactResults = resolvePluginsFor(THIS_PLUGIN);
//            LOG.debug("Resolved plugins: {}", artifactResults);
////            System.out.println(artifactResults);
//            artifactResults.stream().forEach(artifact ->
//                            pluginFiles.put(
//                                    // {@link hudson.PluginManager.copyBundledPlugin()}
////                            artifact.getArtifactId() + "." + artifact.getExtension(),
//                                    artifact.getArtifactId() + ".jpi",
//                                    artifact.getFile()
//                            )
//            );
            existedDataImage = buildImage(pluginFiles);
        }

        return existedDataImage;
    }
693032
private static byte[] getData(String fileName, Object location) throws IOException {

		byte[] data;
		if (location instanceof String) {
			data = FileSupport.getBinaryFromJar(fileName, (String) location);
		} else if (location instanceof File) {
			InputStream in = new FileInputStream((File) location);
			data = StreamSupport.absorbInputStream(in);
			in.close();
		} else {
			throw new NoClassDefFoundError("file '" + fileName + "' could not be loaded from '" + location + '\'');
		}
		return data;
	}
1143185
public function getLoadedPlugin($name)
    {
        if (!isset($this->loadedPlugins[$name]) || is_null($this->loadedPlugins[$name])) {
            throw new \Exception("The plugin '$name' has not been loaded.");
        }
        return $this->loadedPlugins[$name];
    }
580941
public static OutputStream getOutputStreamFromFilename(String filename) {
        try {
            return new FileOutputStream(filename);
        } catch (FileNotFoundException e) {
            log.debug("Error initializing RdfStreamReader, file '{}' not found", filename);
            // do not handle exception at construction time
            return null;
        }
    }
1333671
public static InputStream getResourceAsStream(String resourceName) throws URISyntaxException,
            ClassNotFoundException {
        return ResourceUtil.class.getClassLoader().getResourceAsStream(resourceName);
    }
325310
public function getMetadata($pluginName, $key)
    {
        return isset($this->requestMetadata[$pluginName][$key]) ? $this->requestMetadata[$pluginName][$key] : null;
    }
1073242
public static InputStream getFileInputStream(String filename) throws IOException {
    InputStream in = new FileInputStream(filename);
    if (filename.endsWith(".gz")) {
      in = new GZIPInputStream(in);
    } else if (filename.endsWith(".bz2")) {
      //in = new CBZip2InputStream(in);
      in = getBZip2PipedInputStream(filename);
    }
    return in;
  }
565876
@Nullable
  public String getSourceFileName() {
    StaticSourceFile file = getStaticSourceFile();
    return file == null ? null : file.getName();
  }
874489
public function getDefaultInstanceConfig($pluginName)
    {
        $blockConfig = $this->blockConfigRepository->findById($pluginName);

        if (empty($blockConfig)) {
            throw new \Exception('Block config not found for ' . $pluginName); //@TODO throw custom exception class
        }

        return $blockConfig->getDefaultConfig();
    }
303833
private static String readClasspathResource(String filename) {
        InputStream is = CreateEntities.class.getResourceAsStream(filename);
        if (is == null) {
            throw new IllegalArgumentException(
                    "Could not find the given file '" + filename + "' in the classpath.");
        }
        
        return readContents(is);
    }
1056751
public static function load( $fileName )
	{
		$file	= new FS_File_Reader( $fileName );
		if( !$file->exists() )
			throw new Exception( "File '".$fileName."' is not existing." );
		$xml	= $file->readString();
		$parser	= new XML_OPML_Parser();
		return $parser->parse( $xml );
	}
408575
public static function get_plugin_directory($plugintype, $pluginname) {
        if (empty($pluginname)) {
            // Invalid plugin name, sorry.
            return null;
        }

        self::init();

        if (!isset(self::$plugins[$plugintype][$pluginname])) {
            return null;
        }
        return self::$plugins[$plugintype][$pluginname];
    }