Clone DataInputStream

  • Replies:1
jvb2008
  • Forum posts: 1

Apr 7, 2016, 11:25:44 AM via Website

Hello all,

I am creating an app for Android and I need to save in two different variables the same part (64B) of a stream I have received (DataInputStream). How can I clone the stream in order to for save in two different variables the same part of this stream? Otherwise, how can I position the pointer in the stream in order to read twice the same part of the stream?

I am using this:

DataInputStream in;
in.read(data,0 , numBytesRead);

Thanks so much,

Reply
Vladimir S.
  • Forum posts: 266

Apr 7, 2016, 4:51:06 PM via Website

Hello.

You are using byte array named "data" to read part of stream, so just copy it to another byte array after reading:

in.read(data,0 , numBytesRead);
data2 = data;

there data2 is another byte array, but in this case both will reference to one object. If you need to separate them, use System.arraycopy().

Reply