@@ -12,13 +12,15 @@ import org.apache.thrift.protocol.TBinaryProtocol
12
12
import org.apache.thrift.transport.TFramedTransport
13
13
import org.apache.thrift.transport.TSocket
14
14
import java.io.File
15
+ import java.io.FileInputStream
15
16
import java.io.InputStream
16
17
import java.io.StringReader
17
18
import java.net.ServerSocket
18
19
import java.nio.ByteBuffer
19
20
import java.util.zip.ZipEntry
20
21
import java.util.zip.ZipInputStream
21
22
import javax.xml.bind.JAXB
23
+ import kotlin.concurrent.thread
22
24
23
25
internal fun String.isLoopback (): Boolean {
24
26
return this == " localhost" || this == " 127.0.0.1"
@@ -33,22 +35,24 @@ private fun getAvailablePort(): Int {
33
35
internal fun startRemoteProxy (fmuFile : File , host : String , port : Int ): Int {
34
36
// with 150 MB max message size
35
37
val transport = TFramedTransport .Factory (150000000 )
36
- .getTransport(TSocket (host, port))
38
+ .getTransport(TSocket (host, port))
37
39
val protocol = TBinaryProtocol (transport)
38
40
val client = FmuService .Client (protocol)
39
41
transport.open()
40
42
41
43
return if (host.isLoopback()) {
42
44
client.loadFromLocalFile(fmuFile.absolutePath)
43
45
} else {
44
- val data = fmuFile.readBytes ().let {
45
- ByteBuffer .wrap(it)
46
+ val data = FileInputStream ( fmuFile).buffered ().use {
47
+ ByteBuffer .wrap(it.readBytes() )
46
48
}
47
49
client.loadFromRemoteFile(fmuFile.name, data)
50
+ }.also {
51
+ transport.close()
48
52
}
49
53
}
50
54
51
- internal fun startLocalProxy (proxyFile : File , fmuFile : File ): Int {
55
+ internal fun startLocalProxy (proxyFile : File , fmuFile : File ): Pair < Process , Int > {
52
56
53
57
require(fmuFile.exists()) { " No such file: $fmuFile " }
54
58
require(proxyFile.exists()) { " No such file: $proxyFile " }
@@ -60,12 +64,20 @@ internal fun startLocalProxy(proxyFile: File, fmuFile: File): Int {
60
64
" $port " , fmuFile.absolutePath
61
65
)
62
66
63
- ProcessBuilder ().apply {
67
+ val pb = ProcessBuilder ().apply {
64
68
command(* cmd)
65
- start()
66
69
}
67
70
68
- return port
71
+ val process = pb.start()
72
+ thread(true ) {
73
+ val br = process.inputStream.bufferedReader()
74
+ while (true ) {
75
+ val read = br.readLine()
76
+ if (read == null ) break else println (read)
77
+ }
78
+ }
79
+
80
+ return process to port
69
81
}
70
82
71
83
internal fun extractModelDescriptionXml (stream : InputStream ): String {
0 commit comments