Исправление ошибок загрузки постов

This commit is contained in:
Victor 2013-08-29 20:36:24 +03:00
parent f91ddb6a83
commit 2b61d5e990
2 changed files with 12 additions and 11 deletions

View File

@ -16,7 +16,7 @@ import android.widget.ProgressBar;
*/ */
public class ForumPostLoader extends AsyncTask<String, Void, List<ForumPost>> { public class ForumPostLoader extends AsyncTask<String, Void, List<ForumPost>> {
private static final String SEPARATOR = "|$|"; private static final String SEPARATOR = "\\|\\$\\|";
private Context context; private Context context;
private FinishLoadingListener listener; private FinishLoadingListener listener;
@ -39,12 +39,12 @@ public class ForumPostLoader extends AsyncTask<String, Void, List<ForumPost>> {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
ForumPost post = new ForumPost(); ForumPost post = new ForumPost();
String titleAuthor = data[i]; String titleAuthor = data[i * 3];
int breakCharIndex = titleAuthor.indexOf('\n'); int breakCharIndex = titleAuthor.indexOf('\n');
post.setForumTitle(titleAuthor.substring(0, breakCharIndex)); post.setForumTitle(titleAuthor.substring(0, breakCharIndex));
post.setAuthor(titleAuthor.substring(breakCharIndex + 1)); post.setAuthor(titleAuthor.substring(breakCharIndex + 1));
post.setDate(data[i + 1]); post.setDate(data[i * 3 + 1]);
post.setMessage(data[i + 2]); post.setMessage(data[i * 3 + 2]);
postItems.add(post); postItems.add(post);
} }

View File

@ -1,6 +1,5 @@
package com.annimon.client.utils; package com.annimon.client.utils;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
@ -14,16 +13,18 @@ public class InetUtils {
public static synchronized String getTextFromUri(String urlsite) { public static synchronized String getTextFromUri(String urlsite) {
StringBuilder text = new StringBuilder(); StringBuilder text = new StringBuilder();
BufferedReader reader = null; InputStreamReader reader = null;
try { try {
final URL url = new URL(urlsite); final URL url = new URL(urlsite);
reader = new BufferedReader(new InputStreamReader(url.openStream())); reader = new InputStreamReader(url.openStream());
String line; final int bufferSize = 2048;
while ((line = reader.readLine()) != null) { char[] buffer = new char[bufferSize];
text.append(line); int readSize;
while ( (readSize = reader.read(buffer, 0, bufferSize)) != -1 ) {
text.append(buffer, 0, readSize);
} }
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ExceptionHandler.log(ex);
} finally { } finally {
if (reader != null) { if (reader != null) {
try { try {