From 93a85c4b1ba90770c58d4376f310c754360525a7 Mon Sep 17 00:00:00 2001 From: Ali Date: Tue, 8 Mar 2022 09:57:47 +0100 Subject: [PATCH] Fix the logviewer problem --- .../rescuecore2/log/AbstractLogWriter.java | 83 ++++++++++--------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/modules/rescuecore2/src/rescuecore2/log/AbstractLogWriter.java b/modules/rescuecore2/src/rescuecore2/log/AbstractLogWriter.java index fba25394..0b05d07c 100644 --- a/modules/rescuecore2/src/rescuecore2/log/AbstractLogWriter.java +++ b/modules/rescuecore2/src/rescuecore2/log/AbstractLogWriter.java @@ -5,52 +5,53 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; -import com.google.protobuf.util.JsonFormat; - import rescuecore2.messages.protobuf.RCRSLogProto.LogProto; /** - Abstract base class for log writer implementations. + * Abstract base class for log writer implementations. */ public abstract class AbstractLogWriter implements LogWriter { - @Override - public final void writeRecord(LogRecord entry) throws LogException { + @Override + public final void writeRecord(LogRecord entry) throws LogException { // writeRecordV1(entry); - writeRecordProtoBuf(entry); - } - private final void writeRecordProtoBuf(LogRecord entry) throws LogException { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - try { - LogProto proto = entry.toLogProto(); - byte[] data = JsonFormat.printer().print(proto).getBytes(); - writeInt32(data.length, out); - out.write(data); - write(out.toByteArray()); - } - catch (IOException e) { - throw new LogException(e); - } - } - private final void writeRecordV1(LogRecord entry) throws LogException { - ByteArrayOutputStream gather = new ByteArrayOutputStream(); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - try { - entry.write(gather); - byte[] data = gather.toByteArray(); - writeInt32(entry.getRecordType().getID(), out); - writeInt32(data.length, out); - out.write(data); - write(out.toByteArray()); - } - catch (IOException e) { - throw new LogException(e); - } - } + writeRecordProtoBuf(entry); + } + + private final void writeRecordProtoBuf(LogRecord entry) + throws LogException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + try { + LogProto proto = entry.toLogProto(); +// byte[] data = JsonFormat.printer().print(proto).getBytes(); FOR JSON PRINT + byte[] data = proto.toByteString().toByteArray(); + writeInt32(data.length, out); + out.write(data); + write(out.toByteArray()); + } catch (IOException e) { + throw new LogException(e); + } + } + + private final void writeRecordV1(LogRecord entry) throws LogException { + ByteArrayOutputStream gather = new ByteArrayOutputStream(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + try { + entry.write(gather); + byte[] data = gather.toByteArray(); + writeInt32(entry.getRecordType().getID(), out); + writeInt32(data.length, out); + out.write(data); + write(out.toByteArray()); + } catch (IOException e) { + throw new LogException(e); + } + } - /** - Write a set of bytes to the log. - @param bytes The bytes to write. - @throws LogException If there is a problem writing the bytes. - */ - protected abstract void write(byte[] bytes) throws LogException; + /** + * Write a set of bytes to the log. + * + * @param bytes The bytes to write. + * @throws LogException If there is a problem writing the bytes. + */ + protected abstract void write(byte[] bytes) throws LogException; }