如何确定BufferedReader对象的输入?换句话说,我想静态分析程序,以确定BufferedReader对象的输入是套接字还是文件。
例如,在下面的代码中,我希望能够识别bfReader对象实际上是从端口号为1024的套接字读取的。如何静态获取此信息?它是否应该出现在程序的AST,类型或控制流程图中?
import java.io.*;
import java.net.*;
public class Bob {
private
int bobFortune = 1000;
public static void main(String[] args) throws Exception{
Bob bob = new Bob();
bob.run();
}
public void run() throws Exception{
ServerSocket serverSocket = new ServerSocket(1024);
Socket socket = serverSocket.accept();
InputStreamReader inputReader = new InputStreamReader(socket.getInputStream());
BufferedReader bfReader = new BufferedReader(inputReader);
int aliceFortune = Integer.valueOf(bfReader.readLine());
if (bobFortune > aliceFortune)
System.out.println("Bob is richer");
else
System.out.println("Alice is richer");
bfReader.close();
inputReader.close();
serverSocket.close();
}
}
非常感谢!