user1221483
user1221483

Reputation: 431

Java Netty data break

I am using in my project netty-3.5.3.Final to transfer files. Unfortunately, sometimes I get the wrong data. For example, I am downloading a file size of 1 GB. After receiving the file contains 5 "mistakes". All errors affect the individual bytes. This is a "logical" changeenter image description here

Ë -> ë  (CB -> EB)  C+2 = E
À -> à  (C0 -> E0)  C+2 = E
Ú -> ú  (DA -> FA)  D+2 = F
œ -> ¼  (9C -> BC)  9+2 = B
 -> $   (04 -> 24)  0+2 = 2
e.t.c.
(Not every Ë becomes ë, only ~1/100000000...000..)

The process of obtaining the file:

ChannelBuffer buf = (ChannelBuffer) e.getMessage(); //SimpleChannelHandler.messageReceived(...)..
 ByteBuffer bbuf = buf.toByteBuffer();
RandomAccessFile bos = new RandomAccessFile(...,"rw");
bos.write(bbuf.array(), 0, bbuf.position());
bos.close();

Data are not subject to any changes. Why can it happen?

Upvotes: 1

Views: 191

Answers (1)

Norman Maurer
Norman Maurer

Reputation: 23567

I think your write code is wrong.

Could you try this:

ChannelBuffer buf = ...
OutputStream out = new FileOutputStream(...)
buf.readBytes(out, buf.readableBytes());
out.close();

Upvotes: 1

Related Questions