0
我有一個使用「windows-1254」編碼的服務器。我的客戶端通過套接字讀取數據並創建一個textview並添加到屏幕上。我有一個編碼問題。TextView和Logcat編碼
這裏是我的客戶:
@Override
public void run() {
try {
InetAddress servAddress = InetAddress.getByName(SERVER_IP);
socked = new Socket(servAddress, SERVERPORT);
input = new BufferedReader(new InputStreamReader(socked.getInputStream(), "windows-1254"));
while(!Thread.currentThread().isInterrupted()) {
String read = input.readLine();
Log.v("Information",read);
// Log.v("Information","msg: " + read);
updateConversationHandler.post(new updateUIThread(read));
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
和我的更新線程:
@Override
public void run() {
TextView tv = new TextView(cont);
tv.setPadding(0,0,0,0);
Log.v("Information", msg);
tv.setLayoutParams(lp);
tv.setTypeface(Typeface.MONOSPACE);
// tv.setText(msg);
tv.setText(makeTextWithColors(msg));
screen.addView(tv);
}
的方法makeTextWithColors做一些分析和添加標籤上色根據ANSI從服務器逃逸的文本具有不會改變文本的任何編碼。
這裏的問題是,當我使用Log.v(「信息」,「味精:」+讀);而不是原來的,我得到額外的換行符。但是,當我將原始文本發佈到日誌貓,不知何故日誌貓刪除這些實際上是我想要的換行符。有沒有一種特殊的換行符,我可以避免在Windows-1254編碼,我不知道?
對於誰想要檢查服務器輸出的人, 服務器IP:www.turkmud.com 端口:4000
在輸出中,有一個基於文本的圖片,你可以看到,和換行符破壞了它們。