Questions tagged [filechannel]

In Java FileChannel is an abstract class for reading, writing, mapping, and manipulating a file

In Java FileChannel is an abstract class for reading, writing, mapping, and manipulating a file.

A file channel is a SeekableByteChannel that is connected to a file.

It has a current position within its file which can be both queried and modified.

The file itself contains a variable-length sequence of bytes that can be read and written and whose current size can be queried.

The size of the file increases when bytes are written beyond its current size; the size of the file decreases when it is truncated.

The file may also have some associated metadata such as access permissions, content type, and last-modification time; this class does not define methods for metadata access.

More info

193 questions
0
votes
1 answer

Having trouble releasing a Java FileLock

I haven't worked with nio much and I'm having some trouble with releasing a FileLock. Basically, in JVM-A I have a NON-SHARABLE write lock on a file which looks something like this: File lockfile = new File("m.lock"); RandomAccessFile writeFile =…
Michael Remijan
  • 687
  • 7
  • 22
0
votes
1 answer

Why does changing the way you initialise RandomAccessFile objects change FileChannel performance?

Im investigating the possibility of re-writing some code that bottlenecks on disk writes into java. The javadoc does not make clear why the first two code loops below would perform so differently to the second two loops: public void…
Jay
  • 19,649
  • 38
  • 121
  • 184
0
votes
4 answers

Java - Process bytes as they are being read from a file

Is there a way to have one thread in java make a read call to some FileInputStream or similar and have a second thread processing the bytes being loaded at the same time? I've tried a number of things - my current attempt has one thread running…
Chris Kitching
  • 2,559
  • 23
  • 37
0
votes
2 answers

Is there a way to read and write using the same FileChannel?

I am new to Java NIO. I am seeing that a FileChannel object has both read and write methods. But I am unable to read and write using the same FileChannel at a single point of time. Is there a way to do so?
gnreddy
  • 2,393
  • 4
  • 22
  • 18
0
votes
3 answers

android : faster solution to copying one file to another

I am copying files using BufferedInputStream . I copy byte[] in loop. This is quite slow for big files. I saw the FileChannel structure. I tried using this also. I want to know if FileChannel is better than using IOSTreams. During my testings, i am…
png
  • 4,368
  • 7
  • 69
  • 118
0
votes
2 answers

Java-NIO: Use FileChannel.read() with offset-address / NullPointer

Does anyone know how to use the FileChannel.read(ByteBuffer[],int,int)-method of java-NIO to read just a certain part of a file? ByteBuffer[] bb = new ByteBuffer[(int) fChannel.size()]; fChannel.read(bb, offsetAddress, endAddress); Throws a…
chollinger
  • 1,097
  • 5
  • 20
  • 34
0
votes
1 answer

Unexplained ClosedByInterruptException. Java FileChannel Bug?

Rarely, my production application encounters an unexpected ClosedByInterruptException when invoking methods on a FileChannel. According to Java documentation, this occurs when the invoking thread is in the interrupted state. Interestingly, my…
Elliot
  • 189
  • 8
-1
votes
1 answer

Multithread AES encryption in Java

As the title say i'm trying to encrypt a file using 2 thread and to decrypt using 1 thread. Since encryption isn't thread safe i use FileChannel to specify the position where to read in the second thread. I am using a 512 byte buffer so i divide the…
Marcus34
  • 1
  • 2
-1
votes
2 answers

Spaces added when writing files

I'm modifying the source code of H2 MVStore 1.4.191 to write files by doing some thread sleep. The big change is that the file is not written in one time anymore, but by 2^16 bytes chunks. MVStore uses java nio FileChannel and ByteBuffer to write…
Joss29
  • 19
  • 2
-1
votes
1 answer

Open file descriptors in lsof as (deleted)

I have in my java process code that opens a file for writing using Files.newOutputStream which is inside the try-with-resources statement. After I finishing writing the files (all written in the same way) and closed. They deleted together with the…
SlavaG
  • 518
  • 8
  • 28
-1
votes
1 answer

java nio socketChannel.write() missing bytes

System.out.println(" @ bBuffer = " + bBuffer.capacity()); headerBuffer.rewind(); socketChannel.write(headerBuffer); int writen = socketChannel.write(bBuffer); System.out.println(" @ writen = " + writen); bBuffer is an object of type ByteBuffer…
dj lee
  • 1
  • 1
-1
votes
1 answer

Not able to read file using java.nio.channels.FileChannel

I am doing following: - creating an empty file - locking file - write to file - reading back the content public class TempClass { public static void main(String[] args) throws Exception{ File file = new File("c:/newfile.txt"); String…
Mahesha999
  • 22,693
  • 29
  • 116
  • 189
-3
votes
1 answer

How to debug "Java NIO Socket Channel mismatch in size of sent and received bytes"?

Please look at this question. This is exact what I'm looking for but I didn't reach it yet. I'm sending multiple of images over a socketChannel. I try to attach the image size into a (cleared ByteBuffer) and attach then the image data into the same…
AppFell
  • 1
  • 1
1 2 3
12
13