CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-eclipse-jetty--jetty-util

Comprehensive Java utility library providing infrastructure and helper classes for the Eclipse Jetty web server

Pending
Overview
Eval results
Files

resource-management.mddocs/

Resource Management

Unified resource management API supporting various resource types with automatic cleanup and efficient access patterns for files, memory, JARs, and URLs.

Capabilities

Resource Interface

Abstract resource representation providing unified access to different resource types.

/**
 * Abstract resource interface
 */
public interface Resource {
    /** Check if resource exists */
    boolean exists();
    
    /** Check if resource is directory */
    boolean isDirectory();
    
    /** Check if resource is file */
    boolean isFile();
    
    /** Get resource path */
    Path getPath();
    
    /** Get resource URI */
    URI getURI();
    
    /** Resolve sub-resource */
    Resource resolve(String subUriPath);
    
    /** Get input stream */
    InputStream newInputStream() throws IOException;
    
    /** Get file name */
    String getFileName();
    
    /** Get last modified time */
    Instant lastModified();
    
    /** Get resource length */
    long length();
    
    /** List directory contents */
    List<Resource> list();
}

ResourceFactory Interface

Factory for creating and managing resources.

/**
 * Resource factory interface
 */
public interface ResourceFactory {
    /** Create resource from URI or path string */
    Resource newResource(String uriOrPath);
    
    /** Create resource from Path */
    Resource newResource(Path path);
    
    /** Create resource from URI */
    Resource newResource(URI uri);
    
    /** Closeable resource factory */
    interface Closeable extends ResourceFactory, java.io.Closeable {
        // Factory that can be closed to release resources
    }
    
    /** Lifecycle-managed resource factory */
    interface LifeCycle extends ResourceFactory, org.eclipse.jetty.util.component.LifeCycle {
        // Factory with full lifecycle management
    }
}

Resource Implementations

/**
 * File system path-based resource
 */
public class PathResource implements Resource {
    /** Create path resource */
    public PathResource(Path path);
    
    /** Create path resource from file */
    public PathResource(File file);
}

/**
 * In-memory resource implementation
 */
public class MemoryResource implements Resource {
    /** Create memory resource from byte array */
    public MemoryResource(byte[] data);
    
    /** Create memory resource with name and data */
    public MemoryResource(String name, byte[] data);
}

/**
 * Combined resource from multiple sources
 */
public class CombinedResource implements Resource {
    /** Create combined resource */
    public CombinedResource(Resource... resources);
}

ResourceFactory Implementations

/**
 * Path-based resource factory
 */
public class PathResourceFactory implements ResourceFactory {
    /** Create factory */
    public PathResourceFactory();
}

/**
 * URL-based resource factory
 */
public class URLResourceFactory implements ResourceFactory {
    /** Create factory */
    public URLResourceFactory();
}

Usage Examples:

import org.eclipse.jetty.util.resource.*;

// Create resource factory
ResourceFactory factory = new PathResourceFactory();

// Create resources
Resource configFile = factory.newResource("/app/config/app.properties");
Resource webRoot = factory.newResource("/var/www/html");

// Check resource properties
if (configFile.exists() && configFile.isFile()) {
    try (InputStream input = configFile.newInputStream()) {
        Properties props = new Properties();
        props.load(input);
    }
}

// List directory contents
if (webRoot.isDirectory()) {
    for (Resource file : webRoot.list()) {
        System.out.println(file.getFileName() + " - " + file.length() + " bytes");
    }
}

// Resolve sub-resources
Resource indexFile = webRoot.resolve("index.html");
Resource cssDir = webRoot.resolve("css/");

Error Handling

Resource operations handle errors through:

  • IOException for I/O operations that fail
  • IllegalArgumentException for invalid paths or URIs
  • Graceful handling of missing resources (exists() returns false)
  • Automatic resource cleanup when using try-with-resources

Install with Tessl CLI

npx tessl i tessl/maven-org-eclipse-jetty--jetty-util

docs

async-operations.md

component-lifecycle.md

core-utilities.md

data-structures.md

index.md

resource-management.md

security.md

statistics.md

threading.md

tile.json