diff --git a/app/src/main/java/com/hippo/ehviewer/spider/SpiderQueen.java b/app/src/main/java/com/hippo/ehviewer/spider/SpiderQueen.java index 733baaa8b..4b840af55 100644 --- a/app/src/main/java/com/hippo/ehviewer/spider/SpiderQueen.java +++ b/app/src/main/java/com/hippo/ehviewer/spider/SpiderQueen.java @@ -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); diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 404d49985..008c53ba3 100755 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -92,6 +92,7 @@ 非法数字 请先登陆 页面内容为空 + 无法获取图片 设置->Eh->画廊站点->e-hentai diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index db357c2b6..b3597387a 100755 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -92,6 +92,7 @@ 非法數字 請先登陸 頁面內容為空 + 無法獲取圖片 設置->Eh->畫廊站點->e-hentai diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index e63500f6f..8f4f95eb9 100755 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -92,6 +92,7 @@ 無效的數字 請先登陸 頁面內容為空 + 無法獲取圖片 設定->Eh->圖庫站台->e-hentai diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 23fcee58f..523069aa8 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -134,6 +134,7 @@ Invalid number Please login first Empty page + Can\'t get image Settings->Eh->Gallery Site->e-hentai