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 classAbstractStreamDecoder.BufferedStreamThis class avoids locking which gains the performance of this decoder.static classAbstractStreamDecoder.MalformedFrameExceptionclassAbstractStreamDecoder.Mementostatic classAbstractStreamDecoder.Segmentstatic classAbstractStreamDecoder.StreamReadStatusUnderflow - could not completely read out al bytes in one call.
-
Field Summary
Fields Modifier and Type Field Description private ForkNodeArgumentsargumentsstatic intBUFFER_SIZEprivate static intBYTE_LENGTHprivate java.nio.channels.ReadableByteChannelchannelprivate static byte[]DEFAULT_STREAM_ENCODING_BYTESprivate static intDELIMITER_LENGTHprivate static intINT_LENGTHprivate static java.lang.String[]JVM_ERROR_PATTERNSprivate ConsoleLoggerloggerprivate static intLONG_LENGTHprivate java.util.Map<AbstractStreamDecoder.Segment,MT>messageTypesprivate static intNO_POSITIONprivate static java.lang.StringPRINTABLE_JVM_NATIVE_STREAM
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractStreamDecoder(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 voidcheckArguments(AbstractStreamDecoder.Memento memento, int expectedDataElements)protected voidcheckDelimiter(AbstractStreamDecoder.Memento memento)protected voidcheckHeader(AbstractStreamDecoder.Memento memento)protected voiddebugStream(byte[] array, int position, int remaining)abstract Mdecode(AbstractStreamDecoder.Memento memento)private static intdecodeString(java.nio.charset.CharsetDecoder decoder, java.nio.ByteBuffer input, java.nio.CharBuffer output, int bytesToDecode, boolean endOfInput, int errorStreamFrom)protected ForkNodeArgumentsgetArguments()protected abstract byte[]getEncodedMagicNumber()protected abstract ST[]nextSegmentType(MT messageType)private voidprintCorruptedStream(AbstractStreamDecoder.Memento memento)protected voidprintRemainingStream(AbstractStreamDecoder.Memento memento)Print the last string which has not been finished by a new line character.private AbstractStreamDecoder.StreamReadStatusread(java.nio.ByteBuffer buffer, int oldPosition, int recommendedCount)protected AbstractStreamDecoder.StreamReadStatusread(AbstractStreamDecoder.Memento memento, int recommendedCount)protected bytereadByte(AbstractStreamDecoder.Memento memento)protected java.nio.charset.CharsetreadCharset(AbstractStreamDecoder.Memento memento)protected intreadInt(AbstractStreamDecoder.Memento memento)protected java.lang.IntegerreadInteger(AbstractStreamDecoder.Memento memento)protected java.lang.LongreadLong(AbstractStreamDecoder.Memento memento)protected longreadLongPrivate(AbstractStreamDecoder.Memento memento)protected MTreadMessageType(AbstractStreamDecoder.Memento memento)protected AbstractStreamDecoder.SegmentreadSegment(AbstractStreamDecoder.Memento memento)protected java.lang.StringreadString(AbstractStreamDecoder.Memento memento)private java.lang.StringreadString(AbstractStreamDecoder.Memento memento, int totalBytes)protected abstract MtoMessage(MT messageType, AbstractStreamDecoder.Memento memento)private static java.lang.StringtoString(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:
MalformedChannelExceptionjava.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.IOExceptionAbstractStreamDecoder.MalformedFrameException
-
readSegment
@Nonnull protected AbstractStreamDecoder.Segment readSegment(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException
- Throws:
java.io.IOExceptionAbstractStreamDecoder.MalformedFrameException
-
readCharset
@Nonnull protected java.nio.charset.Charset readCharset(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException- Throws:
java.io.IOExceptionAbstractStreamDecoder.MalformedFrameException
-
readString
protected java.lang.String readString(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException- Throws:
java.io.IOExceptionAbstractStreamDecoder.MalformedFrameException
-
readInteger
protected java.lang.Integer readInteger(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException- Throws:
java.io.IOExceptionAbstractStreamDecoder.MalformedFrameException
-
readByte
protected byte readByte(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException- Throws:
java.io.IOExceptionAbstractStreamDecoder.MalformedFrameException
-
readInt
protected int readInt(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException- Throws:
java.io.IOExceptionAbstractStreamDecoder.MalformedFrameException
-
readLong
protected java.lang.Long readLong(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException- Throws:
java.io.IOExceptionAbstractStreamDecoder.MalformedFrameException
-
readLongPrivate
protected long readLongPrivate(@Nonnull AbstractStreamDecoder.Memento memento) throws java.io.IOException, AbstractStreamDecoder.MalformedFrameException- Throws:
java.io.IOExceptionAbstractStreamDecoder.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.IOExceptionAbstractStreamDecoder.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
-
-