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
6ef9ae14
Commit
6ef9ae14
authored
8 years ago
by
Mick Jordan
Browse files
Options
Downloads
Patches
Plain Diff
implement bzip2 decompression internally
parent
67ecb276
No related branches found
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/RCompression.java
+27
-46
27 additions, 46 deletions
...untime/src/com/oracle/truffle/r/runtime/RCompression.java
with
27 additions
and
46 deletions
com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RCompression.java
+
27
−
46
View file @
6ef9ae14
...
...
@@ -35,6 +35,7 @@ import java.util.zip.GZIPInputStream;
import
com.oracle.truffle.r.runtime.conn.GZIPConnections.GZIPRConnection
;
import
com.oracle.truffle.r.runtime.ffi.RFFIFactory
;
import
org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream
;
import
org.tukaani.xz.LZMA2InputStream
;
import
org.tukaani.xz.XZInputStream
;
...
...
@@ -179,64 +180,44 @@ public class RCompression {
}
}
/**
* This is used by {@link GZIPRConnection}.
*/
@FunctionalInterface
private
interface
CreateInStream
<
T
extends
InputStream
>
{
InputStream
create
(
InputStream
base
)
throws
IOException
;
}
public
static
byte
[]
lzmaUncompressFromFile
(
String
path
)
{
try
{
byte
[]
data
=
Files
.
readAllBytes
(
Paths
.
get
(
path
));
byte
[]
buffer
=
new
byte
[
data
.
length
*
4
];
try
(
XZInputStream
lzmaStream
=
new
XZInputStream
(
new
ByteArrayInputStream
(
data
)))
{
int
totalRead
=
0
;
int
n
;
while
((
n
=
lzmaStream
.
read
(
buffer
,
totalRead
,
buffer
.
length
-
totalRead
))
>
0
)
{
totalRead
+=
n
;
if
(
totalRead
==
buffer
.
length
)
{
byte
[]
newbuffer
=
new
byte
[
buffer
.
length
*
2
];
System
.
arraycopy
(
buffer
,
0
,
newbuffer
,
0
,
buffer
.
length
);
buffer
=
newbuffer
;
}
}
byte
[]
result
=
new
byte
[
totalRead
];
System
.
arraycopy
(
buffer
,
0
,
result
,
0
,
totalRead
);
return
result
;
}
return
genericUncompressFromFile
(
path
,
(
is
)
->
new
XZInputStream
(
is
));
}
catch
(
IOException
ex
)
{
throw
RInternalError
.
shouldNotReachHere
(
ex
);
}
}
public
static
byte
[]
bzipUncompressFromFile
(
String
path
)
{
return
genericUncompressFromFile
(
new
String
[]{
"bzip2"
,
"-dc"
,
path
});
}
private
static
byte
[]
genericUncompressFromFile
(
String
[]
command
)
{
int
rc
;
ProcessBuilder
pb
=
new
ProcessBuilder
(
command
);
pb
.
redirectError
(
Redirect
.
INHERIT
);
try
{
Process
p
=
pb
.
start
();
InputStream
is
=
p
.
getInputStream
();
ProcessOutputManager
.
OutputThreadVariable
readThread
=
new
ProcessOutputManager
.
OutputThreadVariable
(
command
[
0
],
is
);
readThread
.
start
();
rc
=
p
.
waitFor
();
if
(
rc
==
0
)
{
readThread
.
join
();
return
readThread
.
getData
();
}
}
catch
(
InterruptedException
|
IOException
ex
)
{
// fall through
return
genericUncompressFromFile
(
path
,
(
is
)
->
new
BZip2CompressorInputStream
(
is
));
}
catch
(
IOException
ex
)
{
throw
RInternalError
.
shouldNotReachHere
(
ex
);
}
throw
RInternalError
.
shouldNotReachHere
(
join
(
command
));
}
private
static
String
join
(
String
[]
args
)
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
String
s
:
args
)
{
sb
.
append
(
s
);
sb
.
append
(
' '
);
private
static
<
T
extends
InputStream
>
byte
[]
genericUncompressFromFile
(
String
path
,
CreateInStream
<
T
>
creator
)
throws
IOException
{
byte
[]
data
=
Files
.
readAllBytes
(
Paths
.
get
(
path
));
byte
[]
buffer
=
new
byte
[
data
.
length
*
4
];
try
(
InputStream
in
=
creator
.
create
(
new
ByteArrayInputStream
(
data
)))
{
int
totalRead
=
0
;
int
n
;
while
((
n
=
in
.
read
(
buffer
,
totalRead
,
buffer
.
length
-
totalRead
))
>
0
)
{
totalRead
+=
n
;
if
(
totalRead
==
buffer
.
length
)
{
byte
[]
newbuffer
=
new
byte
[
buffer
.
length
*
2
];
System
.
arraycopy
(
buffer
,
0
,
newbuffer
,
0
,
buffer
.
length
);
buffer
=
newbuffer
;
}
}
byte
[]
result
=
new
byte
[
totalRead
];
System
.
arraycopy
(
buffer
,
0
,
result
,
0
,
totalRead
);
return
result
;
}
return
sb
.
toString
();
}
}
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