filechannel

How to avoid OutOfMemoryError when using Bytebuffers and NIO?

I'm using ByteBuffers and FileChannels to write binary data to a file. When doing that for big files or successively for multiple files, I get a OutOfMemoryError exception. I've read elsewhere that using Bytebuffers with NIO is broken and should be avoided. Does any of you already faced this kind of problem and found a solution to effici...

Java: Reading an ASCII file with FileChannel and ByteArrays.

I have the following code: String inputFile = "somefile.txt"; FileInputStream in = new FileInputStream(inputFile); FileChannel ch = in.getChannel(); ByteBuffer buf = ByteBuffer.allocateDirect(BUFSIZE); // BUFSIZE = 256 /* read the file into a buffer, 256 bytes at a time */ int rd; while ( (rd = ch...

Does RandomAccessFile.close() internally call FileChannel.force()?

I am using RandomAccessFile to perform some writes to a file as part of a transaction. Before I commit my transaction, I want to be absolutely sure that the data is written to disk. Calling force(boolean) on the RAF's FileChannel appears to provide this guarantee, but is it called implicitly when I close the file, or do I have to call ...

In-memory version of Java's FileChannel

I'm in the process of making some changes to a library that I'm using. In order to reduce memory usage the library is writing its temporary data to disk instead of keeping it in memory. However, for my usage scenario it is more efficient to keep it in memory. It also has some concurrency issues, because it has constant names for its temp...

Any code tips for speeding up random reads from a Java FileChannel?

I have a large (3Gb) binary file of doubles which I access (more or less) randomly during an iterative algorithm I have written for clustering data. Each iteration does about half a million reads from the file and about 100k writes of new values. I create the FileChannel like this... f = new File(_filename); _ioFile = new RandomAccess...

Reading a GZIP file from a FileChannel (Java NIO)

I need to read/unpack a .gz file given a FileChannel. I've played around with extracting GZIP archives using GZIPInputStream, but this won't take a FileChannel. I don't have access to the original FileInputStream that the FileChannel was taken from. If someone could tell me a good way (or at least any way) of reading GZIP from a FileC...

Java Rolling File Creation Fails when attempting to read simultaneously

I am using java.util logging classes to create a rolling file appender. I want to create a log reader that reads from these logs as data is written to them. The rolling log appender code works fine on its own. But once I start the reader thread new files are not created i.e. if rolling log appender is set to use 5 files it will create ...