Class AbstractStreamDecoder<M,MT extends java.lang.Enum<MT>,ST extends java.lang.Enum<ST>>
- java.lang.Object
-
- org.apache.maven.surefire.api.stream.AbstractStreamDecoder<M,MT,ST>
-
- Type Parameters:
M
- message objectMT
- enum describing the meaning of the messageST
- enum for segment type
- All Implemented Interfaces:
java.lang.AutoCloseable
- Direct Known Subclasses:
CommandDecoder
,EventDecoder
public abstract class AbstractStreamDecoder<M,MT extends java.lang.Enum<MT>,ST extends java.lang.Enum<ST>> extends java.lang.Object implements java.lang.AutoCloseable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
AbstractStreamDecoder.BufferedStream
This class avoids locking which gains the performance of this decoder.static class
AbstractStreamDecoder.MalformedFrameException
class
AbstractStreamDecoder.Memento
static class
AbstractStreamDecoder.Segment
static class
AbstractStreamDecoder.StreamReadStatus
Underflow - could not completely read out al bytes in one call.
-
Field Summary
Fields Modifier and Type Field Description private ForkNodeArguments
arguments
static int
BUFFER_SIZE
private static int
BYTE_LENGTH
private java.nio.channels.ReadableByteChannel
channel
private static byte[]
DEFAULT_STREAM_ENCODING_BYTES
private static int
DELIMITER_LENGTH
private static int
INT_LENGTH
private static java.lang.String[]
JVM_ERROR_PATTERNS
private ConsoleLogger
logger
private static int
LONG_LENGTH
private java.util.Map<AbstractStreamDecoder.Segment,MT>
messageTypes
private static int
NO_POSITION
private static java.lang.String
PRINTABLE_JVM_NATIVE_STREAM
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractStreamDecoder(java.nio.channels.ReadableByteChannel channel, ForkNodeArguments arguments, java.util.Map<AbstractStreamDecoder.Segment,MT> messageTypes)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
checkArguments(AbstractStreamDecoder.Memento memento, int expectedDataElements)
protected void
checkDelimiter(AbstractStreamDecoder.Memento memento)
protected void
checkHeader(AbstractStreamDecoder.Memento memento)
protected void
debugStream(byte[] array, int position, int remaining)
abstract M
decode(AbstractStreamDecoder.Memento memento)
private static int
decodeString(java.nio.charset.CharsetDecoder decoder, java.nio.ByteBuffer input, java.nio.CharBuffer output, int bytesToDecode, boolean endOfInput, int errorStreamFrom)
protected ForkNodeArguments
getArguments()
protected abstract byte[]
getEncodedMagicNumber()
protected abstract ST[]
nextSegmentType(MT messageType)
private void
printCorruptedStream(AbstractStreamDecoder.Memento memento)
protected void
printRemainingStream(AbstractStreamDecoder.Memento memento)
Print the last string which has not been finished by a new line character.private AbstractStreamDecoder.StreamReadStatus
read(java.nio.ByteBuffer buffer, int oldPosition, int recommendedCount)
protected AbstractStreamDecoder.StreamReadStatus
read(AbstractStreamDecoder.Memento memento, int recommendedCount)
protected byte
readByte(AbstractStreamDecoder.Memento memento)
protected java.nio.charset.Charset
readCharset(AbstractStreamDecoder.Memento memento)
protected int
readInt(AbstractStreamDecoder.Memento memento)
protected java.lang.Integer
readInteger(AbstractStreamDecoder.Memento memento)
protected java.lang.Long
readLong(AbstractStreamDecoder.Memento memento)
protected long
readLongPrivate(AbstractStreamDecoder.Memento memento)
protected MT
readMessageType(AbstractStreamDecoder.Memento memento)
protected AbstractStreamDecoder.Segment
readSegment(AbstractStreamDecoder.Memento memento)
protected java.lang.String
readString(AbstractStreamDecoder.Memento memento)
private java.lang.String
readString(AbstractStreamDecoder.Memento memento, int totalBytes)
protected abstract M
toMessage(MT messageType, AbstractStreamDecoder.Memento memento)
private static java.lang.String
toString(java.util.List<java.lang.String> strings)
-
-
-
Field Detail
-
BUFFER_SIZE
public static final int BUFFER_SIZE
- See Also:
- Constant Field Values
-
PRINTABLE_JVM_NATIVE_STREAM
private static final java.lang.String PRINTABLE_JVM_NATIVE_STREAM
- See Also:
- Constant Field Values
-
JVM_ERROR_PATTERNS
private static final java.lang.String[] JVM_ERROR_PATTERNS
-
DEFAULT_STREAM_ENCODING_BYTES
private static final byte[] DEFAULT_STREAM_ENCODING_BYTES
-
NO_POSITION
private static final int NO_POSITION
- See Also:
- Constant Field Values
-
DELIMITER_LENGTH
private static final int DELIMITER_LENGTH
- See Also:
- Constant Field Values
-
BYTE_LENGTH
private static final int BYTE_LENGTH
- See Also:
- Constant Field Values
-
INT_LENGTH
private static final int INT_LENGTH
- See Also:
- Constant Field Values
-
LONG_LENGTH
private static final int LONG_LENGTH
- See Also:
- Constant Field Values
-
channel
private final java.nio.channels.ReadableByteChannel channel
-
arguments
private final ForkNodeArguments arguments
-
messageTypes
private final java.util.Map<AbstractStreamDecoder.Segment,MT extends java.lang.Enum<MT>> messageTypes
-
logger
private final ConsoleLogger logger
-
-
Constructor Detail
-
AbstractStreamDecoder
protected AbstractStreamDecoder(@Nonnull java.nio.channels.ReadableByteChannel channel, @Nonnull ForkNodeArguments arguments, @Nonnull java.util.Map<AbstractStreamDecoder.Segment,MT> messageTypes)
-
-
Method Detail
-
decode
public abstract M decode(@Nonnull AbstractStreamDecoder.Memento memento) throws MalformedChannelException, java.io.IOException
- Throws:
MalformedChannelException
java.io.IOException
-
getEncodedMagicNumber
@Nonnull protected abstract byte[] getEncodedMagicNumber()
-
toMessage
@Nonnull protected abstract M toMessage(@Nonnull MT messageType, @Nonnull AbstractStreamDecoder.Memento memento) throws AbstractStreamDecoder.MalformedFrameException
-
getArguments
@Nonnull protected final ForkNodeArguments getArguments()
-
debugStream
protected void debugStream(byte[] array, int position, int remaining)
-
readMessageType
protected MT readMessageType(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException
- Throws:
java.io.IOException
AbstractStreamDecoder.MalformedFrameException
-
readSegment
@Nonnull protected AbstractStreamDecoder.Segment readSegment(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException
- Throws:
java.io.IOException
AbstractStreamDecoder.MalformedFrameException
-
readCharset
@Nonnull protected java.nio.charset.Charset readCharset(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException
- Throws:
java.io.IOException
AbstractStreamDecoder.MalformedFrameException
-
readString
protected java.lang.String readString(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException
- Throws:
java.io.IOException
AbstractStreamDecoder.MalformedFrameException
-
readInteger
protected java.lang.Integer readInteger(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException
- Throws:
java.io.IOException
AbstractStreamDecoder.MalformedFrameException
-
readByte
protected byte readByte(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException
- Throws:
java.io.IOException
AbstractStreamDecoder.MalformedFrameException
-
readInt
protected int readInt(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException
- Throws:
java.io.IOException
AbstractStreamDecoder.MalformedFrameException
-
readLong
protected java.lang.Long readLong(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException
- Throws:
java.io.IOException
AbstractStreamDecoder.MalformedFrameException
-
readLongPrivate
protected long readLongPrivate(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException
- Throws:
java.io.IOException
AbstractStreamDecoder.MalformedFrameException
-
checkDelimiter
protected final void checkDelimiter(AbstractStreamDecoder.Memento memento) throws AbstractStreamDecoder.MalformedFrameException
-
checkHeader
protected final void checkHeader(AbstractStreamDecoder.Memento memento) throws AbstractStreamDecoder.MalformedFrameException
-
checkArguments
protected void checkArguments(AbstractStreamDecoder.Memento memento, int expectedDataElements) throws AbstractStreamDecoder.MalformedFrameException
-
readString
private java.lang.String readString(@Nonnull AbstractStreamDecoder.Memento memento, @Nonnegative int totalBytes) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException
- Throws:
java.io.IOException
AbstractStreamDecoder.MalformedFrameException
-
decodeString
private static int decodeString(@Nonnull java.nio.charset.CharsetDecoder decoder, @Nonnull java.nio.ByteBuffer input, @Nonnull java.nio.CharBuffer output, @Nonnegative int bytesToDecode, boolean endOfInput, @Nonnegative int errorStreamFrom) throws AbstractStreamDecoder.MalformedFrameException
-
toString
private static java.lang.String toString(java.util.List<java.lang.String> strings)
-
printCorruptedStream
private void printCorruptedStream(AbstractStreamDecoder.Memento memento)
-
printRemainingStream
protected final void printRemainingStream(AbstractStreamDecoder.Memento memento)
Print the last string which has not been finished by a new line character.- Parameters:
memento
- current memento object
-
read
@Nonnull protected AbstractStreamDecoder.StreamReadStatus read(@Nonnull AbstractStreamDecoder.Memento memento, int recommendedCount) throws java.io.IOException
- Throws:
java.io.IOException
-
read
private AbstractStreamDecoder.StreamReadStatus read(java.nio.ByteBuffer buffer, int oldPosition, int recommendedCount) throws java.io.IOException
- Throws:
java.io.IOException
-
-