package com.zxhl.cms.common

import androidx.annotation.DrawableRes
import java.io.*
import java.nio.charset.Charset

class NotifyInfo : Serializable {

    var uniqueId: Int = 0

    var title: String? = null

    var subText: String? = null

    var content: String? = null

    var param: String? = null

    var beginTime: Long? = null

    @DrawableRes
    var smallIcon = 0

    companion object {

        @kotlin.jvm.Throws(IOException::class)
        fun toBytes(obj: NotifyInfo?): ByteArray {
            val bout = ByteArrayOutputStream()
            var oos: ObjectOutputStream? = null
            val content: String? = null
            oos = ObjectOutputStream(bout)
            oos.writeObject(obj)
            oos.close()
            val bytes = bout.toByteArray()
            bout.close()
            return bytes
        }

        @JvmStatic
        @kotlin.jvm.Throws(IOException::class, ClassNotFoundException::class)
        fun from(content: String): NotifyInfo? {
            val bin = ByteArrayInputStream(content.toByteArray(charset("ISO-8859-1")))
            val ois = ObjectInputStream(bin)
            val obj = ois.readObject() as NotifyInfo
            ois.close()
            bin.close()
            return obj
        }

        @JvmStatic
        @kotlin.jvm.Throws(IOException::class)
        fun to(obj: NotifyInfo): String {
            val bout = ByteArrayOutputStream()
            val oos = ObjectOutputStream(bout)
            oos.writeObject(obj)
            oos.close()
            val bytes = bout.toByteArray()
            val content = String(bytes, Charset.forName("ISO-8859-1"))
            bout.close()
            return content
        }

    }
}