Java File Cursor
Is there some library for using some sort of cursor over a file? I have to read big files, but can't afford to read them all at once into memory. I'm aware of java.nio, but I want to use a higher level API.
A little backgrond: I have a tool written in GWT that analyzes submitted xml documents and then pretty prints the xml, among other things. Currently I'm writing the pretty printed xml to a temp file (my lib would throw me an OOMException if I use plain Strings), but the temp file's size are approaching 18 megs, I can't afford to respond a GWT RPC with 18 megs :)
So I can have a widget to show only a portion of the xml (check this example), but I need to read the corresponding portion of the file.
Asked by: Joyce390 | Posted: 23-01-2022
Answer 1
Have you taken a look at using FileChannels (i.e., memory mapped files)? Memory mapped files allow you to manipulate large files without bringing the entire file into memory.
Here's a link to a good introduction: http://www.developer.com/java/other/article.php/1548681
Answered by: Marcus834 | Posted: 24-02-2022Answer 2
Maybe java.io.RandomAccessFile can be of use to you.
Answered by: Alissa432 | Posted: 24-02-2022Answer 3
I don't understand when you ask for a "higher level API" when positioning the file pointer. It is the higher levels that may need to control the "cursor". If you want control, go lower, not higher.
I am certain that lower level Java io clases allow you to position yourself anywhere within any sized file without reading anything into memory until you want to. I know I have done it before. Try RandomAccessFile as one example.
Answered by: Anna113 | Posted: 24-02-2022Similar questions
Performance question: Fastest way to convert hexadecimal char to its number value in Java?
I want to convert from char representing a hexadecimal value (in upper or lower case) to byte, like
'0'->0, '1' -> 1, 'A' -> 10, 'a' -> 10, 'f' -> 15 etc...
I will be calling this method extremely often, so performance is important. Is there a faster way than to use a pre-initialized HashMap<Character,Byte> to get the value from?
Answer
performance - Java very large heap sizes
Closed. This question needs to be more focused. It ...
java - Is there a performance difference between Javac debug on and off?
If I switch on the generating of debug info with Javac then the class files are 20-25% larger. Has this any performance effects on running the Java program? If yes on which conditions and how many. I expect a little impact on loading the classes because the files are larger but this should be minimal.
performance - Size of a byte in memory - Java
I have heard mixed opinions over the amount of memory that a byte takes up in a java program.
I am aware you can store no more than +127 in a java byte, and the documentation says that a byte is only 8 bits but here I am told that it actua...
java - How to improve Netbeans performance?
Is there a real way to get Netbeans to load and work faster?
It is too slow and gets worse when you have been coding for some time. It eats all my RAM.
I am on a Windows machine, specifically Windows Server 2008 Datacenter Edition x64,
4Gb of RAM, 3Ghz Core 2 Duo processor, etc. I am using the x64 JDK. I use the NOD32 Antivirus since for me it is the best in machine performance.
In Task Manage...
java - Is there a performance difference between a for loop and a for-each loop?
What, if any, is the performance difference between the following two loops?
for (Object o: objectArrayList) {
o.DoSomething();
}
and
for (int i=0; i<objectArrayList.size(); i++) {
objectArrayList.get(i).DoSomething();
}
performance - Accelerate 2D images in Java *without* disturbing JMenus
Already implemented performance boosters :
- Get compatible image of GraphicsConfiguration to draw on
- Enable OpenGL pipeline in 1.5: Not possible due to severe artifacts
So far I am fine, the main profiled bottleneck of the program is drawing an image with several thousand tiles. Unfortunately it is not regular, else I simply could set pixels
and scale them.
I accerelated the image with VolatileImages and own ren...
performance - Measuring Java execution time, memory usage and CPU load for a code segment
For a particular segment of Java code, I'd like to measure:
Execution time (most likely thread execution time)
Memory usage
CPU load (specifically attributable to the code segment)
I'm a relative Java novice and am not familiar with how this might be achieved. I've been referred to
Can anyone quantify performance differences between C++ and Java?
Java was initially slow before the JIT but today performance is pretty close to C++. I want to know if someone has done measurable performance comparisons between the two languages? Where does Java fall short when compared to C++? Java provides many productivity gains to developers so they can write applications much quicker because of garbage college, lack of pointers, etc. Applications such as Firefox, Webkit ...
performance - ArrayList vs. Vectors in Java if thread safety isn't a concern
Is there really that much of a difference between the performance of Vector and ArrayList? Is it good practice to use ArrayLists at all times when thread safety isn't an issue?
Still can't find your answer? Check out these amazing Java communities for help...
Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)