Blame view

footsafety/app/src/main/java/com/printer/sdk/usb/Converter 630 Bytes
f7a13682   “wangming”   项目初始化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  package com.printer.sdk.usb
  
  abstract class Converter {
      open fun toByteArray(input: String): ByteArray {
          val text = convert(input)
          return try {
              var i = 0
              val bytes = ByteArray(text.length)
              for (c in text.toCharArray()) {
                  bytes[i++] = convert(c)
              }
              bytes
          } catch (e: Exception) {
              e.printStackTrace()
              byteArrayOf()
          }
      }
  
      protected open fun convert(input: String): String {
          return input
      }
  
      protected open fun convert(input: Char): Byte {
          return input.toByte()
      }
  }