-1

I have this input stream from socket and I want to check if the input stream that I just read is an string, int, image etc...

Currently I am using DataInputStream..

Is there a way to check the type through byte or something else??

user207421
  • 305,947
  • 44
  • 307
  • 483
Rod_Algonquin
  • 26,074
  • 6
  • 52
  • 63
  • Try this question: http://stackoverflow.com/questions/51438/getting-a-files-mime-type-in-java/8973468#8973468 is not exactly the same as you are asking, but it can help you, maybe you can write in a Temp file the first 1024 bytes as a sample and then use the accepted answer of such question. – morgano May 01 '14 at 23:58

1 Answers1

0

Not unless you prepend each data item with a type tag.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • is DataInputStream fast than ObjectInputStream??? Because I will consider using the ObjectInputStrean it if it is faster.. – Rod_Algonquin May 02 '14 at 00:05
  • Define 'fast'. The limiting factor is the network, not the class. Serialization has its overheads but if you need it you need it. – user207421 May 02 '14 at 00:19