In a method I need a BufferedReader wrapping a DataInputStream as a parameter. I want to declare the method as this :
public void firstPass(BufferedReader inStream){ // some code ... }
But I don’t know how I can check whether inStream is wrapping a DataInputStream.
I’ve tried
public static void firstPass(BufferedReader inStream){
if (inStream instanceof DataInputStream){
}
}
but the code can’t compile (Eclispe does not accept the code : “Incompatible conditional operand types BufferedReader and DataInputStream”).
Why this need ? Because I want to use with the same variable inStream :
- the method readLine() from BufferedReader
- the method readDouble() from DataInputStream
So I need a stream which chains both classes.
I’m programming with Java 7 JDK.
Could someone help me please ? Thanks in advance.
A DataInputStream can never be a instance of BufferedReader – they are both in separate class hierarchies.
A BufferedReader wraps another Reader, not a Stream.
You can bridge from Streams to Readers using an InputStreamReader.
Reading doubles and lines from the same Reader doesn’t really makes sense – one is raw binary data, the other is character data. Maybe you need to read a textual encoding of the doubles, and parse this using
Double.parseDouble(text).