diff --git a/app/src/main/java/com/hippo/ehviewer/legacy/SpiderInfoCompat.kt b/app/src/main/java/com/hippo/ehviewer/legacy/SpiderInfoCompat.kt
index c9816983d..60d73a1e2 100644
--- a/app/src/main/java/com/hippo/ehviewer/legacy/SpiderInfoCompat.kt
+++ b/app/src/main/java/com/hippo/ehviewer/legacy/SpiderInfoCompat.kt
@@ -1,12 +1,14 @@
package com.hippo.ehviewer.legacy
import com.hippo.ehviewer.spider.SpiderInfo
-import com.hippo.ehviewer.yorozuya.IOUtils
+import okio.buffer
+import okio.source
import java.io.InputStream
fun readLegacySpiderInfo(inputStream: InputStream): SpiderInfo {
+ val source = inputStream.source().buffer()
fun read(): String {
- return IOUtils.readAsciiLine(inputStream)
+ return source.readUtf8LineStrict()
}
fun readInt(): Int {
diff --git a/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.kt b/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.kt
index 490c4cd72..1a9940499 100644
--- a/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.kt
+++ b/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.kt
@@ -68,7 +68,6 @@ import com.hippo.ehviewer.ui.scene.ProgressScene
import com.hippo.ehviewer.util.addTextToClipboard
import com.hippo.ehviewer.util.getParcelableExtraCompat
import com.hippo.ehviewer.util.getUrlFromClipboard
-import com.hippo.ehviewer.yorozuya.IOUtils
import eu.kanade.tachiyomi.util.lang.launchUI
import eu.kanade.tachiyomi.util.lang.withUIContext
import kotlinx.coroutines.delay
@@ -77,8 +76,6 @@ import splitties.systemservices.clipboardManager
import splitties.systemservices.connectivityManager
import java.io.File
import java.io.FileOutputStream
-import java.io.IOException
-import java.io.OutputStream
class MainActivity : EhActivity() {
private lateinit var binding: ActivityMainBinding
@@ -91,15 +88,12 @@ class MainActivity : EhActivity() {
ImageDecoder.decodeBitmap(src, Image.imageSearchDecoderSampleListener)
}.getOrNull() ?: return null
val temp = AppConfig.createTempFile() ?: return null
- var os: OutputStream? = null
- return try {
- os = FileOutputStream(temp)
- bitmap.compress(Bitmap.CompressFormat.JPEG, 90, os)
+ return runCatching {
+ FileOutputStream(temp).use { bitmap.compress(Bitmap.CompressFormat.JPEG, 90, it) }
temp
- } catch (e: IOException) {
+ }.getOrElse {
+ it.printStackTrace()
null
- } finally {
- IOUtils.closeQuietly(os)
}
}
@@ -191,10 +185,15 @@ class MainActivity : EhActivity() {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
- val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment
+ val navHostFragment =
+ supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment
navController = navHostFragment.navController
if (!EhUtils.needSignedIn()) setNavGraph()
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) binding.drawView.addDrawerListener(mDrawerOnBackPressedCallback)
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
+ binding.drawView.addDrawerListener(
+ mDrawerOnBackPressedCallback,
+ )
+ }
binding.navView.setupWithNavController(navController)
// Trick: Tweak NavigationUI to disable multiple backstack
diff --git a/app/src/main/java/com/hippo/ehviewer/yorozuya/IOUtils.java b/app/src/main/java/com/hippo/ehviewer/yorozuya/IOUtils.java
deleted file mode 100644
index 9a1d13a47..000000000
--- a/app/src/main/java/com/hippo/ehviewer/yorozuya/IOUtils.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright 2015 Hippo Seven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hippo.ehviewer.yorozuya;
-
-import java.io.ByteArrayOutputStream;
-import java.io.Closeable;
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-
-public final class IOUtils {
- private static final int EOF = -1;
- private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
-
- private IOUtils() {
- }
-
- /**
- * Close the closeable stuff. Don't worry about anything.
- *
- * @param is the closeable stuff
- */
- public static void closeQuietly(Closeable is) {
- try {
- if (is != null) {
- is.close();
- }
- } catch (IOException e) {
- // Ignore
- }
- }
-
- /**
- * Copy bytes from an InputStream to an
- * OutputStream.
- *
- * @param input the InputStream
- * @param output the OutputStream
- * @return the number of bytes copied
- * @throws IOException
- */
- public static long copy(InputStream input, OutputStream output)
- throws IOException {
- byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
- long count = 0;
- int n;
- while (EOF != (n = input.read(buffer))) {
- output.write(buffer, 0, n);
- count += n;
- }
- return count;
- }
-
- /**
- * Returns the ASCII characters up to but not including the next "\r\n", or
- * "\n".
- *
- * @throws java.io.EOFException if the stream is exhausted before the next
- * newline character.
- */
- public static String readAsciiLine(final InputStream in) throws IOException {
- final StringBuilder result = new StringBuilder(80);
- while (true) {
- final int c = in.read();
- if (c == -1) {
- throw new EOFException();
- } else if (c == '\n') {
- break;
- }
-
- result.append((char) c);
- }
- final int length = result.length();
- if (length > 0 && result.charAt(length - 1) == '\r') {
- result.setLength(length - 1);
- }
- return result.toString();
- }
-
- public static String readString(final InputStream is, String encoding) throws IOException {
- InputStreamReader reader = new InputStreamReader(is, encoding);
- StringBuilder sb = new StringBuilder();
-
- char[] buffer = new char[DEFAULT_BUFFER_SIZE];
- int n;
- while (EOF != (n = reader.read(buffer))) {
- sb.append(buffer, 0, n);
- }
-
- return sb.toString();
- }
-}