OSGi utility classes for bnd/bndtools - provides essential utility functionality for OSGi bundle analysis and manipulation
npx @tessl/cli install tessl/maven-biz-aqute-bnd--util@6.4.0OSGi utility classes for bnd/bndtools providing essential utility functionality for OSGi bundle analysis and manipulation. This library contains comprehensive APIs for Java class file processing, functional programming patterns, stream operations, and immutable data structures optimized for OSGi development environments.
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bnd.util</artifactId>
<version>6.4.1</version>
</dependency>// Java class file processing
import aQute.bnd.classfile.ClassFile;
import aQute.bnd.classfile.ConstantPool;
import aQute.bnd.classfile.MethodInfo;
import aQute.bnd.classfile.FieldInfo;
// Memoization utilities
import aQute.bnd.memoize.Memoize;
import aQute.bnd.memoize.CloseableMemoize;
// Result type for error handling
import aQute.bnd.result.Result;
// Stream utilities
import aQute.bnd.stream.MapStream;
// Immutable collections
import aQute.bnd.unmodifiable.Lists;
import aQute.bnd.unmodifiable.Maps;
import aQute.bnd.unmodifiable.Sets;
// Signature processing
import aQute.bnd.signatures.ClassSignature;
import aQute.bnd.signatures.MethodSignature;import aQute.bnd.classfile.ClassFile;
import aQute.bnd.result.Result;
import aQute.bnd.memoize.Memoize;
import aQute.bnd.unmodifiable.Lists;
// Parse a Java class file
try (DataInputStream in = new DataInputStream(Files.newInputStream(classPath))) {
ClassFile classFile = ClassFile.parseClassFile(in);
System.out.println("Class: " + classFile.this_class);
System.out.println("Super: " + classFile.super_class);
}
// Use Result type for error handling
Result<String> result = processData("input");
if (result.isOk()) {
System.out.println("Success: " + result.value());
} else {
System.err.println("Error: " + result.error());
}
// Create immutable collections
List<String> immutableList = Lists.of("alpha", "beta", "gamma");
Map<String, Integer> immutableMap = Maps.of("key1", 1, "key2", 2);
// Use memoization for expensive operations
Memoize<String> expensiveComputation = Memoize.supplier(() -> {
// Expensive computation here
return "computed result";
});
String result1 = expensiveComputation.get(); // Computes
String result2 = expensiveComputation.get(); // Returns cached resultThe biz.aQute.bnd.util library is organized into eight main functional areas:
Complete Java class file parsing, analysis, and manipulation capabilities for OSGi bundle tooling. Supports all class file attributes, constant pool operations, and bytecode analysis.
public static ClassFile parseClassFile(DataInput in) throws IOException;
public class ClassFile extends ElementInfo {
public final int minor_version;
public final int major_version;
public final ConstantPool constant_pool;
public final String this_class;
public final String super_class;
public final String[] interfaces;
public final FieldInfo[] fields;
public final MethodInfo[] methods;
}
public class ConstantPool {
public int size();
public Object entry(int index);
public String utf8(int index);
public String className(int index);
}Fluent builder patterns for constructing Java class files programmatically with full type safety and validation.
public class ClassFileBuilder {
public ClassFileBuilder minor_version(int version);
public ClassFileBuilder major_version(int version);
public ClassFileBuilder this_class(String className);
public ClassFileBuilder super_class(String superClass);
public ClassFile build();
}
public class MutableConstantPool extends ConstantPool {
public MutableConstantPool();
public <T> T add(Class<T> type, Supplier<T> supplier);
}Thread-safe memoization utilities for caching expensive computations with configurable eviction policies and resource management.
public interface Memoize<S> extends Supplier<S> {
static <T> Memoize<T> supplier(Supplier<? extends T> supplier);
static <T> Memoize<T> refreshingSupplier(Supplier<? extends T> supplier, long duration, TimeUnit unit);
S get();
Optional<S> peek();
boolean isPresent();
<R> Memoize<R> map(Function<? super S, ? extends R> mapper);
}
public interface CloseableMemoize<S extends AutoCloseable> extends Memoize<S>, AutoCloseable {
static <T extends AutoCloseable> CloseableMemoize<T> closeableSupplier(Supplier<? extends T> supplier);
boolean isClosed();
}Monadic error handling similar to Rust's Result type, providing safe and composable error management without exceptions.
public interface Result<V> {
static <T> Result<T> ok(T value);
static <T> Result<T> err(CharSequence error);
boolean isOk();
boolean isErr();
V value();
String error();
V unwrap();
<U> Result<U> map(FunctionWithException<? super V, ? extends U> mapper);
<U> Result<U> flatMap(FunctionWithException<? super V, ? extends Result<? extends U>> mapper);
V orElse(V defaultValue);
}Comprehensive processing and analysis of Java generic type signatures for advanced type introspection and OSGi metadata generation.
public interface Signature {
Set<String> erasedBinaryReferences();
}
public class ClassSignature implements Signature {
public static ClassSignature of(String signature);
public final TypeParameter[] typeParameters;
public final ClassTypeSignature superClass;
public final ClassTypeSignature[] superInterfaces;
}
public class MethodSignature implements Signature {
public final TypeParameter[] typeParameters;
public final JavaTypeSignature[] parameters;
public final JavaTypeSignature returnType;
public final ThrowsSignature[] exceptions;
}Map-specialized stream operations extending Java 8 streams with fluent APIs for key-value pair processing and transformations.
public interface MapStream<K, V> extends BaseStream<Map.Entry<K, V>, MapStream<K, V>> {
static <K, V> MapStream<K, V> of(Map<? extends K, ? extends V> map);
static <K, V> MapStream<K, V> empty();
Stream<Map.Entry<K, V>> entries();
Stream<K> keys();
Stream<V> values();
<R> MapStream<K, R> mapValue(Function<? super V, ? extends R> mapper);
<R> MapStream<R, V> mapKey(Function<? super K, ? extends R> mapper);
MapStream<K, V> filterKey(Predicate<? super K> predicate);
MapStream<K, V> filterValue(Predicate<? super V> predicate);
}Thread-safe, unmodifiable collection implementations with factory methods compatible with Java 9+ collection APIs but available for earlier Java versions.
public final class Lists {
public static <E> List<E> of();
public static <E> List<E> of(E element);
public static <E> List<E> of(E... elements);
public static <E> List<E> copyOf(Collection<? extends E> collection);
}
public final class Maps {
public static <K, V> Map<K, V> of();
public static <K, V> Map<K, V> of(K key, V value);
public static <K, V> Map<K, V> copyOf(Map<? extends K, ? extends V> map);
public static <K, V> Map.Entry<K, V> entry(K key, V value);
}
public final class Sets {
public static <E> Set<E> of();
public static <E> Set<E> of(E element);
public static <E> Set<E> of(E... elements);
public static <E> Set<E> copyOf(Collection<? extends E> collection);
}Support for experimental and preview-level Java class file features, enabling forward compatibility with future Java versions.