-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrintStream.cs
54 lines (43 loc) · 1.58 KB
/
PrintStream.cs
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) Rodrigo Speller. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE.txt in the project root for license information.
using System;
using JNet.Hosting;
using JNet.Runtime;
namespace java.io
{
public class PrintStream
{
private static readonly jclass clz_PrintStream;
private static readonly jmethodID mid_println_A;
private readonly jobject obj;
static PrintStream()
{
var setup = JNetHost.Run(runtime =>
{
var clz_PrintStream = runtime.FindClass("java/io/PrintStream");
var mid_println_A = runtime.GetMethodID(clz_PrintStream, "println", "(Ljava/lang/String;)V");
clz_PrintStream = (jclass)runtime.NewGlobalRef(clz_PrintStream);
return (clz_PrintStream, mid_println_A);
});
clz_PrintStream = setup.clz_PrintStream;
mid_println_A = setup.mid_println_A;
}
public PrintStream(jobject obj)
{
if (!obj.HasValue)
throw new ArgumentException("Empty object reference.", nameof(obj));
this.obj = obj;
}
~PrintStream()
{
JNetHost.Run(runtime => {
runtime.DeleteGlobalRef(this.obj);
});
}
public void Println(string x)
=> JNetHost.Run(runtime => {
var jx = runtime.NewString(x);
runtime.CallVoidMethod(obj, mid_println_A, jx);
});
}
}