Package org.apache.james.mime4j.stream
Class MimeEntity
- java.lang.Object
-
- org.apache.james.mime4j.stream.MimeEntity
-
- All Implemented Interfaces:
EntityStateMachine
class MimeEntity extends java.lang.Object implements EntityStateMachine
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.ThreadLocal<java.lang.ref.SoftReference<BufferRecycler>>
_recyclerRef
private BodyDescriptor
body
private BodyDescriptorBuilder
bodyDescBuilder
private MimeConfig
config
private MimeBoundaryInputStream
currentMimePartStream
private LineReaderInputStreamAdaptor
dataStream
private boolean
endOfHeader
private EntityState
endState
private Field
field
private FieldBuilder
fieldBuilder
private int
headerCount
private BufferedLineReaderInputStream
inbuffer
private ByteArrayBuffer
linebuf
private int
lineCount
private LineNumberSource
lineSource
private DecodeMonitor
monitor
private RecursionMode
recursionMode
private EntityState
state
private byte[]
tmpbuf
-
Constructor Summary
Constructors Constructor Description MimeEntity(LineNumberSource lineSource, java.io.InputStream instream, BodyDescriptorBuilder bodyDescBuilder)
MimeEntity(LineNumberSource lineSource, java.io.InputStream instream, FieldBuilder fieldBuilder, BodyDescriptorBuilder bodyDescBuilder)
MimeEntity(LineNumberSource lineSource, java.io.InputStream instream, MimeConfig config, BodyDescriptorBuilder bodyDescBuilder)
MimeEntity(LineNumberSource lineSource, java.io.InputStream instream, MimeConfig config, EntityState startState, EntityState endState, DecodeMonitor monitor, FieldBuilder fieldBuilder, BodyDescriptorBuilder bodyDescBuilder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description EntityStateMachine
advance()
Advances the state machine to the next state in the process of the MIME stream parsing.private void
advanceToBoundary()
private void
clearMimePartStream()
private void
createMimePartStream()
private java.io.InputStream
decodedStream(java.io.InputStream instream)
BodyDescriptor
getBodyDescriptor()
Gets a descriptor for the current entity.static BufferRecycler
getBufferRecycler()
java.io.InputStream
getContentStream()
Returns content stream of the entity body.private LineReaderInputStream
getDataStream()
java.io.InputStream
getDecodedContentStream()
Returns the decoded content stream of the entity body.Field
getField()
This method is valid, ifgetState()
returnsEntityState.T_FIELD
.private java.io.InputStream
getLimitedContentStream()
private int
getLineNumber()
RecursionMode
getRecursionMode()
EntityState
getState()
Return the current state of the entity.protected java.lang.String
message(Event event)
Creates an indicative message suitable for display based on the given event and the current state of the system.protected void
monitor(Event event)
protected boolean
nextField()
private EntityStateMachine
nextMessage()
private EntityStateMachine
nextMimeEntity()
private EntityStateMachine
nextMimeEntity(EntityState startState, EntityState endState, java.io.InputStream instream)
private void
readRawField()
void
setRecursionMode(RecursionMode recursionMode)
Sets the current recursion mode.static java.lang.String
stateToString(EntityState state)
Renders a state as a string suitable for logging.void
stop()
void
stopSoft()
java.lang.String
toString()
-
-
-
Field Detail
-
_recyclerRef
protected static final java.lang.ThreadLocal<java.lang.ref.SoftReference<BufferRecycler>> _recyclerRef
-
endState
private final EntityState endState
-
config
private final MimeConfig config
-
monitor
private final DecodeMonitor monitor
-
fieldBuilder
private final FieldBuilder fieldBuilder
-
bodyDescBuilder
private final BodyDescriptorBuilder bodyDescBuilder
-
linebuf
private final ByteArrayBuffer linebuf
-
lineSource
private final LineNumberSource lineSource
-
inbuffer
private final BufferedLineReaderInputStream inbuffer
-
state
private EntityState state
-
lineCount
private int lineCount
-
endOfHeader
private boolean endOfHeader
-
headerCount
private int headerCount
-
field
private Field field
-
body
private BodyDescriptor body
-
recursionMode
private RecursionMode recursionMode
-
currentMimePartStream
private MimeBoundaryInputStream currentMimePartStream
-
dataStream
private LineReaderInputStreamAdaptor dataStream
-
tmpbuf
private byte[] tmpbuf
-
-
Constructor Detail
-
MimeEntity
MimeEntity(LineNumberSource lineSource, java.io.InputStream instream, MimeConfig config, EntityState startState, EntityState endState, DecodeMonitor monitor, FieldBuilder fieldBuilder, BodyDescriptorBuilder bodyDescBuilder)
-
MimeEntity
MimeEntity(LineNumberSource lineSource, java.io.InputStream instream, MimeConfig config, BodyDescriptorBuilder bodyDescBuilder)
-
MimeEntity
MimeEntity(LineNumberSource lineSource, java.io.InputStream instream, FieldBuilder fieldBuilder, BodyDescriptorBuilder bodyDescBuilder)
-
MimeEntity
MimeEntity(LineNumberSource lineSource, java.io.InputStream instream, BodyDescriptorBuilder bodyDescBuilder)
-
-
Method Detail
-
getBufferRecycler
public static BufferRecycler getBufferRecycler()
-
getState
public EntityState getState()
Description copied from interface:EntityStateMachine
Return the current state of the entity.- Specified by:
getState
in interfaceEntityStateMachine
- Returns:
- current state
- See Also:
EntityState
-
getRecursionMode
public RecursionMode getRecursionMode()
-
setRecursionMode
public void setRecursionMode(RecursionMode recursionMode)
Description copied from interface:EntityStateMachine
Sets the current recursion mode. The recursion mode specifies the approach taken to parsing parts.RecursionMode.M_RAW
mode does not parse the part at all.RecursionMode.M_RECURSE
mode recursively parses each mail when anmessage/rfc822
part is encounted;RecursionMode.M_NO_RECURSE
does not.- Specified by:
setRecursionMode
in interfaceEntityStateMachine
- See Also:
RecursionMode
-
stop
public void stop()
-
stopSoft
public void stopSoft()
-
getLineNumber
private int getLineNumber()
-
getDataStream
private LineReaderInputStream getDataStream()
-
message
protected java.lang.String message(Event event)
Creates an indicative message suitable for display based on the given event and the current state of the system.- Parameters:
event
-Event
, not null- Returns:
- message suitable for use as a message in an exception or for logging
-
monitor
protected void monitor(Event event) throws MimeException, java.io.IOException
- Throws:
MimeException
java.io.IOException
-
readRawField
private void readRawField() throws java.io.IOException, MimeException
- Throws:
java.io.IOException
MimeException
-
nextField
protected boolean nextField() throws MimeException, java.io.IOException
- Throws:
MimeException
java.io.IOException
-
advance
public EntityStateMachine advance() throws java.io.IOException, MimeException
Description copied from interface:EntityStateMachine
Advances the state machine to the next state in the process of the MIME stream parsing. This method may return an new state machine that represents an embedded entity, which must be parsed before the parsing process of the current entity can proceed.- Specified by:
advance
in interfaceEntityStateMachine
- Returns:
- a state machine of an embedded entity, if encountered,
null
otherwise. - Throws:
java.io.IOException
- if an I/O error occurs.MimeException
- if the message can not be processed due to the MIME specification violation.
-
createMimePartStream
private void createMimePartStream() throws MimeException, java.io.IOException
- Throws:
MimeException
java.io.IOException
-
clearMimePartStream
private void clearMimePartStream()
-
advanceToBoundary
private void advanceToBoundary() throws java.io.IOException
- Throws:
java.io.IOException
-
nextMessage
private EntityStateMachine nextMessage()
-
decodedStream
private java.io.InputStream decodedStream(java.io.InputStream instream)
-
nextMimeEntity
private EntityStateMachine nextMimeEntity()
-
nextMimeEntity
private EntityStateMachine nextMimeEntity(EntityState startState, EntityState endState, java.io.InputStream instream)
-
getLimitedContentStream
private java.io.InputStream getLimitedContentStream()
-
getBodyDescriptor
public BodyDescriptor getBodyDescriptor()
Gets a descriptor for the current entity. This method is valid if
getState()
returns:- Specified by:
getBodyDescriptor
in interfaceEntityStateMachine
- Returns:
BodyDescriptor
, not nulls
-
getField
public Field getField()
This method is valid, ifgetState()
returnsEntityState.T_FIELD
.- Specified by:
getField
in interfaceEntityStateMachine
- Returns:
- String with the fields raw contents.
- Throws:
java.lang.IllegalStateException
-getState()
returns another value thanEntityState.T_FIELD
.
-
getContentStream
public java.io.InputStream getContentStream()
Description copied from interface:EntityStateMachine
Returns content stream of the entity body.- Specified by:
getContentStream
in interfaceEntityStateMachine
- Returns:
- input stream
- See Also:
EntityStateMachine.getContentStream()
-
getDecodedContentStream
public java.io.InputStream getDecodedContentStream() throws java.lang.IllegalStateException
Description copied from interface:EntityStateMachine
Returns the decoded content stream of the entity body.- Specified by:
getDecodedContentStream
in interfaceEntityStateMachine
- Returns:
- input stream
- Throws:
java.lang.IllegalStateException
- if the content stream cannot be obtained at the current stage of the parsing process.- See Also:
EntityStateMachine.getDecodedContentStream()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
stateToString
public static java.lang.String stateToString(EntityState state)
Renders a state as a string suitable for logging.- Parameters:
state
-- Returns:
- rendered as string, not null
-
-