android string inputstream,Android / Java - Converting DataInputStream into String

I currently have a connection established to some middleware, through which I send SQL queries to a database.

I'm having some trouble with converting the DataInputStream to a useable format (Whether or not that is a String). I looked at another StackOverflow question, however this did not resolve my problem since using

in.readLine();

is 'deprecated', whatever that means. I need to be able to read the response from my middleware.

private class NetworkTask extends AsyncTask

{

protected Integer doInBackground(String... params)

{

Message message = networkHandler.obtainMessage();

String ip = "example ip";

int port = 1234;

try

{

InetAddress serverAddr = InetAddress.getByName(ip);

Log.d("EventBooker", "C: Connecting...");

Socket socket = new Socket(serverAddr, port);

DataInputStream in = new DataInputStream(socket.getInputStream());

try

{

Log.d("EventBooker", "C: Connected. Sending command.");

PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);

out.println(params[0]);

networkHandler.sendMessage(message);

Log.d("EventBooker", "C: Sent.");

}

catch (Exception e)

{

Log.e("EventBooker", "S: Error", e);

}

Log.d("EventBooker", "C: Reading...");

Log.d("EventBooker", "C: Response read, closing.");

socket.close();

Log.d("Eventbooker", "C: Closed.");

}

catch (Exception e)

{

Log.e("EventBooker", "C: Error", e);

}

return 1;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值