Skip to content

RutledgePaulV/injecting-streams

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status Maven Central

Injecting Streams

Implements a java.io.OutputStream that injects bytes as data is written to the original output stream. Bytes are injected before or after a delimiter of your choice (an array of known bytes). Correct for all uses of the returned stream, carefully implemented for optimal efficiency, and has zero dependencies.

Usage

You might use this to inject additional markup into a stream of html content without having to otherwise parse the markup or convert back into text.

var source       = new FileInputStream("original.html");
var sink         = new FileOutputStream("modified.html");
var modifiedSink = InjectingStreams.injectAfterOutput(sink, "<head>", "<script>alert('hello, world')</script>");

try {
    IOUtils.copy(source,modifiedSink);
} finally {
    IOUtils.close(source);
    IOUtils.close(modifiedSink);
}
var source       = new FileInputStream("original.html");
var sink         = new FileOutputStream("modified.html");
var modifiedSink = InjectingStreams.injectBeforeOutput(sink, "</body>", "<script>alert('hello, world')</script>");

try {
    IOUtils.copy(source,modifiedSink);
} finally {
    IOUtils.close(source);
    IOUtils.close(modifiedSink);
}

Installation

<dependencies>
    <dependency>
        <groupId>com.github.rutledgepaulv</groupId>
        <artifactId>injecting-streams</artifactId>
        <version>2.0</version>
    </dependency>
</dependencies>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published