public boolean installPlugin( InputStream in, String pluginFilename )
    {
        if ( pluginFilename == null || pluginFilename.isEmpty() )
        {
            Log.error( "Error installing plugin: pluginFilename was null or empty." );
            return false;
        }
        if ( in == null )
        {
            Log.error( "Error installing plugin '{}': Input stream was null.", pluginFilename );
            return false;
        }

        try ( final BufferedInputStream bin = new BufferedInputStream( in ) )
        {
            // Check magic bytes to ensure this is a JAR file.
            final boolean magicNumberCheckEnabled = JiveGlobals.getBooleanProperty("plugins.upload.magic-number-check.enabled", true);
            if ( magicNumberCheckEnabled && ! validMagicNumbers( bin ) )
            {
                Log.error( "Error installing plugin '{}': This does not appear to be a JAR file (unable to find a magic byte match).", pluginFilename );
                return false;
            }

            // If pluginFilename is a path instead of a simple file name, we only want the file name
            pluginFilename = Paths.get(pluginFilename).getFileName().toString();
            // Absolute path to the plugin file
            Path absolutePath = pluginDirectory.resolve( pluginFilename );
            Path partFile = pluginDirectory.resolve( pluginFilename + ".part" );
            // Save input stream contents to a temp file
            Files.copy( bin, partFile, StandardCopyOption.REPLACE_EXISTING );

            // Check if zip file, else ZipException caught below.
            try (JarFile pluginJar = new JarFile(partFile.toFile())) {
                final boolean pluginXMLCheckEnabled = JiveGlobals.getBooleanProperty("plugins.upload.pluginxml-check.enabled", true);
                // Check if the zip file contains a plugin.xml file.
                if ( pluginXMLCheckEnabled && pluginJar.getEntry( "plugin.xml" ) == null ) {
                    Log.error( "Error installing plugin '{}': Unable to find 'plugin.xml' in archive.", pluginFilename );
                    Files.deleteIfExists( partFile );
                    return false;
                }
            } catch (ZipException e) {
                Log.error( "Error installing plugin '{}': Cannot parse file into a JAR format.", pluginFilename, e);
                Files.deleteIfExists(partFile);
                return false;
            }

            // Rename temp file to .jar
            Files.move( partFile, absolutePath, StandardCopyOption.REPLACE_EXISTING );
            // Ask the plugin monitor to update the plugin immediately.
            pluginMonitor.runNow( true );
        }
        catch ( IOException e )
        {
            Log.error( "An exception occurred while installing new version of plugin '{}':", pluginFilename, e );
            return false;
        }
        return true;
    }
Installs or updates an existing plugin.

@param in the input stream that contains the new plugin definition.
@param pluginFilename the filename of the plugin to create or update.
@return true if the plugin was successfully installed or updated.
xmppserver/src/main/java/org/jivesoftware/openfire/container/PluginManager.java