Skip to content

Commit

Permalink
Fix the logviewer problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali committed Mar 8, 2022
1 parent d101233 commit 93a85c4
Showing 1 changed file with 42 additions and 41 deletions.
83 changes: 42 additions & 41 deletions modules/rescuecore2/src/rescuecore2/log/AbstractLogWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 93a85c4

Please sign in to comment.