sry, fix Formating :D

This commit is contained in:
CodeSteak 2019-06-03 16:33:19 +02:00
parent 37c4983d8e
commit c975730a58
2 changed files with 30 additions and 27 deletions

View File

@ -59,7 +59,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable {
@Throws(IOException::class, ConnectionException::class)
@Synchronized
fun query(query : Array<String>) : Array<Texture> {
fun query(query: Array<String>): Array<Texture> {
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<Array<InternalTexture>>(pkg.content, Array<InternalTexture>::class.java).map {
tex -> tex.toTexture()
return Gson().fromJson<Array<InternalTexture>>(pkg.content, Array<InternalTexture>::class.java)
.map { tex ->
tex.toTexture()
}.toTypedArray()
} catch (e : JsonSyntaxException ){
} 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<Texture> {
fun getTextureById(id: UUID): Optional<Texture> {
val io = getStreams()
val obj = JsonObject()
@ -118,7 +119,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable {
.fromJson<InternalTexture>(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<Texture> {
fun getTextureByName(name: String): Optional<Texture> {
val io = getStreams()
val obj = JsonObject()
@ -155,7 +156,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable {
.fromJson<InternalTexture>(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)

View File

@ -4,11 +4,13 @@ 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 ConnectionInvalidJsonException : ConnectionException("The Format of the Json Received is Unexpected.")