Skip to content

Commit 06584f0

Browse files
committed
Now log line split with deviders
1 parent 09cf870 commit 06584f0

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
|:--------------------:|:------:|:------:|:------:|:--------------------------------------------------------------------------:|:--------:|:-------:|:---------:|
1010
| Field Length (bytes) | 4 byte | 4 byte | 4 byte | 1 byte ('0' for Remove, '1' for Insert, '2' for update, '100' for unknown) | 4 byte | 8 byte | 8 byte |
1111

12-
Total: 33 bytes per line
12+
Total: 33 bytes per line (+1 byte for devider)
1313

1414
Filename: /{save}/{world/dimension}/*.bytelog
1515

src/main/java/ru/lionzxy/fastlogblock/io/log/LogReader.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,20 @@ public List<BlockChangeEventModel> readEventByPos(final BlockPos blockPos) throw
5050
final TLongSet needBlockName = new TLongHashSet();
5151
final TIntSet needNickName = new TIntHashSet();
5252
iterateByFile((byteList) -> {
53-
final PrepareReadBlockChangeEvent prepareReadBlockChangeEvent = prepareOrNullByPos(byteList.toArray(),
54-
needPosX, needPosY, needPosZ);
55-
if (prepareReadBlockChangeEvent == null) {
56-
return;
53+
try {
54+
final PrepareReadBlockChangeEvent prepareReadBlockChangeEvent = prepareOrNullByPos(byteList.toArray(),
55+
needPosX, needPosY, needPosZ);
56+
if (prepareReadBlockChangeEvent == null) {
57+
return;
58+
}
59+
60+
needBlockName.add(prepareReadBlockChangeEvent.getBlockId());
61+
needNickName.add(prepareReadBlockChangeEvent.getPlayerid());
62+
63+
prepareEvents.add(prepareReadBlockChangeEvent);
64+
} catch (Exception e) {
65+
FMLLog.log.warn("Your logfile is corrupt!", e);
5766
}
58-
59-
needBlockName.add(prepareReadBlockChangeEvent.getBlockId());
60-
needNickName.add(prepareReadBlockChangeEvent.getPlayerid());
61-
62-
prepareEvents.add(prepareReadBlockChangeEvent);
6367
});
6468

6569
final TIntObjectMap<ASCIString> idToNick = CollectionUtils.toHashMap(needNickName, id -> nickMapper.getById(id));
@@ -103,6 +107,6 @@ public void sync() throws IOException {
103107

104108
@Override
105109
protected boolean checkLineEnd(final TByteArrayList arrayList, final byte endByte) {
106-
return arrayList.size() == Constants.SIZE_LOGLINE;
110+
return endByte == Constants.DEVIDER_SYMBOL;
107111
}
108112
}

src/main/java/ru/lionzxy/fastlogblock/io/log/LogWritter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public void putEvent(final BlockChangeEventModel blockChangeEventModel) {
4242
byteBuffer.putInt(nickMapper.getOrPutUser(blockChangeEventModel.getPlayernick()));
4343
byteBuffer.putLong(blockMapper.getOrPutBlock(blockChangeEventModel.getNameblock()));
4444
byteBuffer.putLong(blockChangeEventModel.getTimestamp().getTime());
45+
byteBuffer.put(Constants.DEVIDER_SYMBOL);
4546

4647
try {
4748
os.write(byteBuffer.array());
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ru.lionzxy.fastlogblock.utils;
22

33
public class Constants {
4-
public static final int SIZE_LOGLINE = Integer.BYTES * 4 + Long.BYTES * 2 + Byte.BYTES;
4+
public static final int SIZE_LOGLINE = Integer.BYTES * 4 + Long.BYTES * 2 + Byte.BYTES * 2;
55
public static final byte DEVIDER_SYMBOL = 28;
66
}

0 commit comments

Comments
 (0)