From c975730a58923e29a37450c7b30568af913011fd Mon Sep 17 00:00:00 2001 From: CodeSteak Date: Mon, 3 Jun 2019 16:33:19 +0200 Subject: [PATCH] sry, fix Formating :D --- .../controller/net/Connection.kt | 47 ++++++++++--------- .../texturesyncclient/controller/net/error.kt | 10 ++-- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/controller/net/Connection.kt b/client/src/main/kotlin/org/hso/texturesyncclient/controller/net/Connection.kt index 21f2535..e53ebab 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/controller/net/Connection.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/net/Connection.kt @@ -59,7 +59,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable { @Throws(IOException::class, ConnectionException::class) @Synchronized - fun query(query : Array) : Array { + fun query(query: Array): Array { val io = getStreams() val obj = JsonObject() @@ -67,7 +67,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable { val inner = JsonObject() inner.add("query", { val array = JsonArray() - for(queryString in query) { + for (queryString in query) { array.add(queryString) } array @@ -80,10 +80,11 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable { when (val pkg = Package.read(io.first)) { is JsonPackage -> { try { - return Gson().fromJson>(pkg.content, Array::class.java).map { - tex -> tex.toTexture() - }.toTypedArray() - } catch (e : JsonSyntaxException ){ + return Gson().fromJson>(pkg.content, Array::class.java) + .map { tex -> + tex.toTexture() + }.toTypedArray() + } catch (e: JsonSyntaxException) { throw ConnectionInvalidJsonException() } } @@ -95,7 +96,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable { @Throws(IOException::class, ConnectionException::class) @Synchronized - fun getTextureById(id : UUID) : Optional { + fun getTextureById(id: UUID): Optional { val io = getStreams() val obj = JsonObject() @@ -110,7 +111,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable { when (val pkg = Package.read(io.first)) { is JsonPackage -> { return if (pkg.content.isJsonNull) { - Optional.empty() + Optional.empty() } else { try { Optional.of( @@ -118,7 +119,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable { .fromJson(pkg.content, InternalTexture::class.java) .toTexture() ) - } catch (e : JsonSyntaxException ){ + } catch (e: JsonSyntaxException) { throw ConnectionInvalidJsonException() } } @@ -132,7 +133,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable { @Throws(IOException::class, ConnectionException::class) @Synchronized - fun getTextureByName(name : String) : Optional { + fun getTextureByName(name: String): Optional { val io = getStreams() val obj = JsonObject() @@ -155,7 +156,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable { .fromJson(pkg.content, InternalTexture::class.java) .toTexture() ) - } catch (e : JsonSyntaxException ){ + } catch (e: JsonSyntaxException) { throw ConnectionInvalidJsonException() } } @@ -169,7 +170,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable { @Throws(IOException::class, ConnectionException::class) @Synchronized - fun getTextureFile(hash : Sha256) : ByteArray { + fun getTextureFile(hash: Sha256): ByteArray { val io = getStreams() val obj = JsonObject() @@ -192,7 +193,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable { @Throws(IOException::class, ConnectionException::class) @Synchronized - fun getTexturePreview(hash : Sha256) : Image { + fun getTexturePreview(hash: Sha256): Image { val io = getStreams() val obj = JsonObject() @@ -217,18 +218,18 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable { @Throws(IOException::class, ConnectionException::class, IllegalArgumentException::class) @Synchronized - private fun replaceTexture(old: Texture?, new : Texture?, image : ByteArray? ) { + private fun replaceTexture(old: Texture?, new: Texture?, image: ByteArray?) { val io = getStreams() val obj = JsonObject() obj.add("replace_texture", { val inner = JsonObject() - if(old != null) { + if (old != null) { inner.add("old", Gson().toJsonTree(InternalTexture(old), InternalTexture::class.java)) } else { inner.add("old", null) } - if(new != null) { + if (new != null) { inner.add("new", Gson().toJsonTree(InternalTexture(new), InternalTexture::class.java)) } else { inner.add("new", null) @@ -250,7 +251,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable { BinaryPackage(image).write(io.second) when (val ipkg = Package.read(io.first)) { is JsonPackage -> { - if(ipkg.content != JsonPrimitive(true)) { + if (ipkg.content != JsonPrimitive(true)) { // Protokoll Assertion failed throw ConnectionUnexpectedPacketException() } @@ -273,8 +274,8 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable { @Throws(IOException::class, ConnectionException::class, IllegalArgumentException::class) @Synchronized - fun uploadTexture(texture: Texture, image : ByteArray ) { - if(texture.textureHash != Sha256(image)) { + fun uploadTexture(texture: Texture, image: ByteArray) { + if (texture.textureHash != Sha256(image)) { throw IllegalArgumentException("Sha256 of Image does not Match with Texture.") } @@ -283,8 +284,8 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable { @Throws(IOException::class, ConnectionException::class, IllegalArgumentException::class) @Synchronized - fun updateTexture(old: Texture, new : Texture, image : ByteArray ) { - if(new.textureHash != Sha256(image)) { + fun updateTexture(old: Texture, new: Texture, image: ByteArray) { + if (new.textureHash != Sha256(image)) { throw IllegalArgumentException("Sha256 of Image does not Match with Texture.") } @@ -293,8 +294,8 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable { @Throws(IOException::class, ConnectionException::class, IllegalArgumentException::class) @Synchronized - fun deleteTexture(texture : Texture) { - replaceTexture(texture, null , null) + fun deleteTexture(texture: Texture) { + replaceTexture(texture, null, null) } @Throws(IOException::class) diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/controller/net/error.kt b/client/src/main/kotlin/org/hso/texturesyncclient/controller/net/error.kt index 4435a4f..c43d785 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/controller/net/error.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/net/error.kt @@ -4,12 +4,14 @@ package org.hso.texturesyncclient.controller.net import java.lang.Exception -sealed class ConnectionException(override val message : String) : Exception(message) +sealed class ConnectionException(override val message: String) : Exception(message) -class ConnectionErrorException(val errorCode : Int, val errorMessage : String) : ConnectionException("${errorCode} ${errorMessage}") { - internal constructor(err : ErrorPackage) : this(err.code, err.message) +class ConnectionErrorException(val errorCode: Int, val errorMessage: String) : + ConnectionException("$errorCode $errorMessage") { + internal constructor(err: ErrorPackage) : this(err.code, err.message) } -class ConnectionUnexpectedPacketException : ConnectionException("Got Unexpected Type of Packet") + +class ConnectionUnexpectedPacketException : ConnectionException("Got Unexpected Type of Packet") class ConnectionInvalidJsonException : ConnectionException("The Format of the Json Received is Unexpected.")