Java Code Examples for org.eclipse.jetty.util.resource.JarFileResource

Following code examples demonstrate how to use org.eclipse.jetty.util.resource.JarFileResource from jetty. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.eclipse.jetty.util.resource.JarFileResource and various code implementation of this class.

        }
        catch (final Exception ex)
        {
            throw new RuntimeException(ex);
        } 


    }

    private Path extractPackedFile( JarFileResource configResource )
        throws IOException
    {
        String uri = configResource.getURI().toASCIIString();
        int colon = uri.lastIndexOf(":");
        int bang_slash = uri.indexOf("!/");
        if (colon<0 || bang_slash<0 || colon>bang_slash)
            throw new IllegalArgumentException("Not resolved JarFile resource: "+uri);        
        String entry_path = uri.substring(colon+2).replace("!/","__").replace('/','_').replace('.','_');

        Path tmpDirectory = Files.createTempDirectory( "users_store" );
        tmpDirectory.toFile().deleteOnExit();
        Path extractedPath = Paths.get(tmpDirectory.toString(), entry_path);
        Files.deleteIfExists( extractedPath );
        extractedPath.toFile().deleteOnExit();
        IO.copy(configResource.getInputStream(),new FileOutputStream(extractedPath.toFile()));
        if (isHotReload())
        {
            LOG.warn("Cannot hot reload from packed configuration: {}",configResource);
            setHotReload(false);
        }
        return extractedPath;
    } 

    
    public void setConfig(String config)
    {
        if (config == null)
        {
            _configPath = null;
            return;
        }
        
        try
        {
            Resource configResource = Resource.newResource(config);
            
            if (configResource instanceof JarFileResource)
                _configPath = extractPackedFile((JarFileResource)configResource);
            else if (configResource instanceof PathResource)
                _configPath = ((PathResource)configResource).getPath();
            else if (configResource.getFile() != null)
                setConfigFile(configResource.getFile());
            else
                throw new IllegalArgumentException(config);
        }
        catch (Exception e)
        {
            _configPath = null;
            throw new IllegalStateException(e);
        }

    } 

Advertisement
Javadoc
------------------------------------------------------------
Advertisement