| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,7 @@ | |||
| 23 | 23 | <plugin> | |
| 24 | 24 | <groupId>org.springframework.boot</groupId> | |
| 25 | 25 | <artifactId>spring-boot-maven-plugin</artifactId> | |
| 26 | + <version>1.5.8.RELEASE</version> | ||
| 26 | 27 | <executions> | |
| 27 | 28 | <execution> | |
| 28 | 29 | <goals> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,23 +20,23 @@ import java.util.* | |||
| 20 | 20 | ||
| 21 | 21 | class CastUtil { | |
| 22 | 22 | companion object { | |
| 23 | - protected val OUT = ByteArrayOutputStream() | ||
| 24 | - protected var oos: ObjectOutputStream? = null | ||
| 23 | + private val OUT = ByteArrayOutputStream() | ||
| 24 | + private var oos: ObjectOutputStream? = null | ||
| 25 | 25 | ||
| 26 | 26 | fun toInteger(str: Any?): Int { | |
| 27 | 27 | return if (str == null) 0 else (str as? Number)?.toInt() ?: toInteger(str.toString()) | |
| 28 | 28 | } | |
| 29 | 29 | ||
| 30 | 30 | fun toDouble(number: Any?): Double { | |
| 31 | - if (number == null) { | ||
| 32 | - return 0.0 | ||
| 31 | + return if (number == null) { | ||
| 32 | + 0.0 | ||
| 33 | 33 | } else if (number is Number) { | |
| 34 | - return number.toDouble() | ||
| 34 | + number.toDouble() | ||
| 35 | 35 | } else if (number is String) { | |
| 36 | 36 | val str = number as String? | |
| 37 | - return if (isNumeric(str) > 0) java.lang.Double.valueOf(str!!) else 0.0 | ||
| 37 | + if (isNumeric(str) > 0) java.lang.Double.valueOf(str!!) else 0.0 | ||
| 38 | 38 | } else { | |
| 39 | - return 0.0 | ||
| 39 | + 0.0 | ||
| 40 | 40 | } | |
| 41 | 41 | } | |
| 42 | 42 | ||
@@ -55,16 +55,16 @@ class CastUtil { | |||
| 55 | 55 | } | |
| 56 | 56 | ||
| 57 | 57 | fun toInteger(str: String?): Int { | |
| 58 | - var str = str | ||
| 59 | - if (str == null) { | ||
| 60 | - return 0 | ||
| 58 | + var intStr = str | ||
| 59 | + return if (intStr == null) { | ||
| 60 | + 0 | ||
| 61 | 61 | } else { | |
| 62 | - str = str.trim { it <= ' ' } | ||
| 63 | - if (str.length == 0) { | ||
| 64 | - return 0 | ||
| 62 | + intStr = intStr.trim { it <= ' ' } | ||
| 63 | + if (intStr.isEmpty()) { | ||
| 64 | + 0 | ||
| 65 | 65 | } else { | |
| 66 | - val i = isNumeric(str) | ||
| 67 | - return if (i == 1) Integer.parseInt(str) else if (i == 2) java.lang.Double.valueOf(str).toInt() else 0 | ||
| 66 | + val i = isNumeric(intStr) | ||
| 67 | + if (i == 1) Integer.parseInt(intStr) else if (i == 2) java.lang.Double.valueOf(intStr).toInt() else 0 | ||
| 68 | 68 | } | |
| 69 | 69 | } | |
| 70 | 70 | } | |
@@ -118,7 +118,7 @@ class CastUtil { | |||
| 118 | 118 | val newmap = HashMap<Any, Any>(10) | |
| 119 | 119 | ||
| 120 | 120 | for (key in map.keys) { | |
| 121 | - newmap.put(key, map.get(key)!!) | ||
| 121 | + newmap.put(key, map[key]!!) | ||
| 122 | 122 | } | |
| 123 | 123 | ||
| 124 | 124 | return newmap | |
@@ -221,7 +221,6 @@ class CastUtil { | |||
| 221 | 221 | ||
| 222 | 222 | fun stringToBytes(str: String): ByteArray { | |
| 223 | 223 | val sb = StringBuffer(str) | |
| 224 | - val c = sb[0] | ||
| 225 | 224 | val buffer = ByteBuffer.allocate(sb.length * 2) | |
| 226 | 225 | var index = 0 | |
| 227 | 226 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,33 +74,33 @@ object CharUtil { | |||
| 74 | 74 | * Utf8URL解码 | |
| 75 | 75 | */ | |
| 76 | 76 | fun utf8urldecode(text: String?): String { | |
| 77 | - var text = text | ||
| 77 | + var str = text | ||
| 78 | 78 | var result = "" | |
| 79 | 79 | var p: Int | |
| 80 | - if (text != null && text.length > 0) { | ||
| 81 | - text = text.toLowerCase() | ||
| 82 | - p = text.indexOf("%e") | ||
| 80 | + if (str != null && str.isNotEmpty()) { | ||
| 81 | + str = str.toLowerCase() | ||
| 82 | + p = str.indexOf("%e") | ||
| 83 | 83 | if (p == -1) { | |
| 84 | - return text | ||
| 84 | + return str | ||
| 85 | 85 | } | |
| 86 | 86 | while (p != -1) { | |
| 87 | - result += text!!.substring(0, p) | ||
| 88 | - text = text.substring(p, text.length) | ||
| 89 | - if (text == "" || text.length < 9) { | ||
| 87 | + result += str!!.substring(0, p) | ||
| 88 | + str = str.substring(p, str.length) | ||
| 89 | + if (str == "" || str.length < 9) { | ||
| 90 | 90 | return result | |
| 91 | 91 | } | |
| 92 | - result += codetoword(text.substring(0, 9)) | ||
| 93 | - text = text.substring(9, text.length) | ||
| 94 | - p = text.indexOf("%e") | ||
| 92 | + result += codeToWord(str.substring(0, 9)) | ||
| 93 | + str = str.substring(9, str.length) | ||
| 94 | + p = str.indexOf("%e") | ||
| 95 | 95 | } | |
| 96 | 96 | } | |
| 97 | - return result + text!! | ||
| 97 | + return result + str!! | ||
| 98 | 98 | } | |
| 99 | 99 | ||
| 100 | 100 | /** | |
| 101 | 101 | * utf8URL编码转字符 | |
| 102 | 102 | */ | |
| 103 | - private fun codetoword(text: String): String? { | ||
| 103 | + private fun codeToWord(text: String): String? { | ||
| 104 | 104 | var result: String? | |
| 105 | 105 | if (utf8codecheck(text)) { | |
| 106 | 106 | val code = ByteArray(3) | |
@@ -142,14 +142,14 @@ object CharUtil { | |||
| 142 | 142 | * 判断是否Utf8Url编码 | |
| 143 | 143 | */ | |
| 144 | 144 | fun isUtf8Url(text: String): Boolean { | |
| 145 | - var text = text | ||
| 146 | - text = text.toLowerCase() | ||
| 147 | - val p = text.indexOf("%") | ||
| 145 | + var textStr = text | ||
| 146 | + textStr = textStr.toLowerCase() | ||
| 147 | + val p = textStr.indexOf("%") | ||
| 148 | 148 | val nine = 9 | |
| 149 | - if (p != -1 && text.length - p > nine) { | ||
| 150 | - text = text.substring(p, p + nine) | ||
| 149 | + if (p != -1 && textStr.length - p > nine) { | ||
| 150 | + textStr = textStr.substring(p, p + nine) | ||
| 151 | 151 | } | |
| 152 | - return utf8codecheck(text) | ||
| 152 | + return utf8codecheck(textStr) | ||
| 153 | 153 | } | |
| 154 | 154 | ||
| 155 | 155 | /** | |
@@ -158,19 +158,19 @@ object CharUtil { | |||
| 158 | 158 | * @return char | |
| 159 | 159 | */ | |
| 160 | 160 | fun regularize(input: Char): Char { | |
| 161 | - var input = input | ||
| 162 | - if (input.toInt() == 12288) { | ||
| 163 | - input = 32.toChar() | ||
| 164 | - } else if (input.toInt() > 65280 && input.toInt() < 65375) { | ||
| 165 | - input = (input.toInt() - 65248).toChar() | ||
| 161 | + var char = input | ||
| 162 | + if (char.toInt() == 12288) { | ||
| 163 | + char = 32.toChar() | ||
| 164 | + } else if (char.toInt() in 65281..65374) { | ||
| 165 | + char = (char.toInt() - 65248).toChar() | ||
| 166 | 166 | } else { | |
| 167 | 167 | val a = 'A' | |
| 168 | 168 | val z = 'Z' | |
| 169 | - if (input >= a && input <= z) { | ||
| 170 | - input += 32.toChar().toInt() | ||
| 169 | + if (char in a..z) { | ||
| 170 | + char += 32.toChar().toInt() | ||
| 171 | 171 | } | |
| 172 | 172 | } | |
| 173 | - return input | ||
| 173 | + return char | ||
| 174 | 174 | } | |
| 175 | 175 | ||
| 176 | 176 | @JvmStatic | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -201,7 +201,6 @@ object FileUtil { | |||
| 201 | 201 | } | |
| 202 | 202 | ||
| 203 | 203 | val entries = dir.listFiles() | |
| 204 | - val sz = entries?.size ?: 0 | ||
| 205 | 204 | ||
| 206 | 205 | for (entry in entries ?: arrayOfNulls(0)) { | |
| 207 | 206 | if (entry.isDirectory) { | |
@@ -528,10 +527,10 @@ object FileUtil { | |||
| 528 | 527 | */ | |
| 529 | 528 | @Throws(IOException::class) | |
| 530 | 529 | fun genModuleTpl(path: String, modulecontent: String): Boolean { | |
| 531 | - var path = path | ||
| 530 | + var str = path | ||
| 532 | 531 | ||
| 533 | - path = getUNIXfilePath(path) | ||
| 534 | - val patharray = path.split("\\/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() | ||
| 532 | + str = getUNIXfilePath(str) | ||
| 533 | + val patharray = str.split("\\/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() | ||
| 535 | 534 | var modulepath = "" | |
| 536 | 535 | for (i in 0 until patharray.size - 1) { | |
| 537 | 536 | modulepath += "/" + patharray[i] | |
@@ -543,7 +542,7 @@ object FileUtil { | |||
| 543 | 542 | } | |
| 544 | 543 | } | |
| 545 | 544 | //建立FileWriter对象,并实例化fw | |
| 546 | - val fw = FileWriter(path) | ||
| 545 | + val fw = FileWriter(str) | ||
| 547 | 546 | //将字符串写入文件 | |
| 548 | 547 | fw.write(modulecontent) | |
| 549 | 548 | fw.close() | |
@@ -558,23 +557,23 @@ object FileUtil { | |||
| 558 | 557 | * @since 1.0 | |
| 559 | 558 | */ | |
| 560 | 559 | fun getPicExtendName(picPath: String): String { | |
| 561 | - var picPath = picPath | ||
| 562 | - picPath = getUNIXfilePath(picPath) | ||
| 560 | + var pic = picPath | ||
| 561 | + pic = getUNIXfilePath(pic) | ||
| 563 | 562 | var picExtend = "" | |
| 564 | 563 | val gif = ".gif" | |
| 565 | - if (isFileExist(picPath + gif)) { | ||
| 564 | + if (isFileExist(pic + gif)) { | ||
| 566 | 565 | picExtend = gif | |
| 567 | 566 | } | |
| 568 | 567 | val jpeg = ".jpeg" | |
| 569 | - if (isFileExist(picPath + jpeg)) { | ||
| 568 | + if (isFileExist(pic + jpeg)) { | ||
| 570 | 569 | picExtend = jpeg | |
| 571 | 570 | } | |
| 572 | 571 | val jpg = ".jpg" | |
| 573 | - if (isFileExist(picPath + jpg)) { | ||
| 572 | + if (isFileExist(pic + jpg)) { | ||
| 574 | 573 | picExtend = jpg | |
| 575 | 574 | } | |
| 576 | 575 | val png = ".png" | |
| 577 | - if (isFileExist(picPath + png)) { | ||
| 576 | + if (isFileExist(pic + png)) { | ||
| 578 | 577 | picExtend = png | |
| 579 | 578 | } | |
| 580 | 579 | //返回图片扩展名 | |
@@ -672,15 +671,14 @@ object FileUtil { | |||
| 672 | 671 | // 重新定义图片名字 | |
| 673 | 672 | filename = FileUtil.getNewFileName(fileName, email) | |
| 674 | 673 | //上传服务器上 新文件路径 | |
| 675 | - val os = System.getProperty("os.name").toLowerCase() | ||
| 676 | 674 | try { | |
| 677 | 675 | // 判断服务器上 文件夹是否存在 | |
| 678 | 676 | val newFile = File(savePath) | |
| 679 | 677 | if (!newFile.exists()) { | |
| 680 | 678 | val result = newFile.mkdirs() | |
| 681 | 679 | println(result) | |
| 682 | 680 | } | |
| 683 | - savePath = savePath + filename | ||
| 681 | + savePath += filename | ||
| 684 | 682 | val out = FileOutputStream(savePath) | |
| 685 | 683 | // 写入文件 | |
| 686 | 684 | out.write(file.bytes) | |
@@ -716,7 +714,6 @@ object FileUtil { | |||
| 716 | 714 | var bytes: ByteArray? = ByteArray(len) | |
| 717 | 715 | val r = bufferedInputStream.read(bytes!!) | |
| 718 | 716 | if (len != r) { | |
| 719 | - bytes = null | ||
| 720 | 717 | throw IOException("读取文件不正确") | |
| 721 | 718 | } | |
| 722 | 719 | bufferedInputStream.close() | |
@@ -731,7 +728,6 @@ object FileUtil { | |||
| 731 | 728 | var bytes: ByteArray? = ByteArray(len) | |
| 732 | 729 | val r = bufferedInputStream.read(bytes!!) | |
| 733 | 730 | if (len != r) { | |
| 734 | - bytes = null | ||
| 735 | 731 | throw IOException("读取文件不正确") | |
| 736 | 732 | } | |
| 737 | 733 | bufferedInputStream.close() | |
@@ -746,10 +742,9 @@ object FileUtil { | |||
| 746 | 742 | * @return | |
| 747 | 743 | */ | |
| 748 | 744 | private fun getData(`in`: InputStream): String { | |
| 749 | - val result = "" | ||
| 750 | 745 | val sb = StringBuilder() | |
| 751 | 746 | val br = BufferedReader(InputStreamReader(`in`)) | |
| 752 | - var line = "" | ||
| 747 | + val line = "" | ||
| 753 | 748 | try { | |
| 754 | 749 | while ((br.readLine()) != null) { | |
| 755 | 750 | // result = result + line; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -125,13 +125,13 @@ object HtmlUtil { | |||
| 125 | 125 | * @since 1.0 | |
| 126 | 126 | */ | |
| 127 | 127 | fun htmlDecode(strSrc: String?): String? { | |
| 128 | - var strSrc: String? = strSrc ?: return "" | ||
| 129 | - strSrc = strSrc!!.replace("<".toRegex(), "<") | ||
| 130 | - strSrc = strSrc.replace(">".toRegex(), ">") | ||
| 131 | - strSrc = strSrc.replace(""".toRegex(), "\"") | ||
| 132 | - strSrc = strSrc.replace("'".toRegex(), "'") | ||
| 133 | - strSrc = strSrc.replace("&".toRegex(), "&") | ||
| 134 | - return strSrc | ||
| 128 | + var str: String? = strSrc ?: return "" | ||
| 129 | + str = str!!.replace("<".toRegex(), "<") | ||
| 130 | + str = str.replace(">".toRegex(), ">") | ||
| 131 | + str = str.replace(""".toRegex(), "\"") | ||
| 132 | + str = str.replace("'".toRegex(), "'") | ||
| 133 | + str = str.replace("&".toRegex(), "&") | ||
| 134 | + return str | ||
| 135 | 135 | } | |
| 136 | 136 | ||
| 137 | 137 | /** | |
@@ -141,7 +141,7 @@ object HtmlUtil { | |||
| 141 | 141 | * @return string | |
| 142 | 142 | */ | |
| 143 | 143 | fun delHTMLTag(htmlStr: String): String { | |
| 144 | - var htmlStr = htmlStr | ||
| 144 | + var text = htmlStr | ||
| 145 | 145 | //定义script的正则表达式 | |
| 146 | 146 | val regexScript = "<script[^>]*?>[\\s\\S]*?<\\/script>" | |
| 147 | 147 | //定义style的正则表达式 | |
@@ -150,21 +150,21 @@ object HtmlUtil { | |||
| 150 | 150 | val regexHtml = "<[^>]+>" | |
| 151 | 151 | ||
| 152 | 152 | val pScript = Pattern.compile(regexScript, Pattern.CASE_INSENSITIVE) | |
| 153 | - val mScript = pScript.matcher(htmlStr) | ||
| 153 | + val mScript = pScript.matcher(text) | ||
| 154 | 154 | //过滤script标签 | |
| 155 | - htmlStr = mScript.replaceAll("") | ||
| 155 | + text = mScript.replaceAll("") | ||
| 156 | 156 | ||
| 157 | 157 | val pStyle = Pattern.compile(regexStyle, Pattern.CASE_INSENSITIVE) | |
| 158 | - val mStyle = pStyle.matcher(htmlStr) | ||
| 158 | + val mStyle = pStyle.matcher(text) | ||
| 159 | 159 | //过滤style标签 | |
| 160 | - htmlStr = mStyle.replaceAll("") | ||
| 160 | + text = mStyle.replaceAll("") | ||
| 161 | 161 | ||
| 162 | 162 | val pHtml = Pattern.compile(regexHtml, Pattern.CASE_INSENSITIVE) | |
| 163 | - val mHtml = pHtml.matcher(htmlStr) | ||
| 163 | + val mHtml = pHtml.matcher(text) | ||
| 164 | 164 | //过滤html标签 | |
| 165 | - htmlStr = mHtml.replaceAll("") | ||
| 165 | + text = mHtml.replaceAll("") | ||
| 166 | 166 | //返回文本字符串 | |
| 167 | - return htmlStr.trim { it <= ' ' } | ||
| 167 | + return text.trim { it <= ' ' } | ||
| 168 | 168 | } | |
| 169 | 169 | ||
| 170 | 170 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -126,7 +126,7 @@ class HttpUtil { | |||
| 126 | 126 | val read = BufferedReader(InputStreamReader(`in`, DEFAULT_CHARSET)) | |
| 127 | 127 | val valueString: String? = null | |
| 128 | 128 | bufferRes = StringBuffer() | |
| 129 | - while ((valueString == read.readLine()) != null) { | ||
| 129 | + while ((read.readLine()) != null) { | ||
| 130 | 130 | bufferRes.append(valueString) | |
| 131 | 131 | } | |
| 132 | 132 | read.close() | |
@@ -141,13 +141,13 @@ class HttpUtil { | |||
| 141 | 141 | } | |
| 142 | 142 | ||
| 143 | 143 | fun post(url: String, params: String?, headers: Map<String, String>?): String? { | |
| 144 | - var bufferRes: StringBuffer? = null | ||
| 144 | + var bufferRes: StringBuffer? | ||
| 145 | 145 | try { | |
| 146 | - var http: HttpURLConnection? = null | ||
| 147 | - if (isHttps(url)) { | ||
| 148 | - http = initHttps(url, POST, headers) | ||
| 146 | + var http: HttpURLConnection? | ||
| 147 | + http = if (isHttps(url)) { | ||
| 148 | + initHttps(url, POST, headers) | ||
| 149 | 149 | } else { | |
| 150 | - http = initHttp(url, POST, headers) | ||
| 150 | + initHttp(url, POST, headers) | ||
| 151 | 151 | } | |
| 152 | 152 | val out = http.outputStream | |
| 153 | 153 | out.write(params!!.toByteArray(charset(DEFAULT_CHARSET))) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments