Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
skiko
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuqiang
skiko
Commits
24f1cecb
Commit
24f1cecb
authored
Jul 29, 2020
by
Alexey Tsvetkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert org.jetbrains.skiko.Library to Kotlin
parent
691a0f58
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
55 deletions
+44
-55
Library.kt
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Library.kt
+44
-55
No files found.
skiko/src/jvmMain/kotlin/org/jetbrains/skiko/Library.kt
View file @
24f1cecb
package
org.jetbrains.skiko
;
package
org.jetbrains.skiko
import
java.io.File;
import
java.io.InputStream;
import
java.io.IOException;
import
java.net.URL;
import
java.net.URISyntaxException;
import
java.nio.file.Files;
import
java.nio.file.StandardCopyOption;
import
java.io.File
import
java.io.IOException
import
java.net.URISyntaxException
import
java.nio.file.Files
import
java.nio.file.StandardCopyOption
// based on https://github.com/JetBrains/skija/blob/bc6e0531021e4ff839c07196e0336d6456ed7520/src/main/java/org/jetbrains/skija/Library.java
public
class
Library
{
public
static
boolean
_loaded
=
false
;
object
Library
{
var
_loaded
=
false
// https://github.com/adamheinrich/native-utils/blob/e6a39489662846a77504634b6fafa4995ede3b1d/src/main/java/cz/adamh/utils/NativeUtils.java
public
static
void
load
(
String
resourcePath
,
String
name
)
{
if
(
_loaded
)
return
;
try
{
File
file
;
String
fileName
=
_getPrefix
()
+
name
+
"."
+
_getExtension
();
URL
url
=
Library
.
class
.
getResource
(
resourcePath
+
fileName
);
if
(
url
==
null
)
throw
new
IllegalArgumentException
(
"Library "
+
fileName
+
" is not found in "
+
resourcePath
);
else
if
(
url
.
getProtocol
()
==
"file"
)
fun
load
(
resourcePath
:
String
,
name
:
String
)
{
if
(
_loaded
)
return
try
{
var
file
:
File
val
fileName
=
_getPrefix
()
+
name
+
"."
+
_getExtension
()
val
url
=
Library
::
class
.
java
.
getResource
(
resourcePath
+
fileName
)
// System.out.println("Loading " + url);
file
=
new
File
(
url
.
toURI
());
}
catch
(
URISyntaxException
e
)
{
throw
new
RuntimeException
(
e
);
}
else
t
ry
(
InputStream
is
=
url
.
openStream
())
{
File
tempDir
=
new
File
(
System
.
getProperty
(
"java.io.tmpdir"
),
"skija_"
+
System
.
nanoTime
());
tempDir
.
mkdirs
();
tempDir
.
deleteOnExit
();
file
=
new
File
(
tempDir
,
fileName
);
file
.
deleteOnExit
();
Files
.
copy
(
is
,
file
.
toPath
(),
StandardCopyOption
.
REPLACE_EXISTING
);
// System.out.println("Loading " + url + " from " + file);
requireNotNull
(
url
)
{
"Library $fileName is not found in $resourcePath"
}
if
(
url
.
protocol
===
"file"
)
file
=
try
{
// System.out.println("Loading " + url
);
File
(
url
.
toURI
())
}
catch
(
e
:
URISyntaxException
)
{
t
hrow
RuntimeException
(
e
)
}
else
url
.
openStream
().
use
{
`is`
->
val
tempDir
=
File
(
System
.
getProperty
(
"java.io.tmpdir"
),
"skija_"
+
System
.
nanoTime
())
tempDir
.
mkdirs
()
tempDir
.
deleteOnExit
()
file
=
File
(
tempDir
,
fileName
)
file
.
deleteOnExit
()
Files
.
copy
(
`is`
,
file
.
toPath
(),
StandardCopyOption
.
REPLACE_EXISTING
)
}
System
.
load
(
file
.
getAbsolutePath
());
_loaded
=
true
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
System
.
load
(
file
.
absolutePath
)
_loaded
=
true
}
catch
(
e
:
IOException
)
{
throw
RuntimeException
(
e
)
}
}
public
static
String
_getPrefix
()
{
String
os
=
System
.
getProperty
(
"os.name"
);
String
lowerCaseOs
=
os
.
toLowerCase
();
if
(
lowerCaseOs
.
contains
(
"windows"
))
return
""
;
return
"lib"
;
fun
_getPrefix
():
String
{
val
os
=
System
.
getProperty
(
"os.name"
)
val
lowerCaseOs
=
os
.
toLowerCase
()
return
if
(
lowerCaseOs
.
contains
(
"windows"
))
""
else
"lib"
}
public
static
String
_getExtension
()
{
String
os
=
System
.
getProperty
(
"os.name"
);
if
(
os
==
null
)
throw
new
RuntimeException
(
"Unknown operation system"
);
String
lowerCaseOs
=
os
.
toLowerCase
();
if
(
lowerCaseOs
.
contains
(
"mac"
)
||
lowerCaseOs
.
contains
(
"darwin"
))
return
"dylib"
;
if
(
lowerCaseOs
.
contains
(
"windows"
))
return
"dll"
;
if
(
lowerCaseOs
.
contains
(
"nux"
))
return
"so"
;
throw
new
RuntimeException
(
"Unknown operation system: "
+
os
);
fun
_getExtension
():
String
{
val
os
=
System
.
getProperty
(
"os.name"
)
?:
throw
RuntimeException
(
"Unknown operation system"
)
val
lowerCaseOs
=
os
.
toLowerCase
()
if
(
lowerCaseOs
.
contains
(
"mac"
)
||
lowerCaseOs
.
contains
(
"darwin"
))
return
"dylib"
if
(
lowerCaseOs
.
contains
(
"windows"
))
return
"dll"
if
(
lowerCaseOs
.
contains
(
"nux"
))
return
"so"
throw
RuntimeException
(
"Unknown operation system: $os"
)
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment