Any way to clear the data of a DataInputStream in Java? (an Android application)
<p>First of all thanks for helping and apologize for my English, I'm from Spain.</p>

<p>I'm receiving images from a computer via TCP using a socket. For every image I get the number of layers (RGB), rows and columns of every layer, then the values of each pixel. To collect the data I use a <code>DataInputStream</code>.</p>

<p>Usually it works fine, but sometimes I get wrong values of the number of rows and columns causing problems in the next functions i.e. the app freezes waiting for data that will never be sent, or simply causes an index error on the array which holds the data.</p>

<p>So I want to clear the data if the number of rows and columns is too high, but I can't find any way to clear the <code>DataInputStream</code>, full of wrong bytes of pixel values.</p>

<p>In addition, I dont't know the size of the <code>DataInputStream</code>, because the size is calculated the following way: <code>Layers * Width * height</code>. So if I don't get the real values of this camps, I can't know the number of bytes that I have to skip.</p>

<p>Questions:</p>

<ol>
<li><p>Anyone knows some way to just clear a <code>DataInputStream</code>?</p></li>
<li><p>If not, should I use another type of Input way like
<code>BufferedInputStream</code>?</p></li>
</ol>
