Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QueryR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Lopez
QueryR
Commits
d44775d0
Commit
d44775d0
authored
8 years ago
by
Mick Jordan
Browse files
Options
Downloads
Patches
Plain Diff
support jars and dirs in DefaultResourceHandlerfactory
parent
2f2f3516
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/DefaultResourceHandlerFactory.java
+39
-19
39 additions, 19 deletions
...acle/truffle/r/runtime/DefaultResourceHandlerFactory.java
with
39 additions
and
19 deletions
com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/DefaultResourceHandlerFactory.java
+
39
−
19
View file @
d44775d0
...
...
@@ -22,8 +22,11 @@
*/
package
com.oracle.truffle.r.runtime
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.net.URI
;
import
java.net.URL
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
...
...
@@ -60,26 +63,43 @@ class DefaultResourceHandlerFactory extends ResourceHandlerFactory implements Ha
CodeSource
source
=
accessor
.
getProtectionDomain
().
getCodeSource
();
ArrayList
<
String
>
list
=
new
ArrayList
<>();
try
{
URL
jarURL
=
source
.
getLocation
();
JarFile
fastrJar
=
new
JarFile
(
new
File
(
jarURL
.
toURI
()));
Enumeration
<
JarEntry
>
iter
=
fastrJar
.
entries
();
while
(
iter
.
hasMoreElements
())
{
JarEntry
entry
=
iter
.
nextElement
();
String
name
=
entry
.
getName
();
if
(
name
.
endsWith
(
".R"
)
||
name
.
endsWith
(
".r"
))
{
Path
p
=
Paths
.
get
(
name
);
String
entryPkg
=
p
.
getName
(
p
.
getNameCount
()
-
3
).
getFileName
().
toString
();
String
entryParent
=
p
.
getName
(
p
.
getNameCount
()
-
2
).
getFileName
().
toString
();
if
(
entryParent
.
equals
(
"R"
)
&&
entryPkg
.
equals
(
pkgName
))
{
int
size
=
(
int
)
entry
.
getSize
();
byte
[]
buf
=
new
byte
[
size
];
InputStream
is
=
fastrJar
.
getInputStream
(
entry
);
int
totalRead
=
0
;
int
n
;
while
((
n
=
is
.
read
(
buf
,
totalRead
,
buf
.
length
-
totalRead
))
>
0
)
{
totalRead
+=
n
;
URL
url
=
source
.
getLocation
();
Path
sourcePath
=
Paths
.
get
(
url
.
toURI
().
getPath
());
File
sourceFile
=
sourcePath
.
toFile
();
if
(
sourceFile
.
isDirectory
())
{
InputStream
is
=
accessor
.
getResourceAsStream
(
pkgName
+
"/R"
);
if
(
is
!=
null
)
{
try
(
BufferedReader
r
=
new
BufferedReader
(
new
InputStreamReader
(
is
)))
{
String
line
;
while
((
line
=
r
.
readLine
())
!=
null
)
{
if
(
line
.
endsWith
(
".r"
)
||
line
.
endsWith
(
".R"
))
{
final
String
rResource
=
pkgName
+
"/R/"
+
line
.
trim
();
list
.
add
(
Utils
.
getResourceAsString
(
accessor
,
rResource
,
true
));
}
}
}
}
}
else
{
JarFile
fastrJar
=
new
JarFile
(
sourceFile
);
Enumeration
<
JarEntry
>
iter
=
fastrJar
.
entries
();
while
(
iter
.
hasMoreElements
())
{
JarEntry
entry
=
iter
.
nextElement
();
String
name
=
entry
.
getName
();
if
(
name
.
endsWith
(
".R"
)
||
name
.
endsWith
(
".r"
))
{
Path
p
=
Paths
.
get
(
name
);
String
entryPkg
=
p
.
getName
(
p
.
getNameCount
()
-
3
).
getFileName
().
toString
();
String
entryParent
=
p
.
getName
(
p
.
getNameCount
()
-
2
).
getFileName
().
toString
();
if
(
entryParent
.
equals
(
"R"
)
&&
entryPkg
.
equals
(
pkgName
))
{
int
size
=
(
int
)
entry
.
getSize
();
byte
[]
buf
=
new
byte
[
size
];
InputStream
is
=
fastrJar
.
getInputStream
(
entry
);
int
totalRead
=
0
;
int
n
;
while
((
n
=
is
.
read
(
buf
,
totalRead
,
buf
.
length
-
totalRead
))
>
0
)
{
totalRead
+=
n
;
}
list
.
add
(
new
String
(
buf
));
}
list
.
add
(
new
String
(
buf
));
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment