Package org.eclipse.lsp4j.jsonrpc.json
Class StreamMessageProducer
- java.lang.Object
-
- org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,MessageConstants,MessageProducer
public class StreamMessageProducer extends java.lang.Object implements MessageProducer, java.io.Closeable, MessageConstants
A message producer that reads from an input stream and parses messages from JSON.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classStreamMessageProducer.Headers
-
Field Summary
-
Fields inherited from interface org.eclipse.lsp4j.jsonrpc.json.MessageConstants
CONTENT_LENGTH_HEADER, CONTENT_TYPE_HEADER, CRLF, JSON_MIME_TYPE, JSONRPC_VERSION
-
-
Constructor Summary
Constructors Constructor Description StreamMessageProducer(java.io.InputStream input, MessageJsonHandler jsonHandler)StreamMessageProducer(java.io.InputStream input, MessageJsonHandler jsonHandler, MessageIssueHandler issueHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected voidfireError(java.lang.Throwable error)Log an error.protected voidfireStreamClosed(java.lang.Exception cause)Report that the stream was closed through an exception.java.io.InputStreamgetInput()protected booleanhandleMessage(java.io.InputStream input, StreamMessageProducer.Headers headers)Read the JSON content part of a message, parse it, and notify the callback.voidlisten(MessageConsumer callback)Listen to a message source and forward all messages to the given consumer.protected voidparseHeader(java.lang.String line, StreamMessageProducer.Headers headers)Parse a header attribute and set the corresponding data in theStreamMessageProducer.Headersfields.voidsetInput(java.io.InputStream input)
-
-
-
Constructor Detail
-
StreamMessageProducer
public StreamMessageProducer(java.io.InputStream input, MessageJsonHandler jsonHandler)
-
StreamMessageProducer
public StreamMessageProducer(java.io.InputStream input, MessageJsonHandler jsonHandler, MessageIssueHandler issueHandler)
-
-
Method Detail
-
getInput
public java.io.InputStream getInput()
-
setInput
public void setInput(java.io.InputStream input)
-
listen
public void listen(MessageConsumer callback)
Description copied from interface:MessageProducerListen to a message source and forward all messages to the given consumer. Typically this method blocks until the message source is unable to deliver more messages.- Specified by:
listenin interfaceMessageProducer
-
fireError
protected void fireError(java.lang.Throwable error)
Log an error.
-
fireStreamClosed
protected void fireStreamClosed(java.lang.Exception cause)
Report that the stream was closed through an exception.
-
parseHeader
protected void parseHeader(java.lang.String line, StreamMessageProducer.Headers headers)Parse a header attribute and set the corresponding data in theStreamMessageProducer.Headersfields.
-
handleMessage
protected boolean handleMessage(java.io.InputStream input, StreamMessageProducer.Headers headers) throws java.io.IOExceptionRead the JSON content part of a message, parse it, and notify the callback.- Returns:
trueif we should continue reading from the input stream,falseif we should stop- Throws:
java.io.IOException
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
-