CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-apache-tomcat-embed--tomcat-embed-core

Embedded Apache Tomcat servlet container with Jakarta Servlet API, HTTP connectors, and lifecycle management for Java web applications

Overview
Eval results
Files

utilities.mddocs/

Utility Classes

Comprehensive utility libraries for HTTP parsing, byte/character buffers, character encoding, networking, threading, URI encoding, MIME type handling, collections, and common operations used throughout Tomcat.

Capabilities

Byte Buffers

Efficient byte buffer management.

public final class ByteChunk implements Cloneable, Serializable {
    public ByteChunk();
    public ByteChunk(int initial);
    
    // Buffer management
    public void setBytes(byte[] b, int off, int len);
    public byte[] getBytes();
    public byte[] getBuffer();
    public int getStart();
    public void setStart(int start);
    public int getEnd();
    public void setEnd(int end);
    public int getLength();
    public void setLimit(int limit);
    public int getLimit();
    
    // Operations
    public void recycle();
    public void reset();
    public void allocate(int initial, int limit);
    public void append(byte b) throws IOException;
    public void append(ByteChunk src) throws IOException;
    public int subtract() throws IOException;
    public int subtract(byte[] dest, int off, int len) throws IOException;
    
    // Comparison
    public boolean equals(String s);
    public boolean equalsIgnoreCase(String s);
    public boolean startsWith(String s, int pos);
    public boolean startsWithIgnoreCase(String s, int pos);

    // Conversion
    public String toString();
    public String toStringInternal();
    public long getLong();
}

Character Buffers

Character buffer for efficient string handling.

public final class CharChunk implements Cloneable, Serializable {
    public CharChunk();
    public CharChunk(int initial);
    
    // Buffer management
    public void setChars(char[] c, int off, int len);
    public char[] getChars();
    public char[] getBuffer();
    public int getStart();
    public void setStart(int start);
    public int getEnd();
    public void setEnd(int end);
    public int getLength();
    
    // Operations
    public void recycle();
    public void reset();
    public void allocate(int initial, int limit);
    public void append(char b) throws IOException;
    public void append(CharChunk src) throws IOException;
    public void append(String s) throws IOException;
    public void append(String s, int off, int len) throws IOException;
    
    // Comparison
    public boolean equals(String s);
    public boolean equalsIgnoreCase(String s);
    public boolean startsWith(String s, int pos);
    public int indexOf(String src, int start);

    // Conversion
    public String toString();
    public String toStringInternal();
}

MessageBytes

Efficient representation of strings as bytes or chars.

public final class MessageBytes implements Cloneable, Serializable {
    // Type constants
    public static final int T_NULL = 0;
    public static final int T_STR = 1;
    public static final int T_BYTES = 2;
    public static final int T_CHARS = 3;
    
    public static MessageBytes newInstance();
    
    // Type management
    public int getType();
    public boolean isNull();
    
    // String operations
    public void setString(String s);
    public String getString();
    public String toString();
    public String toStringType();
    
    // Byte operations
    public ByteChunk getByteChunk();
    public void setBytes(byte[] b, int off, int len);
    
    // Char operations
    public CharChunk getCharChunk();
    public void setChars(char[] c, int off, int len);
    
    // Conversion
    public void toBytes();
    public void toChars();
    
    // Operations
    public void recycle();
    public void duplicate(MessageBytes src) throws IOException;
    
    // Comparison
    public boolean equals(String s);
    public boolean equalsIgnoreCase(String s);
    public boolean equals(MessageBytes mb);
    public boolean equals(byte[] b, int off, int len);
    public boolean equals(CharChunk cc);
    public boolean equals(char[] c, int off, int len);
    public boolean startsWithIgnoreCase(String s, int pos);
    public int indexOf(String s, int starting);
    public int indexOf(String s);

    // Numeric conversion
    public long getLong();
}

B2CConverter

Byte-to-character encoding conversion.

public class B2CConverter {
    public B2CConverter(Charset charset);
    public B2CConverter(String encoding) throws UnsupportedEncodingException;
    
    public void convert(ByteChunk bb, CharChunk cb) throws IOException;
    public void convert(ByteChunk bb, CharChunk cb, boolean endOfInput) throws IOException;
    
    public void recycle();
    
    public Charset getCharset();
}

HTTP Utilities

Utilities for parsing HTTP headers, cookies, and parameters.

// MIME headers management
public class MimeHeaders {
    public MimeHeaders();

    // Header management
    public void addValue(String name);
    public MessageBytes addValue(byte[] b, int startN, int len);
    public MessageBytes getValue(String name);
    public MessageBytes getUniqueValue(String name);
    public int size();
    public MessageBytes getName(int n);
    public MessageBytes getValue(int n);

    // Operations
    public void recycle();
    public void removeHeader(String name);
    public int findHeader(String name, int starting);

    // Iteration
    public Enumeration<String> names();
    public Enumeration<String> values(String name);
}

// Request parameters
public final class Parameters {
    public Parameters();

    // Parameter management
    public void addParameter(String name, String value);
    public String getParameter(String name);
    public Enumeration<String> getParameterNames();
    public String[] getParameterValues(String name);

    // Processing
    public void processParameters(MessageBytes data, Charset charset);
    public void processParameters(byte[] bytes, int start, int len);

    public void recycle();
    public void setLimit(int limit);
    public int getLimit();
}

// Cookie processing
public abstract class CookieProcessor {
    public abstract void parseCookieHeader(MimeHeaders headers, ServerCookies serverCookies);
    public abstract String generateHeader(Cookie cookie);
    public abstract String generateHeader(Cookie cookie, HttpServletRequest request);
}

public class Rfc6265CookieProcessor extends CookieProcessor {
    public Rfc6265CookieProcessor();

    public void parseCookieHeader(MimeHeaders headers, ServerCookies serverCookies);
    public String generateHeader(Cookie cookie);
    public String generateHeader(Cookie cookie, HttpServletRequest request);

    // Configuration
    public void setPartitioned(boolean partitioned);
    public boolean getPartitioned();
}

public class ServerCookie {
    // Cookie management
    public MessageBytes getName();
    public MessageBytes getValue();
    public void setVersion(int version);
    public int getVersion();
}

public class ServerCookies {
    public ServerCookies(int initialSize);

    public ServerCookie getCookie(int idx);
    public int getCookieCount();
    public void recycle();
}

// HTTP date formatting
public final class FastHttpDateFormat {
    public static long parseDate(String value);
    public static long parseDate(MessageBytes value);
    public static String formatDate(long value);
    public static String getCurrentDate();
}

// HTTP parsing
public class HttpParser {
    public static boolean isToken(int c);
    public static boolean isHex(int c);
    public static boolean isNotRequestTarget(int c);
    public static boolean isAbsolutePathRelaxed(int c);
    public static boolean isQueryRelaxed(int c);

    // Media type parsing
    public static String unquote(String input);
    public static String unquoteOnly(String input);
}

URI Utilities

URI encoding and decoding.

public final class UDecoder {
    public UDecoder();

    public void convert(ByteChunk mb) throws IOException;
    public void convert(ByteChunk mb, boolean query) throws IOException;
    public void convert(CharChunk mb) throws IOException;
    public void convert(CharChunk mb, boolean query) throws IOException;

    public void setAllowEncodedSlash(boolean allowEncodedSlash);
}

public final class UEncoder {
    public static final BitSet DEFAULT_ALLOWED;

    public UEncoder();
    public UEncoder(SafeCharsSet safeCharsSet);

    public void urlEncode(CharChunk cb, CharChunk out);
    public void urlEncode(String s, CharChunk out);
}

public final class UriUtil {
    public static boolean hasScheme(CharChunk uri);
    public static int getSchemeLength(String uri);
    public static String buildJarUrl(File jarFile) throws MalformedURLException;
    public static String buildJarUrl(File jarFile, String entryPath) throws MalformedURLException;
    public static String buildJarUrl(String fileUrlString) throws MalformedURLException;
    public static String buildJarUrl(String fileUrlString, String entryPath) throws MalformedURLException;
    public static URL buildJarSafeUrl(File file) throws MalformedURLException;
    public static String warToJar(String warUrl);
}

Security Utilities

Security-related utility classes.

// Concurrent message digest for thread-safe hashing
public class ConcurrentMessageDigest {
    public static byte[] digestMD5(byte[]... input);
    public static byte[] digestSHA1(byte[]... input);
    public static byte[] digest(String algorithm, byte[]... input);
    public static byte[] digest(String algorithm, int iterations, byte[]... input);
}

// MD5 encoding
public final class MD5Encoder {
    public static String encode(byte[] binaryData);
}

// Base64 encoding/decoding
public class Base64 {
    public Base64();
    public Base64(int lineLength);
    public Base64(int lineLength, byte[] lineSeparator);

    public static byte[] encodeBase64(byte[] binaryData);
    public static byte[] encodeBase64(byte[] binaryData, boolean isChunked);
    public static byte[] encodeBase64URLSafe(byte[] binaryData);
    public static byte[] decodeBase64(byte[] base64Data);
    public static byte[] decodeBase64(String base64String);
    public static boolean isBase64(byte[] octets);
    public static boolean isBase64(String base64);
}

// Escape utilities
public class Escape {
    public static String htmlElementContent(String content);
    public static String htmlElementContext(String context);
    public static String xml(String input);
    public static String xml(String org, String dest);
}

Threading Utilities

Thread pool and task management.

public class ThreadPoolExecutor extends java.util.concurrent.ThreadPoolExecutor {
    public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime,
                             TimeUnit unit, BlockingQueue<Runnable> workQueue,
                             ThreadFactory threadFactory);

    public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime,
                             TimeUnit unit, BlockingQueue<Runnable> workQueue,
                             RejectedExecutionHandler handler);

    public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime,
                             TimeUnit unit, BlockingQueue<Runnable> workQueue,
                             ThreadFactory threadFactory, RejectedExecutionHandler handler);

    // Tomcat-specific extensions
    public void contextStopping();
    public long getStopTimeout();
    public void setStopTimeout(long stopTimeout, TimeUnit timeUnit);
}

public class TaskQueue extends LinkedBlockingQueue<Runnable> {
    public TaskQueue();
    public TaskQueue(int capacity);

    public boolean offer(Runnable o);
    public boolean offer(Runnable o, long timeout, TimeUnit unit) throws InterruptedException;
    public boolean force(Runnable o);
    public boolean force(Runnable o, long timeout, TimeUnit unit) throws InterruptedException;

    public void setParent(ThreadPoolExecutor tp);
}

public class TaskThreadFactory implements ThreadFactory {
    public TaskThreadFactory(String namePrefix, boolean daemon, int priority);

    public Thread newThread(Runnable r);

    public String getNamePrefix();
    public void setNamePrefix(String namePrefix);
    public boolean isDaemon();
    public void setDaemon(boolean daemon);
    public int getPriority();
    public void setPriority(int priority);
}

public class VirtualThreadExecutor implements Executor {
    public VirtualThreadExecutor(String namePrefix);

    public void execute(Runnable command);

    public String getName();
}

JAR Scanning

Utilities for scanning JAR files for annotations and resources.

public interface JarScanner {
    void scan(JarScanType scanType, ServletContext context, JarScannerCallback callback);

    JarScanFilter getJarScanFilter();
    void setJarScanFilter(JarScanFilter jarScanFilter);
}

public interface JarScannerCallback {
    void scan(Jar jar, String webappPath, boolean isWebapp) throws IOException;
    void scan(File file, String webappPath, boolean isWebapp) throws IOException;
    void scanWebInfClasses() throws IOException;
}

public interface JarScanFilter {
    boolean check(JarScanType jarScanType, String jarName);
}

public class StandardJarScanner implements JarScanner {
    public StandardJarScanner();

    public void scan(JarScanType scanType, ServletContext context, JarScannerCallback callback);

    // Configuration
    public void setScanManifest(boolean scanManifest);
    public boolean isScanManifest();
    public void setScanAllFiles(boolean scanAllFiles);
    public boolean isScanAllFiles();
    public void setScanAllDirectories(boolean scanAllDirectories);
    public boolean isScanAllDirectories();
    public void setScanClassPath(boolean scanClassPath);
    public boolean isScanClassPath();
    public void setScanBootstrapClassPath(boolean scanBootstrapClassPath);
    public boolean isScanBootstrapClassPath();

    public JarScanFilter getJarScanFilter();
    public void setJarScanFilter(JarScanFilter jarScanFilter);
}

public class StandardJarScanFilter implements JarScanFilter {
    public StandardJarScanFilter();

    public boolean check(JarScanType jarScanType, String jarName);

    // Configuration
    public void setTldSkip(String tldSkip);
    public String getTldSkip();
    public void setTldScan(String tldScan);
    public String getTldScan();
    public void setPluggabilitySkip(String pluggabilitySkip);
    public String getPluggabilitySkip();
    public void setPluggabilityScan(String pluggabilityScan);
    public String getPluggabilityScan();
}

public enum JarScanType {
    TLD,
    PLUGGABILITY,
    OTHER
}

Instance Management

Object lifecycle and dependency injection support.

public interface InstanceManager {
    Object newInstance(Class<?> clazz) throws ReflectiveOperationException, NamingException;
    Object newInstance(String className) throws ReflectiveOperationException, NamingException;
    Object newInstance(String className, ClassLoader classLoader)
            throws ReflectiveOperationException, NamingException;

    void newInstance(Object o) throws ReflectiveOperationException, NamingException;

    void destroyInstance(Object o) throws ReflectiveOperationException;

    void backgroundProcess();
}

public class SimpleInstanceManager implements InstanceManager {
    public SimpleInstanceManager();

    public Object newInstance(Class<?> clazz) throws ReflectiveOperationException, NamingException;
    public Object newInstance(String className) throws ReflectiveOperationException, NamingException;
    public Object newInstance(String className, ClassLoader classLoader)
            throws ReflectiveOperationException, NamingException;

    public void newInstance(Object o) throws ReflectiveOperationException, NamingException;

    public void destroyInstance(Object o) throws ReflectiveOperationException;

    public void backgroundProcess();
}

String and Collection Utilities

// String utilities
public class StringUtils {
    public static String join(String[] array);
    public static String join(Collection<?> collection);
    public static String join(String[] array, char separator);
    public static String join(Collection<?> collection, char separator);
}

public final class Ascii {
    public static int toLower(int c);
    public static long parseLong(byte[] b, int off, int len) throws NumberFormatException;
}

public class HexUtils {
    public static int getDec(int index);
    public static byte getHex(int index);
    public static String toHexString(byte[] bytes);
    public static byte[] fromHexString(String input);
}

// Case insensitive maps
public class CaseInsensitiveKeyMap<V> extends HashMap<String,V> {
    public CaseInsensitiveKeyMap();
}

// Synchronized collections
public class SynchronizedQueue<T> {
    public SynchronizedQueue();
    public SynchronizedQueue(int initialSize);

    public boolean offer(T t);
    public T poll();
    public T poll(long timeout) throws InterruptedException;
    public int size();
    public void clear();
}

public class SynchronizedStack<T> {
    public SynchronizedStack();
    public SynchronizedStack(int size, int limit);

    public boolean push(T obj);
    public T pop();
    public int size();
    public void clear();
}

I/O and File Utilities

public class IOTools {
    public static void flow(InputStream is, OutputStream os) throws IOException;
    public static void flow(Reader reader, Writer writer) throws IOException;
    public static long flow(InputStream is, OutputStream os, byte[] buf) throws IOException;
    public static long flow(Reader reader, Writer writer, char[] buf) throws IOException;
}

public interface ConfigurationSource {
    Resource getResource(String name) throws IOException;
    URI getURI(String name);
}

public class ConfigFileLoader {
    public static InputStream getInputStream(String path) throws IOException;
    public static InputStream getSource(String path) throws IOException;
}

public final class Matcher {
    public static boolean matchName(String[] patternArray, String name, boolean caseSensitive);
    public static boolean match(String pattern, String input, boolean caseSensitive);
}

Usage Examples

Using MessageBytes

import org.apache.tomcat.util.buf.MessageBytes;
import org.apache.tomcat.util.buf.ByteChunk;

public class MessageBytesExample {
    public void processHeader() {
        MessageBytes mb = MessageBytes.newInstance();
        mb.setString("Content-Type");
        
        // Convert to bytes
        mb.toBytes();
        ByteChunk bc = mb.getByteChunk();
        
        System.out.println("Length: " + bc.getLength());
        System.out.println("Value: " + mb.toString());
        
        // Comparison
        if (mb.equalsIgnoreCase("content-type")) {
            System.out.println("Match found");
        }
        
        // Recycle for reuse
        mb.recycle();
    }
}

Install with Tessl CLI

npx tessl i tessl/maven-org-apache-tomcat-embed--tomcat-embed-core

docs

authentication.md

catalina-core.md

connectors.md

embedded-tomcat.md

index.md

logging.md

servlet-api.md

session-management.md

utilities.md

valves.md

web-resources.md

tile.json