java - Parsing DAT file using bouncy castle
问题描述
The dat file
is being extracted. There is a lot of data in it. However, some data is published without problems, while others indicate errors.
Here is my code
public void Decode(File filePath) {
byte[] blockBuffer = new byte[0x800];
ASN1InputStream bIn;
ASN1Primitive obj;
try {
FileInputStream fileInput = new FileInputStream(filePath);
notFound = false;
String checkFileSql = "SELECT count(*) AS cnt FROM table_name WHERE filename=?";
PreparedStatement checkStmt = conn.prepareStatement(checkFileSql);
checkStmt.setString(1, filePath.getName());
ResultSet rs = checkStmt.executeQuery();
if (rs.next()) {
if (rs.getInt("cnt") == 0) {
isExist = false;
String insertSql = "INSERT..."
stmt = conn.prepareStatement(insertSql);
while (fileInput.available() > 0) {
if (fileInput.read(blockBuffer) > 0) {
bIn = new ASN1InputStream(blockBuffer);
boolean endOfBlock = false;
while (bIn.available() > 4 && !endOfBlock) {
if (bIn.markSupported()) {
bIn.mark(4);
if (bIn.read() == 0xff && bIn.read() == 0xff && bIn.read() == 0xff
&& bIn.read() == 0xff) {
endOfBlock = true;
}
bIn.reset();
if (!endOfBlock) {
obj = (ASN1Primitive) bIn.readObject();
Record cr = new Record();
cr.parseObject(obj);
if (cr.cdrType != null) {
if (cr.cdrType == cr.pgwCDR || cr.cdrType == cr.sgwCDR) {
}
}
}
}
}
}
}
int[] rslt = stmt.executeBatch();
for (int i = 0; i < rslt.length; i++) {
inserted += rslt[i];
}
conn.commit();
stmt.close();
fileInput.close();
} else {
isExist = true;
}
}
rs.close();
checkStmt.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SQLException e) {
exceptionStr = e.getMessage();
e.printStackTrace();
}
}
Error message
java.io.EOFException: DEF length 224 object truncated by 90 at org.bouncycastle.asn1.DefiniteLengthInputStream.read(Unknown Source) at org.bouncycastle.util.io.Streams.readFully(Unknown Source) at org.bouncycastle.util.io.Streams.readFully(Unknown Source) at org.bouncycastle.asn1.DefiniteLengthInputStream.toByteArray(Unknown Source) at org.bouncycastle.asn1.ASN1StreamParser.readTaggedObject(Unknown Source) at org.bouncycastle.asn1.BERTaggedObjectParser.getLoadedObject(Unknown Source) at org.bouncycastle.asn1.ASN1StreamParser.readVector(Unknown Source) at org.bouncycastle.asn1.ASN1StreamParser.readTaggedObject(Unknown Source) at org.bouncycastle.asn1.ASN1InputStream.buildObject(Unknown Source) at org.bouncycastle.asn1.ASN1InputStream.readObject(Unknown Source)
Here is parsing data code
public void parseObject(ASN1Primitive obj) {
if (obj instanceof DERTaggedObject) {
DERTaggedObject.getInstance(obj);
DERTaggedObject cdrObj = (DERTaggedObject) DERTaggedObject.getInstance(obj);
cdrType = cdrObj.getTagNo();
if (cdrObj.getObject() instanceof DLSequence) {
DLSequence callModule = (DLSequence) DLSequence.getInstance(cdrObj.getObject());
for (int i = 0; i < callModule.size(); i++) {
if (callModule.getObjectAt(i) instanceof DERTaggedObject) {
DERTaggedObject eventModule = (DERTaggedObject) DERTaggedObject
.getInstance(callModule.getObjectAt(i));
int tag = eventModule.getTagNo();
distValues(cdrType, tag, eventModule);
}
}
}
}
}
The line indicating the error message
obj = (ASN1Primitive) bIn.readObject();
解决方案
推荐阅读
- nuxt.js - Nuxt.js 不接受问题报告?
- asp.net-core - 发布依赖于第三方 dll 的框架
- javascript - 如何使用 ajax 在同一个 servlet 中实现 doPost() 和 doGet() 请求?
- reactjs - onClick 循环匹配 API 属性/产品 - ReactJS
- c# - 使用代码将材质应用于 Unity 中的所有其他对象
- javascript - 为什么 MobX 不能用作状态容器?
- python-3.x - Python 中的快速 GUID
- c++ - 将参数包解压缩到 std::initializer_list 中?
- r - 匹配字符范围内的元素 n 次
- tfs - VSTS - 如果已删除,则恢复团队项目