Display path string and path bytes when an error occurs

This commit is contained in:
apriestman 2021-05-27 10:58:31 -04:00
parent faf4e9a70a
commit f4d521cb7c

View File

@ -1309,7 +1309,8 @@ class SevenZipExtractor {
}
if (tokens.size() != byteTokens.size()) {
logger.log(Level.WARNING, "Could not map path bytes to path string");
logger.log(Level.WARNING, "Could not map path bytes to path string (path string: \"{0}\", bytes: {1})",
new Object[]{filePath, bytesToString(filePathBytes)});
return addNode(rootNode, tokens, null);
}
}
@ -1317,6 +1318,21 @@ class SevenZipExtractor {
return addNode(rootNode, tokens, byteTokens);
}
/**
* Convert byte array to string representation.
*
* @param bytes Byte array
*
* @return Byte array as lower case hex string.
*/
private String bytesToString(byte[] bytes) {
StringBuilder result = new StringBuilder();
for (byte b : bytes) {
result.append(String.format("%02x", b));
}
return result.toString();
}
/**
* recursive method that traverses the path
*