提交 7c92925c authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Pass byte[] to DataUtils.parseChecksummedMap()

上级 712a13ae
......@@ -676,11 +676,12 @@ public final class DataUtils {
/**
* Parse a key-value pair list and checks its checksum.
*
* @param s the list
* @param bytes encoded map
* @return the map without mapping for {@code "fletcher"}, or {@code null} if checksum is wrong
* @throws IllegalStateException if parsing failed
*/
public static HashMap<String, String> parseChecksummedMap(String s) {
public static HashMap<String, String> parseChecksummedMap(byte[] bytes) {
String s = new String(bytes, StandardCharsets.ISO_8859_1).trim();
HashMap<String, String> map = New.hashMap();
StringBuilder buff = new StringBuilder();
for (int i = 0, size = s.length(); i < size;) {
......@@ -693,7 +694,7 @@ public final class DataUtils {
if (i - startKey == 8 && s.regionMatches(startKey, "fletcher", 0, 8)) {
DataUtils.parseMapValue(buff, s, i + 1, size);
int check = (int) Long.parseLong(buff.toString(), 16);
byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
bytes = s.getBytes(StandardCharsets.ISO_8859_1);
if (check == DataUtils.getFletcher32(bytes, startKey - 1)) {
return map;
}
......
......@@ -575,9 +575,7 @@ public final class MVStore {
fileHeaderBlocks.get(buff);
// the following can fail for various reasons
try {
String s = new String(buff, 0, BLOCK_SIZE,
StandardCharsets.ISO_8859_1).trim();
HashMap<String, String> m = DataUtils.parseChecksummedMap(s);
HashMap<String, String> m = DataUtils.parseChecksummedMap(buff);
if (m == null)
continue;
int blockSize = DataUtils.readHexInt(
......@@ -797,8 +795,7 @@ public final class MVStore {
end - Chunk.FOOTER_LENGTH, Chunk.FOOTER_LENGTH);
byte[] buff = new byte[Chunk.FOOTER_LENGTH];
lastBlock.get(buff);
String s = new String(buff, StandardCharsets.ISO_8859_1).trim();
HashMap<String, String> m = DataUtils.parseChecksummedMap(s);
HashMap<String, String> m = DataUtils.parseChecksummedMap(buff);
if (m != null) {
int chunk = DataUtils.readHexInt(m, "chunk", 0);
Chunk c = new Chunk(chunk);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论