Check plain text after downloading
This commit is contained in:
1 parent
47c9d48787
commit
7b95bc804a
5 files changed
+86
-44
No files matched your search
@@ -61,6 +61,7 @@ import com.hippo.yorozuya.Utilities;
|
||||
import com.hippo.yorozuya.collect.SparseJLArray;
|
||||
import com.hippo.yorozuya.thread.PriorityThread;
|
||||
import com.hippo.yorozuya.thread.PriorityThreadFactory;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -1172,7 +1173,6 @@ public final class SpiderQueen implements Runnable {
|
||||
}
|
||||
|
||||
// Download image
|
||||
OutputStreamPipe pipe = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
if (DEBUG_LOG) {
|
||||
@@ -1208,49 +1208,91 @@ public final class SpiderQueen implements Runnable {
|
||||
extension = GalleryProvider2.SUPPORT_IMAGE_EXTENSIONS[0];
|
||||
}
|
||||
|
||||
// Get out put pipe
|
||||
pipe = mSpiderDen.openOutputStreamPipe(index, extension);
|
||||
if (null == pipe) {
|
||||
// Can't get pipe
|
||||
error = GetText.getString(R.string.error_write_failed);
|
||||
response.close();
|
||||
break;
|
||||
}
|
||||
|
||||
long contentLength = responseBody.contentLength();
|
||||
is = responseBody.byteStream();
|
||||
pipe.obtain();
|
||||
OutputStream os = pipe.open();
|
||||
|
||||
final byte data[] = new byte[1024 * 4];
|
||||
long receivedSize = 0;
|
||||
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
int bytesRead = is.read(data);
|
||||
if (bytesRead == -1) {
|
||||
OutputStreamPipe osPipe = null;
|
||||
try {
|
||||
// Get out put pipe
|
||||
osPipe = mSpiderDen.openOutputStreamPipe(index, extension);
|
||||
if (osPipe == null) {
|
||||
// Can't get pipe
|
||||
error = GetText.getString(R.string.error_write_failed);
|
||||
response.close();
|
||||
break;
|
||||
}
|
||||
os.write(data, 0, bytesRead);
|
||||
receivedSize += bytesRead;
|
||||
// Update page percent
|
||||
if (contentLength > 0) {
|
||||
mPagePercentMap.put(index, (float) receivedSize / contentLength);
|
||||
}
|
||||
// Notify listener
|
||||
notifyPageDownload(index, contentLength, receivedSize, bytesRead);
|
||||
}
|
||||
os.flush();
|
||||
|
||||
// check download size
|
||||
if (contentLength >= 0) {
|
||||
if (receivedSize < contentLength) {
|
||||
Log.e(TAG, "Can't download all of image data");
|
||||
error = "Incomplete";
|
||||
forceHtml = true;
|
||||
continue;
|
||||
} else if (receivedSize > contentLength) {
|
||||
Log.w(TAG, "Received data is more than contentLength");
|
||||
long contentLength = responseBody.contentLength();
|
||||
is = responseBody.byteStream();
|
||||
osPipe.obtain();
|
||||
OutputStream os = osPipe.open();
|
||||
|
||||
final byte[] data = new byte[1024 * 4];
|
||||
long receivedSize = 0;
|
||||
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
int bytesRead = is.read(data);
|
||||
if (bytesRead == -1) {
|
||||
response.close();
|
||||
break;
|
||||
}
|
||||
os.write(data, 0, bytesRead);
|
||||
receivedSize += bytesRead;
|
||||
// Update page percent
|
||||
if (contentLength > 0) {
|
||||
mPagePercentMap.put(index, (float) receivedSize / contentLength);
|
||||
}
|
||||
// Notify listener
|
||||
notifyPageDownload(index, contentLength, receivedSize, bytesRead);
|
||||
}
|
||||
os.flush();
|
||||
|
||||
// check download size
|
||||
if (contentLength >= 0) {
|
||||
if (receivedSize < contentLength) {
|
||||
Log.e(TAG, "Can't download all of image data");
|
||||
error = "Incomplete";
|
||||
forceHtml = true;
|
||||
continue;
|
||||
} else if (receivedSize > contentLength) {
|
||||
Log.w(TAG, "Received data is more than contentLength");
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (osPipe != null) {
|
||||
osPipe.close();
|
||||
osPipe.release();
|
||||
}
|
||||
}
|
||||
|
||||
InputStreamPipe isPipe = null;
|
||||
try {
|
||||
// Get InputStreamPipe
|
||||
isPipe = mSpiderDen.openInputStreamPipe(index);
|
||||
if (isPipe == null) {
|
||||
// Can't get pipe
|
||||
error = GetText.getString(R.string.error_reading_failed);
|
||||
break;
|
||||
}
|
||||
|
||||
// Check plain txt
|
||||
isPipe.obtain();
|
||||
InputStream inputStream = new BufferedInputStream(isPipe.open());
|
||||
boolean isPlainTxt = true;
|
||||
for (;;) {
|
||||
int b = inputStream.read();
|
||||
if (b == -1) {
|
||||
break;
|
||||
}
|
||||
if (b > 126) {
|
||||
isPlainTxt = false;
|
||||
}
|
||||
}
|
||||
if (isPlainTxt) {
|
||||
error = GetText.getString(R.string.error_reading_failed);
|
||||
break;
|
||||
}
|
||||
} finally {
|
||||
if (isPipe != null) {
|
||||
isPipe.close();
|
||||
isPipe.release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1274,10 +1316,6 @@ public final class SpiderQueen implements Runnable {
|
||||
forceHtml = true;
|
||||
} finally {
|
||||
IOUtils.closeQuietly(is);
|
||||
if (null != pipe) {
|
||||
pipe.close();
|
||||
pipe.release();
|
||||
}
|
||||
|
||||
if (DEBUG_LOG) {
|
||||
Log.d(TAG, "End download image " + index);
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
<string name="error_invalid_number">非法数字</string>
|
||||
<string name="error_please_login_first">请先登陆</string>
|
||||
<string name="error_empty_html">页面内容为空</string>
|
||||
<string name="error_cant_get_image">无法获取图片</string>
|
||||
|
||||
<string name="kokomade_tip">设置->Eh->画廊站点->e-hentai</string>
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
<string name="error_invalid_number">非法數字</string>
|
||||
<string name="error_please_login_first">請先登陸</string>
|
||||
<string name="error_empty_html">頁面內容為空</string>
|
||||
<string name="error_cant_get_image">無法獲取圖片</string>
|
||||
|
||||
<string name="kokomade_tip">設置->Eh->畫廊站點->e-hentai</string>
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
<string name="error_invalid_number">無效的數字</string>
|
||||
<string name="error_please_login_first">請先登陸</string>
|
||||
<string name="error_empty_html">頁面內容為空</string>
|
||||
<string name="error_cant_get_image">無法獲取圖片</string>
|
||||
|
||||
<string name="kokomade_tip">設定->Eh->圖庫站台->e-hentai</string>
|
||||
|
||||
|
||||
@@ -134,6 +134,7 @@
|
||||
<string name="error_invalid_number">Invalid number</string>
|
||||
<string name="error_please_login_first">Please login first</string>
|
||||
<string name="error_empty_html">Empty page</string>
|
||||
<string name="error_cant_get_image">Can\'t get image</string>
|
||||
|
||||
<string name="kokomade_tip">Settings->Eh->Gallery Site->e-hentai</string>
|
||||
|
||||
|
||||
Reference in new issue
Block a user