在ListView中查看JavaFX中的大型日志文件 [英] Viewing large log files in JavaFX in a ListView

查看:438
本文介绍了在ListView中查看JavaFX中的大型日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个JavaFx App来查看日志文件.每个文件都在一个新选项卡中打开,我遍历文本并将其添加到列表视图中.我创建了一个cellfactory,以突出显示列表文件中的某些文本,并且一切正常.

I have written a JavaFx App to view log files. The files are opened each in a new tab and I run through the text and add it to the list views. I have created a cellfactory to highlight certain text in the list file and that is all working.

问题在于日志文件在800-1300Mb之间.一次打开3-4,JVM达到了内存限制.

The problem is that the log files are between 800-1300Mb. Opening 3-4 at once and the JVM reached its memory limit.

还有另一种方法可以使当前仅在内存中的列表视图中显示文本,并且当我滚动时将更多内容加载到内存中吗?

Is there another way to do this to only have the text currently being displayed in the list view in memory and as I scroll load more into memory?

我需要能够使用滚动条进行滚动.我搜索了Google,发现了很多相同的问题.人们想在几年前使用Java(在Swing中)显示1-10Gb大型文本的地方,但没有答案:

I need to be able to scroll using the scroll bars. I have search Google and I have found plenty of the same question. Where people want to display a large text 1-10Gb files in Java (In Swing) dated back a few years ago and there is no answer:

  • http://www.dreamincode.net/forums/topic/224430-reading-in-large-text-files1gb-10gb-java-swing/
  • http://www.javaprogrammingforums.com/awt-java-swing/9577-diplay-large-text-jtextarea-2gb.html
  • http://www.dreamincode.net/forums/topic/224430-reading-in-large-text-files1gb-10gb-java-swing/

我看了一下分页,但是我需要能够使用滚动条,而且看起来很需要.用户不应该知道某些部分不在内存中.他们滚动并显示下一行.

I had a look at pagination but I need to be able to use the scroll bars and I need it seemlesly. The user should not know that certain portions is not in memory. They scroll and it display the next lines.

有没有人在Java中找到解决方案(Swing或JavaFX)?

Have anyone ever found a solution to this in Java (Swing or JavaFX)?

推荐答案

关键是忘记行号.除非每一行的字节数完全相同,否则行号是一种抽象,要求您读取整个文件以查找下一行的位置.

The key is to forget about line numbers. Unless each line is exactly the same number of bytes long, line numbers are an abstraction that requires you to read the whole file to find the position of the next line.

请考虑字节位置,因为您可以使用

Instead think byte position, since you can seek to that without reading the bytes between, by using a RandomAccessFile or a SeekableByteChannel. Of course, then you have to return the byte position to the client app so you can return it to the server when you are getting the next page.

使用滚动条进行分页是一种简洁而直观的技巧.困难的部分是重新编写滚动条以显示整个文件,而不是仅显示内存中的文件.

Using the scrollbar to do paging is a neat and intuitive trick. The hard part is re-writing the scrollbar to show the whole file instead of just what you have in memory.

注意:刚刚注意到了这个问题的年龄...但是希望我的评论对下一个搜索者有用.

这篇关于在ListView中查看JavaFX中的大型日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆