アルファ版。新版→https://osdn.jp/users/tacticsrealize/pf/ChlorophyllUploader/wiki/FrontPage
Révision | 82b375367456635f711775be0d76dcafef88ca32 |
---|---|
Taille | 2,360 octets |
l'heure | 2015-07-08 20:15:01 |
Auteur | |
Message de Log | 新ファイル形式に対応しArduinoとの連携 |
package ants.chlorofilsender;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
import mirrg.util.UTF8StreamReader;
public class InputChlorofilSender extends UTF8StreamReader
{
public InputChlorofilSender(InputStream in, boolean blocking)
{
super(in, blocking);
}
protected ArrayList<String> messageBlockBuffer;
protected String messageBlockSentinel = null;
public void stream(
IntConsumer consumerAcceptedChar,
BiConsumer<EnumTypeMessage, String> consumerMessage,
Consumer<ArrayList<String>> consumerMessageBlock,
Consumer<Exception> consumerInternalException)
{
stream((Consumer<String>) line -> {
if (messageBlockSentinel != null) {
if (line.equals(messageBlockSentinel)) {
messageBlockSentinel = null;
consumerMessageBlock.accept(messageBlockBuffer);
messageBlockBuffer = new ArrayList<>();
} else {
messageBlockBuffer.add(line);
}
return;
}
{
String res;
if ((res = getProperty(line, "C")) != null) {
int i;
try {
i = Integer.parseInt(res, 10);
} catch (NumberFormatException e) {
consumerInternalException.accept(e);
return;
}
consumerAcceptedChar.accept(i);
return;
}
if ((res = getProperty(line, "Message")) != null) {
consumerMessage.accept(EnumTypeMessage.MESSAGE, res);
return;
}
if ((res = getProperty(line, "Error")) != null) {
consumerMessage.accept(EnumTypeMessage.ERROR, res);
return;
}
if ((res = getProperty(line, "Warnings")) != null) {
consumerMessage.accept(EnumTypeMessage.WARNINGS, res);
return;
}
if ((res = getProperty(line, "MessageBlock")) != null) {
messageBlockSentinel = res;
messageBlockBuffer = new ArrayList<>();
return;
}
}
});
}
protected String getProperty(String string, String prefix)
{
prefix += ":";
if (string.startsWith(prefix)) {
return string.substring(prefix.length());
} else {
return null;
}
}
public static enum EnumTypeMessage
{
MESSAGE, ERROR, WARNINGS,
}
public void close()
{
// TODO 自動生成されたメソッド・スタブ
}
}