-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from AnetteTaivere/restructure
Restructure project: move classes into appropriate packages
- Loading branch information
Showing
9 changed files
with
407 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 56 additions & 56 deletions
112
...pi/json/GoblintSocketMessageConsumer.java → ...jsonrpc/GoblintSocketMessageConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
package api.json; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.eclipse.lsp4j.jsonrpc.JsonRpcException; | ||
import org.eclipse.lsp4j.jsonrpc.MessageConsumer; | ||
import org.eclipse.lsp4j.jsonrpc.json.MessageConstants; | ||
import org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler; | ||
import org.eclipse.lsp4j.jsonrpc.messages.Message; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
|
||
/** | ||
* A message consumer that serializes messages to JSON and sends them to an output stream. | ||
* | ||
* @since 0.0.3 | ||
*/ | ||
|
||
public class GoblintSocketMessageConsumer implements MessageConsumer, MessageConstants { | ||
|
||
private final String encoding; | ||
private final MessageJsonHandler jsonHandler; | ||
private final Object outputLock = new Object(); | ||
private final OutputStream output; | ||
|
||
private final Logger log = LogManager.getLogger(GoblintSocketMessageConsumer.class); | ||
|
||
public GoblintSocketMessageConsumer(OutputStream output, MessageJsonHandler jsonHandler) { | ||
this(output, StandardCharsets.UTF_8.name(), jsonHandler); | ||
} | ||
|
||
public GoblintSocketMessageConsumer(OutputStream output, String encoding, MessageJsonHandler jsonHandler) { | ||
this.output = output; | ||
this.encoding = encoding; | ||
this.jsonHandler = jsonHandler; | ||
} | ||
|
||
@Override | ||
public void consume(Message message) { | ||
try { | ||
String content = jsonHandler.serialize(message) + "\n"; | ||
byte[] contentBytes = content.getBytes(encoding); | ||
synchronized (outputLock) { | ||
output.write(contentBytes); | ||
output.flush(); | ||
} | ||
log.debug("WRITTEN: {}", content); | ||
} catch (IOException exception) { | ||
throw new JsonRpcException(exception); | ||
} | ||
} | ||
|
||
} | ||
package api.jsonrpc; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.eclipse.lsp4j.jsonrpc.JsonRpcException; | ||
import org.eclipse.lsp4j.jsonrpc.MessageConsumer; | ||
import org.eclipse.lsp4j.jsonrpc.json.MessageConstants; | ||
import org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler; | ||
import org.eclipse.lsp4j.jsonrpc.messages.Message; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
|
||
/** | ||
* A message consumer that serializes messages to JSON and sends them to an output stream. | ||
* | ||
* @since 0.0.3 | ||
*/ | ||
|
||
public class GoblintSocketMessageConsumer implements MessageConsumer, MessageConstants { | ||
|
||
private final String encoding; | ||
private final MessageJsonHandler jsonHandler; | ||
private final Object outputLock = new Object(); | ||
private final OutputStream output; | ||
|
||
private final Logger log = LogManager.getLogger(GoblintSocketMessageConsumer.class); | ||
|
||
public GoblintSocketMessageConsumer(OutputStream output, MessageJsonHandler jsonHandler) { | ||
this(output, StandardCharsets.UTF_8.name(), jsonHandler); | ||
} | ||
|
||
public GoblintSocketMessageConsumer(OutputStream output, String encoding, MessageJsonHandler jsonHandler) { | ||
this.output = output; | ||
this.encoding = encoding; | ||
this.jsonHandler = jsonHandler; | ||
} | ||
|
||
@Override | ||
public void consume(Message message) { | ||
try { | ||
String content = jsonHandler.serialize(message) + "\n"; | ||
byte[] contentBytes = content.getBytes(encoding); | ||
synchronized (outputLock) { | ||
output.write(contentBytes); | ||
output.flush(); | ||
} | ||
log.debug("WRITTEN: {}", content); | ||
} catch (IOException exception) { | ||
throw new JsonRpcException(exception); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.