Java读取.cdr文件
现在我正在尝试编写一个读取 .cdr 文件的程序。 CDR 文件的格式如下所示:
***************
* File header *
***************
File length: 44142 bytes
Header length: 54 bytes
High release identifier: Check the field extension below
High version identifier: Version 6
Low release identifier: Check the field extension below
Low version identifier: Version 6
File opening local timestamp: May 20 00:28 (+02:00 from UTC)
Timestamp of last CDR on file: May 20 01:28 (+02:00 from UTC)
Number of CDRs in the file: 130 CDRs
File sequence number: 386
File closure trigger reason: File open-time limit reached
IP address of node generating the file: ff.ff.ff.ff::ffff:ac10:1438
Lost CDR indicator: 0 CDRs lost
Length of CDR routeing filter: 0 bytes
Length of private extensions: 0 bytes
High release ID extension: Release 13
Low release ID extension: Release 13
这是我的代码:
readBinary-method:
public Collection<Data> readBinary(String file) throws IOException, FileNotFoundException
{
ArrayList<Data> arrayList=new ArrayList<>();
try(DataInputStream dis=new DataInputStream(new BufferedInputStream(new FileInputStream(file))))
{
while (dis.available()>0)
{
arrayList.add(new Data(dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(),dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readInt(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF()));
}
}
return arrayList;
}
main:
public class Main implements Serializable
{
public static void main(String[] args) throws IOException, ClassNotFoundException {
Methoden m = new Methoden();
try {
ArrayList<Data> d1 = (ArrayList<Data>) m.readBinary("172.16.20.5601_-_386.20210520_-_0128+0200.cdr");
System.out.println(d1);
} catch (IOException e) {
e.printStackTrace();
}
}
}
所以我的问题是,当我运行程序时,我收到 EOFException 并且我不明白为什么..
也许有人可以帮助我和我的问题
right now I#m trying to write a program which reads a .cdr-File. The Format of the CDR-File looks like this:
***************
* File header *
***************
File length: 44142 bytes
Header length: 54 bytes
High release identifier: Check the field extension below
High version identifier: Version 6
Low release identifier: Check the field extension below
Low version identifier: Version 6
File opening local timestamp: May 20 00:28 (+02:00 from UTC)
Timestamp of last CDR on file: May 20 01:28 (+02:00 from UTC)
Number of CDRs in the file: 130 CDRs
File sequence number: 386
File closure trigger reason: File open-time limit reached
IP address of node generating the file: ff.ff.ff.ff::ffff:ac10:1438
Lost CDR indicator: 0 CDRs lost
Length of CDR routeing filter: 0 bytes
Length of private extensions: 0 bytes
High release ID extension: Release 13
Low release ID extension: Release 13
This is my code:
readBinary-method:
public Collection<Data> readBinary(String file) throws IOException, FileNotFoundException
{
ArrayList<Data> arrayList=new ArrayList<>();
try(DataInputStream dis=new DataInputStream(new BufferedInputStream(new FileInputStream(file))))
{
while (dis.available()>0)
{
arrayList.add(new Data(dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(),dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readInt(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF()));
}
}
return arrayList;
}
main:
public class Main implements Serializable
{
public static void main(String[] args) throws IOException, ClassNotFoundException {
Methoden m = new Methoden();
try {
ArrayList<Data> d1 = (ArrayList<Data>) m.readBinary("172.16.20.5601_-_386.20210520_-_0128+0200.cdr");
System.out.println(d1);
} catch (IOException e) {
e.printStackTrace();
}
}
}
So my problem is, when i run the program I get an EOFException and I don't get why..
Maybe someone can help me with my problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要读取的第一件事是文件头中的文件长度字段。这可能是一个字节或两个字节 - 检查您的规格。看起来您正在使用 DataInputStream.readUTF 来读取该内容,这不适合读取这样的字段。
您需要根据文件布局来读取。您似乎没有遵循文件布局,因此碰巧尝试读取比应有的更多数据,因此出现异常。
The first thing you need to read is the file length field from the file header. That's probably a single byte or maybe two bytes - check your specification. It looks like you're reading that using DataInputStream.readUTF, which is inappropriate for reading such a field.
You need to read according to the file layout. You don't seem to be following the file layout and consequently happen to be trying to read more data than you should be, thus the exception.