sry, fix Formating :D
This commit is contained in:
parent
37c4983d8e
commit
c975730a58
|
@ -59,7 +59,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable {
|
||||||
|
|
||||||
@Throws(IOException::class, ConnectionException::class)
|
@Throws(IOException::class, ConnectionException::class)
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun query(query : Array<String>) : Array<Texture> {
|
fun query(query: Array<String>): Array<Texture> {
|
||||||
val io = getStreams()
|
val io = getStreams()
|
||||||
|
|
||||||
val obj = JsonObject()
|
val obj = JsonObject()
|
||||||
|
@ -67,7 +67,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable {
|
||||||
val inner = JsonObject()
|
val inner = JsonObject()
|
||||||
inner.add("query", {
|
inner.add("query", {
|
||||||
val array = JsonArray()
|
val array = JsonArray()
|
||||||
for(queryString in query) {
|
for (queryString in query) {
|
||||||
array.add(queryString)
|
array.add(queryString)
|
||||||
}
|
}
|
||||||
array
|
array
|
||||||
|
@ -80,10 +80,11 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable {
|
||||||
when (val pkg = Package.read(io.first)) {
|
when (val pkg = Package.read(io.first)) {
|
||||||
is JsonPackage -> {
|
is JsonPackage -> {
|
||||||
try {
|
try {
|
||||||
return Gson().fromJson<Array<InternalTexture>>(pkg.content, Array<InternalTexture>::class.java).map {
|
return Gson().fromJson<Array<InternalTexture>>(pkg.content, Array<InternalTexture>::class.java)
|
||||||
tex -> tex.toTexture()
|
.map { tex ->
|
||||||
}.toTypedArray()
|
tex.toTexture()
|
||||||
} catch (e : JsonSyntaxException ){
|
}.toTypedArray()
|
||||||
|
} catch (e: JsonSyntaxException) {
|
||||||
throw ConnectionInvalidJsonException()
|
throw ConnectionInvalidJsonException()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +96,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable {
|
||||||
|
|
||||||
@Throws(IOException::class, ConnectionException::class)
|
@Throws(IOException::class, ConnectionException::class)
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun getTextureById(id : UUID) : Optional<Texture> {
|
fun getTextureById(id: UUID): Optional<Texture> {
|
||||||
val io = getStreams()
|
val io = getStreams()
|
||||||
|
|
||||||
val obj = JsonObject()
|
val obj = JsonObject()
|
||||||
|
@ -110,7 +111,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable {
|
||||||
when (val pkg = Package.read(io.first)) {
|
when (val pkg = Package.read(io.first)) {
|
||||||
is JsonPackage -> {
|
is JsonPackage -> {
|
||||||
return if (pkg.content.isJsonNull) {
|
return if (pkg.content.isJsonNull) {
|
||||||
Optional.empty()
|
Optional.empty()
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
Optional.of(
|
Optional.of(
|
||||||
|
@ -118,7 +119,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable {
|
||||||
.fromJson<InternalTexture>(pkg.content, InternalTexture::class.java)
|
.fromJson<InternalTexture>(pkg.content, InternalTexture::class.java)
|
||||||
.toTexture()
|
.toTexture()
|
||||||
)
|
)
|
||||||
} catch (e : JsonSyntaxException ){
|
} catch (e: JsonSyntaxException) {
|
||||||
throw ConnectionInvalidJsonException()
|
throw ConnectionInvalidJsonException()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,7 +133,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable {
|
||||||
|
|
||||||
@Throws(IOException::class, ConnectionException::class)
|
@Throws(IOException::class, ConnectionException::class)
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun getTextureByName(name : String) : Optional<Texture> {
|
fun getTextureByName(name: String): Optional<Texture> {
|
||||||
val io = getStreams()
|
val io = getStreams()
|
||||||
|
|
||||||
val obj = JsonObject()
|
val obj = JsonObject()
|
||||||
|
@ -155,7 +156,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable {
|
||||||
.fromJson<InternalTexture>(pkg.content, InternalTexture::class.java)
|
.fromJson<InternalTexture>(pkg.content, InternalTexture::class.java)
|
||||||
.toTexture()
|
.toTexture()
|
||||||
)
|
)
|
||||||
} catch (e : JsonSyntaxException ){
|
} catch (e: JsonSyntaxException) {
|
||||||
throw ConnectionInvalidJsonException()
|
throw ConnectionInvalidJsonException()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,7 +170,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable {
|
||||||
|
|
||||||
@Throws(IOException::class, ConnectionException::class)
|
@Throws(IOException::class, ConnectionException::class)
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun getTextureFile(hash : Sha256) : ByteArray {
|
fun getTextureFile(hash: Sha256): ByteArray {
|
||||||
val io = getStreams()
|
val io = getStreams()
|
||||||
|
|
||||||
val obj = JsonObject()
|
val obj = JsonObject()
|
||||||
|
@ -192,7 +193,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable {
|
||||||
|
|
||||||
@Throws(IOException::class, ConnectionException::class)
|
@Throws(IOException::class, ConnectionException::class)
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun getTexturePreview(hash : Sha256) : Image {
|
fun getTexturePreview(hash: Sha256): Image {
|
||||||
val io = getStreams()
|
val io = getStreams()
|
||||||
|
|
||||||
val obj = JsonObject()
|
val obj = JsonObject()
|
||||||
|
@ -217,18 +218,18 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable {
|
||||||
|
|
||||||
@Throws(IOException::class, ConnectionException::class, IllegalArgumentException::class)
|
@Throws(IOException::class, ConnectionException::class, IllegalArgumentException::class)
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun replaceTexture(old: Texture?, new : Texture?, image : ByteArray? ) {
|
private fun replaceTexture(old: Texture?, new: Texture?, image: ByteArray?) {
|
||||||
val io = getStreams()
|
val io = getStreams()
|
||||||
|
|
||||||
val obj = JsonObject()
|
val obj = JsonObject()
|
||||||
obj.add("replace_texture", {
|
obj.add("replace_texture", {
|
||||||
val inner = JsonObject()
|
val inner = JsonObject()
|
||||||
if(old != null) {
|
if (old != null) {
|
||||||
inner.add("old", Gson().toJsonTree(InternalTexture(old), InternalTexture::class.java))
|
inner.add("old", Gson().toJsonTree(InternalTexture(old), InternalTexture::class.java))
|
||||||
} else {
|
} else {
|
||||||
inner.add("old", null)
|
inner.add("old", null)
|
||||||
}
|
}
|
||||||
if(new != null) {
|
if (new != null) {
|
||||||
inner.add("new", Gson().toJsonTree(InternalTexture(new), InternalTexture::class.java))
|
inner.add("new", Gson().toJsonTree(InternalTexture(new), InternalTexture::class.java))
|
||||||
} else {
|
} else {
|
||||||
inner.add("new", null)
|
inner.add("new", null)
|
||||||
|
@ -250,7 +251,7 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable {
|
||||||
BinaryPackage(image).write(io.second)
|
BinaryPackage(image).write(io.second)
|
||||||
when (val ipkg = Package.read(io.first)) {
|
when (val ipkg = Package.read(io.first)) {
|
||||||
is JsonPackage -> {
|
is JsonPackage -> {
|
||||||
if(ipkg.content != JsonPrimitive(true)) {
|
if (ipkg.content != JsonPrimitive(true)) {
|
||||||
// Protokoll Assertion failed
|
// Protokoll Assertion failed
|
||||||
throw ConnectionUnexpectedPacketException()
|
throw ConnectionUnexpectedPacketException()
|
||||||
}
|
}
|
||||||
|
@ -273,8 +274,8 @@ class Connection(val address: InetAddress, val port: Int = 10796) : Closeable {
|
||||||
|
|
||||||
@Throws(IOException::class, ConnectionException::class, IllegalArgumentException::class)
|
@Throws(IOException::class, ConnectionException::class, IllegalArgumentException::class)
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun uploadTexture(texture: Texture, image : ByteArray ) {
|
fun uploadTexture(texture: Texture, image: ByteArray) {
|
||||||
if(texture.textureHash != Sha256(image)) {
|
if (texture.textureHash != Sha256(image)) {
|
||||||
throw IllegalArgumentException("Sha256 of Image does not Match with Texture.")
|
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)
|
@Throws(IOException::class, ConnectionException::class, IllegalArgumentException::class)
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun updateTexture(old: Texture, new : Texture, image : ByteArray ) {
|
fun updateTexture(old: Texture, new: Texture, image: ByteArray) {
|
||||||
if(new.textureHash != Sha256(image)) {
|
if (new.textureHash != Sha256(image)) {
|
||||||
throw IllegalArgumentException("Sha256 of Image does not Match with Texture.")
|
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)
|
@Throws(IOException::class, ConnectionException::class, IllegalArgumentException::class)
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun deleteTexture(texture : Texture) {
|
fun deleteTexture(texture: Texture) {
|
||||||
replaceTexture(texture, null , null)
|
replaceTexture(texture, null, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
|
|
|
@ -4,12 +4,14 @@ package org.hso.texturesyncclient.controller.net
|
||||||
|
|
||||||
import java.lang.Exception
|
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}") {
|
class ConnectionErrorException(val errorCode: Int, val errorMessage: String) :
|
||||||
internal constructor(err : ErrorPackage) : this(err.code, err.message)
|
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.")
|
class ConnectionInvalidJsonException : ConnectionException("The Format of the Json Received is Unexpected.")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue