Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
embulk-parser-none-bin
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Klaus Wölfel
embulk-parser-none-bin
Commits
b6db701b
Commit
b6db701b
authored
Sep 25, 2016
by
Klaus Wölfel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow none-parsing of binary files
parent
059f1e3d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
11 deletions
+38
-11
build.gradle
build.gradle
+4
-0
src/main/java/org/embulk/parser/NoneParserPlugin.java
src/main/java/org/embulk/parser/NoneParserPlugin.java
+34
-11
No files found.
build.gradle
View file @
b6db701b
...
@@ -7,6 +7,9 @@ import com.github.jrubygradle.JRubyExec
...
@@ -7,6 +7,9 @@ import com.github.jrubygradle.JRubyExec
repositories
{
repositories
{
mavenCentral
()
mavenCentral
()
jcenter
()
jcenter
()
maven
{
url
"https://repo.maven.apache.org/maven2/"
}
}
}
configurations
{
configurations
{
provided
provided
...
@@ -16,6 +19,7 @@ version = "0.2.0"
...
@@ -16,6 +19,7 @@ version = "0.2.0"
dependencies
{
dependencies
{
compile
"org.embulk:embulk-core:0.6.18"
compile
"org.embulk:embulk-core:0.6.18"
compile
"commons-codec:commons-codec:1.9"
provided
"org.embulk:embulk-core:0.6.18"
provided
"org.embulk:embulk-core:0.6.18"
// compile "YOUR_JAR_DEPENDENCY_GROUP:YOUR_JAR_DEPENDENCY_MODULE:YOUR_JAR_DEPENDENCY_VERSION"
// compile "YOUR_JAR_DEPENDENCY_GROUP:YOUR_JAR_DEPENDENCY_MODULE:YOUR_JAR_DEPENDENCY_VERSION"
testCompile
"junit:junit:4.+"
testCompile
"junit:junit:4.+"
...
...
src/main/java/org/embulk/parser/NoneParserPlugin.java
View file @
b6db701b
...
@@ -14,23 +14,38 @@ import org.embulk.spi.SchemaConfig;
...
@@ -14,23 +14,38 @@ import org.embulk.spi.SchemaConfig;
import
org.embulk.spi.Exec
;
import
org.embulk.spi.Exec
;
import
org.embulk.spi.PageBuilder
;
import
org.embulk.spi.PageBuilder
;
import
org.embulk.spi.util.
LineDecoder
;
import
org.embulk.spi.util.
FileInputInputStream
;
import
org.embulk.spi.ColumnConfig
;
import
org.embulk.spi.ColumnConfig
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
org.apache.commons.codec.binary.Base64
;
import
static
org
.
embulk
.
spi
.
type
.
Types
.
STRING
;
import
static
org
.
embulk
.
spi
.
type
.
Types
.
STRING
;
import
org.slf4j.Logger
;
public
class
NoneParserPlugin
public
class
NoneParserPlugin
implements
ParserPlugin
implements
ParserPlugin
{
{
public
interface
PluginTask
public
interface
PluginTask
extends
Task
,
LineDecoder
.
DecoderTask
//, TimestampParser.Task
extends
Task
//
, LineDecoder.DecoderTask //, TimestampParser.Task
{
{
@Config
(
"column_name"
)
@Config
(
"column_name"
)
@ConfigDefault
(
"\"payload\""
)
@ConfigDefault
(
"\"payload\""
)
public
String
getColumnName
();
public
String
getColumnName
();
}
}
private
final
Logger
log
;
public
NoneParserPlugin
()
{
this
.
log
=
Exec
.
getLogger
(
NoneParserPlugin
.
class
);
}
@Override
@Override
public
void
transaction
(
ConfigSource
config
,
ParserPlugin
.
Control
control
)
public
void
transaction
(
ConfigSource
config
,
ParserPlugin
.
Control
control
)
{
{
...
@@ -49,18 +64,26 @@ public class NoneParserPlugin
...
@@ -49,18 +64,26 @@ public class NoneParserPlugin
FileInput
input
,
PageOutput
output
)
FileInput
input
,
PageOutput
output
)
{
{
PluginTask
task
=
taskSource
.
loadTask
(
PluginTask
.
class
);
PluginTask
task
=
taskSource
.
loadTask
(
PluginTask
.
class
);
LineDecoder
lineDecoder
=
new
LineDecoder
(
input
,
task
);
List
<
String
>
files
=
task
.
getFiles
();
log
.
info
(
""
+
files
);
FileInputInputStream
dataIn
=
new
FileInputInputStream
(
input
);
PageBuilder
pageBuilder
=
new
PageBuilder
(
Exec
.
getBufferAllocator
(),
schema
,
output
);
PageBuilder
pageBuilder
=
new
PageBuilder
(
Exec
.
getBufferAllocator
(),
schema
,
output
);
String
line
=
null
;
String
line
=
null
;
Integer
offset
=
0
;
Integer
bytes_read
=
0
;
Integer
chunksize
=
1024
;
final
String
columnName
=
task
.
getColumnName
();
final
String
columnName
=
task
.
getColumnName
();
while
(
input
.
nextFile
()
){
while
(
input
.
nextFile
()
){
while
(
true
)
{
while
(
true
)
{
line
=
lineDecoder
.
poll
()
;
byte
[]
bytesArray
=
new
byte
[
chunksize
]
;
bytes_read
=
dataIn
.
read
(
bytesArray
,
offset
,
chunksize
);
if
(
line
==
null
)
{
if
(
bytes_read
==
-
1
)
{
break
;
break
;
}
}
offset
+=
bytes_read
;
byte
[]
fittedBytesArray
=
Arrays
.
copyOfRange
(
bytesArray
,
0
,
bytes_read
);
line
=
Base64
.
encodeBase64String
(
fittedBytesArray
);
pageBuilder
.
setString
(
0
,
line
);
pageBuilder
.
setString
(
0
,
line
);
pageBuilder
.
addRecord
();
pageBuilder
.
addRecord
();
...
...
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