-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 1.0.87 * convert files to kotlin * Update IterativePatchUtilTest.kt
- Loading branch information
1 parent
9ed443a
commit 668d45f
Showing
6 changed files
with
162 additions
and
177 deletions.
There are no files selected for viewing
111 changes: 0 additions & 111 deletions
111
core/src/main/java/com/simiacryptus/skyenet/core/OutputInterceptor.java
This file was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
core/src/main/kotlin/com/simiacryptus/skyenet/core/OutputInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.simiacryptus.skyenet.core | ||
|
||
import java.io.ByteArrayOutputStream | ||
import java.io.IOException | ||
import java.io.PrintStream | ||
import java.util.* | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
|
||
object OutputInterceptor { | ||
private val originalOut: PrintStream = System.out | ||
private val originalErr: PrintStream = System.err | ||
private val isSetup = AtomicBoolean(false) | ||
private val globalStreamLock = Any() | ||
|
||
fun setupInterceptor() { | ||
if (isSetup.getAndSet(true)) return | ||
System.setOut(PrintStream(OutputStreamRouter(originalOut))) | ||
System.setErr(PrintStream(OutputStreamRouter(originalErr))) | ||
} | ||
|
||
private val globalStream = ByteArrayOutputStream() | ||
|
||
private val threadLocalBuffer = WeakHashMap<Thread, ByteArrayOutputStream>() | ||
|
||
private fun getThreadOutputStream(): ByteArrayOutputStream { | ||
val currentThread = Thread.currentThread() | ||
synchronized(threadLocalBuffer) { | ||
return threadLocalBuffer.getOrPut(currentThread) { ByteArrayOutputStream() } | ||
} | ||
} | ||
|
||
fun getThreadOutput(): String { | ||
val outputStream = getThreadOutputStream() | ||
try { | ||
outputStream.flush() | ||
} catch (e: IOException) { | ||
throw RuntimeException(e) | ||
} | ||
return outputStream.toString() | ||
} | ||
|
||
fun clearThreadOutput() { | ||
getThreadOutputStream().reset() | ||
} | ||
|
||
fun getGlobalOutput(): String { | ||
synchronized(globalStreamLock) { | ||
return globalStream.toString() | ||
} | ||
} | ||
|
||
fun clearGlobalOutput() { | ||
synchronized(globalStreamLock) { | ||
globalStream.reset() | ||
} | ||
} | ||
|
||
private class OutputStreamRouter(private val originalStream: PrintStream) : ByteArrayOutputStream() { | ||
private val maxGlobalBuffer = 8 * 1024 * 1024 | ||
private val maxThreadBuffer = 1024 * 1024 | ||
|
||
override fun write(b: Int) { | ||
originalStream.write(b) | ||
synchronized(globalStreamLock) { | ||
if (globalStream.size() > maxGlobalBuffer) { | ||
globalStream.reset() | ||
} | ||
globalStream.write(b) | ||
} | ||
val threadOutputStream = getThreadOutputStream() | ||
if (threadOutputStream.size() > maxThreadBuffer) { | ||
threadOutputStream.reset() | ||
} | ||
threadOutputStream.write(b) | ||
} | ||
|
||
override fun write(b: ByteArray, off: Int, len: Int) { | ||
originalStream.write(b, off, len) | ||
synchronized(globalStreamLock) { | ||
if (globalStream.size() > maxGlobalBuffer) { | ||
globalStream.reset() | ||
} | ||
globalStream.write(b, off, len) | ||
} | ||
val threadOutputStream = getThreadOutputStream() | ||
if (threadOutputStream.size() > maxThreadBuffer) { | ||
threadOutputStream.reset() | ||
} | ||
threadOutputStream.write(b, off, len) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Gradle Releases -> https://github.com/gradle/gradle/releases | ||
libraryGroup = com.simiacryptus.skyenet | ||
libraryVersion = 1.0.86 | ||
libraryVersion = 1.0.87 | ||
gradleVersion = 7.6.1 | ||
kotlin.daemon.jvmargs=-Xmx2g |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters