swizzle
Reference for org.tomitribe.swizzle.stream stream manipulation and lexer library. TRIGGER when: code imports from org.tomitribe.swizzle, or user needs to find/replace/transform data in InputStreams using fixed string tokens, stream filters, or stream lexing. DO NOT TRIGGER when: working with regex-based stream processing or unrelated stream libraries.
What this skill does
# Swizzle - Stream Manipulation Library
Java library for finding, manipulating, and transforming data in streams using fixed string tokens (no regex). Provides stream filters for on-the-fly transformation and a stream lexer for token extraction. Memory-efficient with fixed-size buffers.
**Package:** `org.tomitribe.swizzle.stream`
## Maven Coordinates
```xml
<groupId>org.tomitribe</groupId>
<artifactId>swizzle</artifactId>
<version>1.4-SNAPSHOT</version>
```
## Core Design
- **Fixed string tokens only** -- no regex, keeping buffers fixed-size and memory efficient
- **Decorator pattern** -- chain multiple filters on a single InputStream
- **Streaming** -- processes data byte-by-byte, suitable for arbitrarily large streams
## StreamBuilder — Fluent API
The simplest way to use Swizzle. Chain operations and get a transformed stream.
```java
InputStream result = StreamBuilder.of("Hello WORLD, goodbye WORLD")
.replace("WORLD", "Earth")
.get();
String output = StreamUtils.streamToString(result);
// "Hello Earth, goodbye Earth"
```
### Factory Methods
```java
StreamBuilder.of(InputStream in)
StreamBuilder.of(File file)
StreamBuilder.of(byte[] bytes)
StreamBuilder.of(String contents)
StreamBuilder.of(String contents, Charset charset)
```
### Operations
```java
// Include only content between tokens
.include(String begin, String end, boolean caseSensitive, boolean keepDelimiters)
// Exclude content between tokens
.exclude(String begin, String end, boolean caseSensitive, boolean keepDelimiters)
// Delete exact token
.delete(String token)
// Delete token and everything between begin/end (inclusive)
.delete(String begin, String end)
// Delete only content between begin/end (keep delimiters)
.deleteBetween(String begin, String end)
// Replace exact token
.replace(String token, String with)
.replace(String token, StringHandler handler)
// Replace begin/end and everything between (inclusive)
.replace(String begin, String end, String with)
.replace(String begin, String end, StringHandler handler)
// Replace only content between begin/end (keep delimiters)
.replaceBetween(String begin, String end, String with)
.replaceBetween(String begin, String end, StringHandler handler)
// Watch for tokens (observe without consuming)
.watch(String token, Consumer<String> consumer)
.watch(String begin, String end, Consumer<String> consumer)
.watch(OutputStream observer)
```
### Terminal Operations
```java
InputStream get() // get transformed stream
void to(OutputStream out) // write to output stream
void run() // consume and discard (for side effects)
```
## Stream Filters
All filters extend `FilteredInputStream`. Chain by wrapping one inside another.
### IncludeFilterInputStream
Include only data between begin and end tokens:
```java
InputStream in = new IncludeFilterInputStream(input, "<BODY", "</BODY>");
// Only data between <BODY and </BODY> passes through
```
Options: `caseSensitive` (default true), `keepDelimiters` (default true).
### ExcludeFilterInputStream
Remove data between begin and end tokens:
```java
InputStream in = new ExcludeFilterInputStream(input, "<!--", "-->");
// HTML comments are removed
```
### Chaining Filters
```java
InputStream in = new BufferedInputStream(url.openStream());
in = new IncludeFilterInputStream(in, "<BODY", "</BODY>");
in = new ExcludeFilterInputStream(in, "<!--", "-->");
in = new ExcludeFilterInputStream(in, "<SCRIPT", "</SCRIPT>");
```
## Token Replacement
### ReplaceStringInputStream — Simple A to B
```java
InputStream in = new ReplaceStringInputStream(input, "RED", "YELLOW");
```
Case-insensitive variant:
```java
InputStream in = new ReplaceStringInputStream(input, false, "red", "YELLOW");
```
### ReplaceStringsInputStream — Multiple Replacements
```java
Map<String, String> replacements = new HashMap<>();
replacements.put("RED", "pear");
replacements.put("GREEN", "grape");
replacements.put("BLUE", "banana");
InputStream in = new ReplaceStringsInputStream(input, replacements);
```
### ReplaceVariablesInputStream — Template Variables
```java
Map<String, String> vars = new HashMap<>();
vars.put("name", "Alice");
vars.put("role", "admin");
InputStream in = new ReplaceVariablesInputStream(input, "{", "}", vars);
// "Hello {name}, you are {role}" -> "Hello Alice, you are admin"
```
### DelimitedTokenReplacementInputStream — Custom Logic
Replace content between delimiters using a handler:
```java
InputStream in = new DelimitedTokenReplacementInputStream(input, "${", "}",
new StringTokenHandler() {
public String handleToken(String token) {
return System.getProperty(token, "${" + token + "}");
}
});
```
### FixedTokenReplacementInputStream — Handler for Fixed Token
```java
InputStream in = new FixedTokenReplacementInputStream(input, "TODAY",
token -> new ByteArrayInputStream(LocalDate.now().toString().getBytes()));
```
## Token Handlers
### StreamTokenHandler (Core Interface)
```java
public interface StreamTokenHandler {
InputStream processToken(String token) throws IOException;
}
```
Returns an InputStream -- can be anything from a simple string to a 10GB file.
### StringTokenHandler (Convenience Base)
```java
public abstract class StringTokenHandler implements StreamTokenHandler {
public abstract String handleToken(String token) throws IOException;
}
```
### StringHandler (Functional Interface)
```java
StreamBuilder.of(input)
.replace("${", "}", (StringHandler) token -> System.getProperty(token, ""))
.get();
```
### MappedTokenHandler
```java
Map<String, String> map = new HashMap<>();
map.put("color", "blue");
map.put("size", "large");
new MappedTokenHandler(map); // returns mapped value or original token
```
## Token Watching (Observation)
Watch for tokens without consuming them from the stream:
### FixedTokenWatchInputStream
```java
InputStream in = new FixedTokenWatchInputStream(input, "ERROR",
token -> System.err.println("Found: " + token));
// Stream passes through unchanged; callback fires on each match
```
### DelimitedTokenWatchInputStream
```java
InputStream in = new DelimitedTokenWatchInputStream(input, "<error>", "</error>",
token -> log.warn("Error found: " + token));
```
## StreamLexer — Token Extraction
Higher-level API for reading specific tokens from streams.
```java
StreamLexer lexer = new StreamLexer(inputStream);
```
### Reading Tokens
```java
// Read content between begin and end tokens
String value = lexer.readToken("<title>", "</title>");
// Read exact token (seek to it and consume)
String token = lexer.readToken("Expected Text");
```
### Seek and Peek
```java
// Seek: advance to token position
String found = lexer.seek("<body>", "</body>");
// Peek: look ahead without advancing
String preview = lexer.peek("<title>", "</title>");
```
### Mark/Unmark — Scoped Reading
Limit reading scope to a section of the stream:
```java
// Mark scope to <project>...</project>
lexer.seekAndMark("<project>", "</project>");
// Nested mark for <dependencies>...</dependencies>
lexer.seekAndMark("<dependencies>", "</dependencies>");
// Read within scope
String groupId = lexer.readToken("<groupId>", "</groupId>");
String artifactId = lexer.readToken("<artifactId>", "</artifactId>");
// Exit scopes
lexer.readAndUnmark(); // exit </dependencies>
lexer.readAndUnmark(); // exit </project>
```
### StreamLexer API
```java
String readToken(String begin, String end)
String readToken(String string)
String seek(String begin, String end)
String seek(String string)
String peek(String begin, String end)
String peek(String string)
StreamLexer mark()
StreamLexer mark(String limit)
void unmark()
boolean seekAndMark(String begin, String end)
boolean readAndMark(String begin, String end)
boolean seekAndUnmark()
boolean readAndUnmark()
```
## StringTemplate
Simple template engine:
```java
StringTemplate template = new StringTemplate("{dir}/{nRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.