ApackConfiguration is an immutable record that encapsulates all settings for APACK archive operations. It defines chunk size, compression, encryption, checksums, and format options.
public record ApackConfiguration(
int chunkSize,
ChecksumProvider checksumProvider,
CompressionProvider compressionProvider,
int compressionLevel,
EncryptionProvider encryptionProvider,
SecretKey encryptionKey,
EncryptionBlock encryptionBlock,
boolean enableRandomAccess,
boolean streamMode
)public static final ApackConfiguration DEFAULTThe default configuration provides:
| Setting | Default Value |
|---|---|
| Chunk Size | 256 KB |
| Checksum | XXH3-64 |
| Compression | None |
| Encryption | None |
| Random Access | Enabled |
| Stream Mode | Disabled |
Creates a new configuration builder.
public static Builder builder()Returns: A new builder with default values
Example:
ApackConfiguration config = ApackConfiguration.builder()
.chunkSize(128 * 1024)
.compression(CompressionRegistry.zstd(), 6)
.build();public int chunkSize()Returns the chunk size in bytes. Must be between MIN_CHUNK_SIZE (1 KB) and MAX_CHUNK_SIZE (64 MB).
public ChecksumProvider checksumProvider()Returns the checksum provider for data integrity verification.
public @Nullable CompressionProvider compressionProvider()Returns the compression provider, or null if compression is disabled.
public int compressionLevel()Returns the compression level. Interpretation depends on the provider.
public @Nullable EncryptionProvider encryptionProvider()Returns the encryption provider, or null if encryption is disabled.
public @Nullable SecretKey encryptionKey()Returns the encryption key, or null if encryption is disabled.
public @Nullable EncryptionBlock encryptionBlock()Returns the encryption metadata block containing KDF parameters.
public boolean enableRandomAccess()Returns true if random access (TOC) is enabled.
public boolean streamMode()Returns true if stream mode is enabled.
public boolean isCompressionEnabled()Returns true if a compression provider is configured.
public boolean isEncryptionEnabled()Returns true if both encryption provider and key are configured.
public ChunkProcessor createChunkProcessor()Creates a ChunkProcessor based on this configuration's compression and encryption settings.
Example:
ChunkProcessor processor = config.createChunkProcessor();
// Use processor for reading/writing chunksThe Builder class provides a fluent API for constructing configurations.
Sets the chunk size in bytes.
public Builder chunkSize(int chunkSize)Parameters:
chunkSize- Size in bytes (1 KB to 64 MB)
Example:
.chunkSize(512 * 1024) // 512 KBGuidelines:
| Use Case | Recommended Size |
|---|---|
| Random access priority | 16-64 KB |
| Balanced | 256 KB (default) |
| Compression priority | 512 KB - 1 MB |
| Large files | 1-4 MB |
Sets the checksum provider.
public Builder checksumProvider(ChecksumProvider provider)Parameters:
provider- Checksum implementation
Example:
.checksumProvider(ChecksumRegistry.crc32())Sets the checksum by algorithm name.
public Builder checksumAlgorithm(String algorithm)Parameters:
algorithm- Algorithm name ("xxh3-64", "crc32")
Throws: NoSuchElementException if algorithm not found
Enables compression with default level.
public Builder compression(CompressionProvider provider)Parameters:
provider- Compression implementation
Example:
.compression(CompressionRegistry.zstd())Enables compression with specific level.
public Builder compression(CompressionProvider provider, int level)Parameters:
provider- Compression implementationlevel- Compression level
Example:
.compression(CompressionRegistry.zstd(), 9) // High compression
.compression(CompressionRegistry.lz4(), 0) // Fast modeLevel Guidelines:
| Provider | Level Range | Speed | Ratio |
|---|---|---|---|
| ZSTD | 1-3 | Fast | Good |
| ZSTD | 4-6 | Balanced | Better |
| ZSTD | 7-22 | Slow | Best |
| LZ4 | 0 | Fastest | Lower |
| LZ4 | 1-17 | Slower | Better |
Sets compression level without changing provider.
public Builder compressionLevel(int level)Enables encryption with provider and key.
public Builder encryption(EncryptionProvider provider, SecretKey key)Parameters:
provider- Encryption implementationkey- Secret key for encryption
Example:
SecretKey key = aesProvider.generateKey();
.encryption(EncryptionRegistry.aes256Gcm(), key)Enables encryption with full metadata.
public Builder encryption(
EncryptionProvider provider,
SecretKey key,
EncryptionBlock block)Parameters:
provider- Encryption implementationkey- Secret key (DEK)block- Encryption metadata with KDF parameters
Example:
.encryption(aesProvider, dek, encryptionBlock)Sets the encryption block separately.
public Builder encryptionBlock(EncryptionBlock block)Enables or disables table of contents.
public Builder enableRandomAccess(boolean enable)Parameters:
enable-truefor random access support
Note: Disabling reduces archive size slightly but prevents entry lookup by name.
Enables or disables stream mode.
public Builder streamMode(boolean streamMode)Parameters:
streamMode-truefor stream mode
Stream Mode:
- Optimized for single-entry streaming
- Simplified trailer
- No random access
Creates the configuration.
public ApackConfiguration build()Returns: Immutable configuration instance
Throws: IllegalArgumentException if configuration is invalid
ApackConfiguration config = ApackConfiguration.builder()
.build();
// Uses all defaultsApackConfiguration config = ApackConfiguration.builder()
.compression(CompressionRegistry.zstd(), 6)
.build();EncryptionProvider aes = EncryptionRegistry.aes256Gcm();
SecretKey key = aes.generateKey();
ApackConfiguration config = ApackConfiguration.builder()
.encryption(aes, key)
.build();ApackConfiguration config = ApackConfiguration.builder()
.compression(CompressionRegistry.zstd(), 3)
.encryption(EncryptionRegistry.aes256Gcm(), secretKey)
.build();ApackConfiguration config = ApackConfiguration.builder()
.chunkSize(1024 * 1024) // 1 MB for better ratio
.compression(CompressionRegistry.zstd(), 19)
.checksumAlgorithm("crc32") // Simpler checksum
.build();ApackConfiguration config = ApackConfiguration.builder()
.chunkSize(64 * 1024) // Smaller chunks
.compression(CompressionRegistry.lz4(), 0)
.build();ApackConfiguration config = ApackConfiguration.builder()
.streamMode(true)
.compression(CompressionRegistry.lz4())
.enableRandomAccess(false)
.build();// Create encryption block
byte[] salt = new byte[32];
SecureRandom.getInstanceStrong().nextBytes(salt);
EncryptionBlock block = EncryptionBlock.builder()
.kdfAlgorithmId(FormatConstants.KDF_ARGON2ID)
.cipherAlgorithmId(FormatConstants.ENCRYPTION_AES_256_GCM)
.kdfIterations(3)
.kdfMemory(65536)
.kdfParallelism(4)
.salt(salt)
.wrappedKey(encryptedDek)
.wrappedKeyTag(authTag)
.build();
ApackConfiguration config = ApackConfiguration.builder()
.chunkSize(256 * 1024)
.checksumProvider(ChecksumRegistry.xxh3_64())
.compression(CompressionRegistry.zstd(), 6)
.encryption(EncryptionRegistry.aes256Gcm(), dek, block)
.enableRandomAccess(true)
.streamMode(false)
.build();The configuration validates:
- Chunk size must be in valid range
- Encryption key required when provider is set
- Checksum provider must not be null
// This throws IllegalArgumentException
ApackConfiguration.builder()
.chunkSize(100) // Too small (< 1024)
.build();
// This throws IllegalArgumentException
ApackConfiguration.builder()
.encryption(aesProvider, null) // Key required
.build();Next: Entries | Previous: Writer API