From 98bbcc1734c52f2664430ee5a0249566477e40a4 Mon Sep 17 00:00:00 2001 From: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> Date: Sun, 22 Aug 2021 15:16:01 -0500 Subject: [PATCH] Cleanup some intermediate leftovers --- build.gradle | 8 - settings.gradle | 14 -- .../kotlin/mdnet/cache/CachingInputStream.kt | 210 +++++++++--------- src/main/kotlin/mdnet/server/ImageServer.kt | 2 +- 4 files changed, 104 insertions(+), 130 deletions(-) diff --git a/build.gradle b/build.gradle index 19ea743..c1646d8 100644 --- a/build.gradle +++ b/build.gradle @@ -98,13 +98,6 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { } spotless { - java { - targetExclude("build/generated/**/*") - eclipse() - removeUnusedImports() - trimTrailingWhitespace() - endWithNewline() - } kotlin { ktlint("0.40.0").userData(["disabled_rules": "no-wildcard-imports"]) licenseHeaderFile "license_header" @@ -120,7 +113,6 @@ tasks.register("generateVersion", Copy) { into "$buildDir/generated/java" expand templateContext } -//tasks.named(":kaptKotlin").dependsOn generateVersion compileJava.dependsOn generateVersion sourceSets.main.java.srcDir generateVersion diff --git a/settings.gradle b/settings.gradle index 935730c..6353639 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,15 +1 @@ -pluginManagement { - repositories { - gradlePluginPortal() - google() - } - resolutionStrategy { - eachPlugin { - if (requested.id.id == "com.squareup.sqldelight") { - useModule("com.squareup.sqldelight:gradle-plugin:${requested.version}") - } - } - } -} - rootProject.name = 'mangadex_at_home' diff --git a/src/main/kotlin/mdnet/cache/CachingInputStream.kt b/src/main/kotlin/mdnet/cache/CachingInputStream.kt index 9d25e7b..8e13a6d 100644 --- a/src/main/kotlin/mdnet/cache/CachingInputStream.kt +++ b/src/main/kotlin/mdnet/cache/CachingInputStream.kt @@ -1,118 +1,114 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 mdnet.cache; +Mangadex@Home +Copyright (c) 2020, MangaDex Network +This file is part of MangaDex@Home. -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.input.ProxyInputStream; +MangaDex@Home is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.concurrent.ExecutorService; +MangaDex@Home is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. -import static org.apache.commons.io.IOUtils.EOF; +You should have received a copy of the GNU General Public License +along with this MangaDex@Home. If not, see . +*/ +package mdnet.cache -public class CachingInputStream extends ProxyInputStream { - private final OutputStream cache; - private final ExecutorService executor; - private final Runnable onClose; - private boolean eofReached = false; +import org.apache.commons.io.IOUtils +import org.apache.commons.io.input.ProxyInputStream +import java.io.IOException +import java.io.InputStream +import java.io.OutputStream +import java.lang.Runnable +import java.util.concurrent.ExecutorService +import kotlin.Throws - public CachingInputStream(InputStream response, ExecutorService executor, OutputStream cache, Runnable onClose) { - super(response); - this.executor = executor; - this.cache = cache; - this.onClose = onClose; - } +class CachingInputStream( + response: InputStream?, + private val executor: ExecutorService, + private val cache: OutputStream, + private val onClose: Runnable +) : ProxyInputStream(response) { + private var eofReached = false - @Override - public void close() throws IOException { - if (eofReached) { - try { - in.close(); - } catch (IOException ignored) { - } - try { - cache.close(); - } catch (IOException ignored) { - } - onClose.run(); - } else { - executor.submit(() -> { - try { - IOUtils.copy(in, cache); - } catch (IOException ignored) { - } finally { - try { - in.close(); - } catch (IOException ignored) { - } - try { - cache.close(); - } catch (IOException ignored) { - } - onClose.run(); - } - }); - } - } + @Throws(IOException::class) + override fun close() { + if (eofReached) { + try { + `in`.close() + } catch (ignored: IOException) { + } + try { + cache.close() + } catch (ignored: IOException) { + } + onClose.run() + } else { + executor.submit { + try { + IOUtils.copy(`in`, cache) + } catch (ignored: IOException) { + } finally { + try { + `in`.close() + } catch (ignored: IOException) { + } + try { + cache.close() + } catch (ignored: IOException) { + } + onClose.run() + } + } + } + } - @Override - public int read() throws IOException { - final int ch = super.read(); - if (ch != EOF) { - try { - cache.write(ch); - } catch (IOException ignored) { - // don't let write failures affect the image loading - } - } else { - eofReached = true; - } - return ch; - } + @Throws(IOException::class) + override fun read(): Int { + val ch = super.read() + if (ch != IOUtils.EOF) { + try { + cache.write(ch) + } catch (ignored: IOException) { + // don't let write failures affect the image loading + } + } else { + eofReached = true + } + return ch + } - @Override - public int read(final byte[] bts, final int st, final int end) throws IOException { - final int n = super.read(bts, st, end); - if (n != EOF) { - try { - cache.write(bts, st, n); - } catch (IOException ignored) { - // don't let write failures affect the image loading - } - } else { - eofReached = true; - } - return n; - } + @Throws(IOException::class) + override fun read(bts: ByteArray, st: Int, end: Int): Int { + val n = super.read(bts, st, end) + if (n != IOUtils.EOF) { + try { + cache.write(bts, st, n) + } catch (ignored: IOException) { + // don't let write failures affect the image loading + } + } else { + eofReached = true + } + return n + } - @Override - public int read(final byte[] bts) throws IOException { - final int n = super.read(bts); - if (n != EOF) { - try { - cache.write(bts, 0, n); - } catch (IOException ignored) { - // don't let write failures affect the image loading - } - } else { - eofReached = true; - } - return n; - } + @Throws(IOException::class) + override fun read(bts: ByteArray): Int { + val n = super.read(bts) + if (n != IOUtils.EOF) { + try { + cache.write(bts, 0, n) + } catch (ignored: IOException) { + // don't let write failures affect the image loading + } + } else { + eofReached = true + } + return n + } } diff --git a/src/main/kotlin/mdnet/server/ImageServer.kt b/src/main/kotlin/mdnet/server/ImageServer.kt index 12532a8..67a4709 100644 --- a/src/main/kotlin/mdnet/server/ImageServer.kt +++ b/src/main/kotlin/mdnet/server/ImageServer.kt @@ -86,7 +86,7 @@ fun getServer( val circuited = ResilienceFilters.CircuitBreak( circuitBreaker, - isError = { r: Response -> !r.status.successful } + isError = { r: Response -> r.status.serverError } ) val upstream = ClientFilters.MicrometerMetrics.RequestTimer(registry)