Top Description Inners Fields Constructors Methods
org.apache.poi.util

public Class ReplacingInputStream

extends FilterInputStream
Class Inheritance
Annotations
@Internal
Static Imports
java.nio.charset.StandardCharsets.UTF_8

Simple FilterInputStream that can replace occurrences of bytes with something else. This has been taken from inbot-utils. (MIT licensed)
See Also
inbot-utils

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
pack-priv final int[]
private int
private final byte[]
private int
private final byte[]
private ReplacingInputStream.State
private int
Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
public
ReplacingInputStream(InputStream
input
in
,
String
pattern to replace.
pattern
,
String
the replacement or null
replacement
)

Replace occurrences of pattern in the input.

public
ReplacingInputStream(InputStream
input
in
,
byte[]
pattern to replace
pattern
,
byte[]
the replacement or null
replacement
)

Replace occurrences of pattern in the input.

Method Summary

Modifier and TypeMethod and Description
public int
read(byte[]
the buffer into which the data is read.
b
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
len
)

Overrides java.io.FilterInputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes.

public int
read(byte[]
the buffer into which the data is read.
b
)

Overrides java.io.FilterInputStream.read.

Reads up to b.length bytes of data from this input stream into an array of bytes.

public int
read()

Overrides java.io.FilterInputStream.read.

Reads the next byte of data from the input stream.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.io.FilterInputStream:
availableclosemarkmarkSupportedresetskip

Field Detail

bufback to summary
pack-priv final int[] buf
matchedIndexback to summary
private int matchedIndex
patternback to summary
private final byte[] pattern
replacedIndexback to summary
private int replacedIndex
replacementback to summary
private final byte[] replacement
stateback to summary
private ReplacingInputStream.State state
unbufferIndexback to summary
private int unbufferIndex

Constructor Detail

ReplacingInputStreamback to summary
public ReplacingInputStream(InputStream in, String pattern, String replacement)

Replace occurrences of pattern in the input.

Note

input is assumed to be UTF-8 encoded. If not the case use byte[] based pattern and replacement.

Parameters
in:InputStream

input

pattern:String

pattern to replace.

replacement:String

the replacement or null

ReplacingInputStreamback to summary
public ReplacingInputStream(InputStream in, byte[] pattern, byte[] replacement)

Replace occurrences of pattern in the input.

If you want to normalize line endings DOS/MAC (\n\r | \r) to UNIX (\n), you can call the following:
new ReplacingInputStream(new ReplacingInputStream(is, "\n\r", "\n"), "\r", "\n")

Parameters
in:InputStream

input

pattern:byte[]

pattern to replace

replacement:byte[]

the replacement or null

Method Detail

readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes. If len is not zero, the method blocks until some input is available; otherwise, no bytes are read and 0 is returned.

Parameters
b:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

len:int

the maximum number of bytes to read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(byte[] b) throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.read.

Reads up to b.length bytes of data from this input stream into an array of bytes. This method blocks until some input is available.

Parameters
b:byte[]

the buffer into which the data is read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read() throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.apache.poi.util back to summary

private final Enum ReplacingInputStream.State

extends Enum<ReplacingInputStream.State>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final ReplacingInputStream.State
public static final ReplacingInputStream.State
public static final ReplacingInputStream.State
public static final ReplacingInputStream.State

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ReplacingInputStream.State
public static ReplacingInputStream.State[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

MATCHINGback to summary
public static final ReplacingInputStream.State MATCHING
NOT_MATCHEDback to summary
public static final ReplacingInputStream.State NOT_MATCHED
REPLACINGback to summary
public static final ReplacingInputStream.State REPLACING
UNBUFFERback to summary
public static final ReplacingInputStream.State UNBUFFER

Constructor Detail

Stateback to summary
private State()

Method Detail

valueOfback to summary
public static ReplacingInputStream.State valueOf(String name)
valuesback to summary
public static ReplacingInputStream.State[] values()