Skip to content

Commit 3108e81

Browse files
committed
FixBug: Scanner使用多次次nextLine会出现方块
1 parent 08bdd3f commit 3108e81

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

.idea/misc.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler-d8/src/main/java/com/xiaoyv/java/compiler/tools/exec/JavaProgramConsole.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class JavaProgramConsole : CoroutineScope by MainScope() {
126126
// 向输入流写入
127127
inputBuffer.write(bytes, 0, bytes.size)
128128
// 提交
129-
val submitBytes = byteArrayOf('\n'.code.toByte(), (-1).toByte())
129+
val submitBytes = byteArrayOf('\n'.code.toByte())
130130
inputBuffer.write(submitBytes, 0, submitBytes.size)
131131
return true
132132
}.onFailure {

compiler-d8/src/main/java/com/xiaoyv/java/compiler/tools/java/JavaClassHelper.kt

+36
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.xiaoyv.java.compiler.tools.java
22

3+
import android.util.Log
34
import com.xiaoyv.java.compiler.utils.FileUtils
45
import java.io.File
6+
import java.util.*
7+
import java.util.jar.JarEntry
8+
import java.util.jar.JarFile
59

610
/**
711
* @author 王怀玉
@@ -35,4 +39,36 @@ object JavaClassHelper {
3539
}
3640
return classpath.toString()
3741
}
42+
43+
@JvmStatic
44+
fun getClasses(jarPath: String) = getClasses(File(jarPath))
45+
46+
@JvmStatic
47+
fun getClasses(file: File): List<Class<*>> {
48+
if (file.exists().not()) {
49+
return arrayListOf()
50+
}
51+
val classes: MutableList<Class<*>> = arrayListOf()
52+
runCatching {
53+
val jarFile = JarFile(file)
54+
val entries: Enumeration<JarEntry> = jarFile.entries()
55+
while (entries.hasMoreElements()) {
56+
val jarEntry: JarEntry = entries.nextElement()
57+
if (jarEntry.isDirectory ||
58+
jarEntry.name.endsWith(".class").not() ||
59+
jarEntry.name.contains("$")
60+
) {
61+
continue
62+
}
63+
var className = jarEntry.name.substring(0, jarEntry.name.length - 6)
64+
className = className.replace('/', '.')
65+
runCatching {
66+
classes.add(ClassLoader.getSystemClassLoader().loadClass(className))
67+
}.onFailure {
68+
Log.e("JavaClassHelper", "编译器未适配该类: $className")
69+
}
70+
}
71+
}
72+
return classes
73+
}
3874
}

0 commit comments

Comments
 (0)