I am reading a data stream from a tcp socket. All of this data is sent into a byte array :
DataInputStream in = new DataInputStream(mysource.getInputStream());
FileOutputStream output = new FileOutputStream(path);
int len;
byte buffer[] = new byte [8192];
while(len = in.read(buffer)) !=-1){
output.write(buffer);
}
output.close();
As the stream is being read, I would like to detect a specific 4 bytes patern that repeats itself randomly.
I tried using a for
statement to go through all the data once it's been saved but this solution is highly inefficient.
Is there any way of doing this in real time ?