embulk-decoder-unzip 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 254a91d5c8164644ab6c7e16f4250391eaa811b2
4
- data.tar.gz: 543ba43a846465a90233ae910d17abae7ad722c2
3
+ metadata.gz: a7752a0d8a9deefa4462b42140a47b76de3d7f21
4
+ data.tar.gz: 936158b3cdbff5031e5263dc9a97cfe0ec90495f
5
5
  SHA512:
6
- metadata.gz: 54d42e1a652ef22c142f0ef5cfa93e16352e08eb3ce5613a3759b527483d0649b5a9eacb48e4d7e3d7b949b10a54d8aab3359688d64d2432582b482f3e7149a3
7
- data.tar.gz: 785c2ef23a7999e3526bfc68dfb06e58d74b24c869bab8e8f0ad4d816df83a27b0e5d822e31b04d90b6ace55af1ea838dda0fbb9f566247f2eded475593b4ab6
6
+ metadata.gz: 6d6a2dc184c041d52b38a1027ca4a619c803af4814cece3cdc7cfea1e564bd488780bce1588d0c5244b23e60a1fea265d2ea1119c3875600752993b7cceea5c2
7
+ data.tar.gz: 2c0ae19262466aff5c6f359648a60e5b9ecf55d93b161117912a970fdacc115815cf09d2eea9cbef83ccc8e148a5b5ed17dc934a73176c376b4fdb700986bf66
data/.gitignore CHANGED
@@ -10,3 +10,4 @@ build/
10
10
  /.metadata/
11
11
  .classpath
12
12
  .project
13
+ /bin/
@@ -13,7 +13,7 @@ configurations {
13
13
  provided
14
14
  }
15
15
 
16
- version = "0.1.0"
16
+ version = "0.1.1"
17
17
 
18
18
  sourceCompatibility = 1.8
19
19
  targetCompatibility = 1.8
@@ -77,12 +77,12 @@ task gemspec {
77
77
  Gem::Specification.new do |spec|
78
78
  spec.name = "${project.name}"
79
79
  spec.version = "${project.version}"
80
- spec.authors = [""]
80
+ spec.authors = ["fundoshi"]
81
81
  spec.summary = %[Unzip decoder plugin for Embulk]
82
82
  spec.description = %[Decodes Unzip-encoded files read by other file input plugins.]
83
- spec.email = [""]
83
+ spec.email = ["fundoshi.chiclasico@gmail.com"]
84
84
  spec.licenses = ["MIT"]
85
- # TODO set this: spec.homepage = "https://github.com//embulk-decoder-unzip"
85
+ # TODO set this: spec.homepage = "https://github.com/chiclasico/embulk-decoder-unzip"
86
86
 
87
87
  spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
88
88
  spec.test_files = spec.files.grep(%r"^(test|spec)/")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -3,8 +3,6 @@ package org.embulk.decoder.unzip;
3
3
  import java.io.InputStream;
4
4
  import java.io.IOException;
5
5
 
6
- import com.google.common.base.Optional;
7
-
8
6
  import org.embulk.config.Config;
9
7
  import org.embulk.config.ConfigDefault;
10
8
  import org.embulk.config.ConfigInject;
@@ -23,19 +21,9 @@ public class UnzipDecoderPlugin
23
21
  public interface PluginTask
24
22
  extends Task
25
23
  {
26
- // configuration option 1 (required integer)
27
- @Config("option1")
28
- public int getOption1();
29
-
30
- // configuration option 2 (optional string, null is not allowed)
31
- @Config("option2")
32
- @ConfigDefault("\"myvalue\"")
33
- public String getOption2();
34
-
35
- // configuration option 3 (optional string, null is allowed)
36
- @Config("option3")
37
- @ConfigDefault("null")
38
- public Optional<String> getOption3();
24
+ // @Config("skip_on_error")
25
+ // @ConfigDefault("true")
26
+ // public boolean skipOnError();
39
27
 
40
28
  @ConfigInject
41
29
  public BufferAllocator getBufferAllocator();
@@ -54,33 +42,38 @@ public class UnzipDecoderPlugin
54
42
  {
55
43
  final PluginTask task = taskSource.loadTask(PluginTask.class);
56
44
 
57
- // Write your code here :)
58
- throw new UnsupportedOperationException("UnzipDecoderPlugin.open method is not implemented yet");
45
+ final FileInputInputStream files = new FileInputInputStream(fileInput);
59
46
 
60
- // If expect InputStream, you can use this code:
61
-
62
- //final FileInputInputStream files = new FileInputInputStream(fileInput);
63
- //
64
- //return new InputStreamFileInput(
65
- // task.getBufferAllocator(),
66
- // new InputStreamFileInput.Provider() {
67
- // public InputStream openNext() throws IOException
68
- // {
69
- // if (!files.nextFile()) {
70
- // return null;
71
- // }
72
- // return newDecoderInputStream(task, files);
73
- // }
74
- //
75
- // public void close() throws IOException
76
- // {
77
- // files.close();
78
- // }
79
- // });
47
+ InputStreamFileInput isfi = null;
48
+ try {
49
+ isfi = new InputStreamFileInput(
50
+ task.getBufferAllocator(),
51
+ new InputStreamFileInput.Provider() {
52
+ public InputStream openNext() throws IOException
53
+ {
54
+ if (!files.nextFile()) {
55
+ return null;
56
+ }
57
+ return newDecoderInputStream(task, files);
58
+ }
59
+
60
+ public void close() throws IOException
61
+ {
62
+ files.close();
63
+ }
64
+ });
65
+ } catch (Exception e) {
66
+ // if(task.skipOnError()) {
67
+ // System.out.println("skip: " + isfi.hintOfCurrentInputFileNameForLogging());
68
+ // return null;
69
+ // } else
70
+ throw new RuntimeException(e);
71
+ }
72
+ return isfi;
80
73
  }
81
74
 
82
- //private static InputStream newDecoderInputStream(PluginTask task, InputStream file) throws IOException
83
- //{
84
- // return new MyInputStream(file);
85
- //}
75
+ private static InputStream newDecoderInputStream(PluginTask task, InputStream file) throws IOException
76
+ {
77
+ return new UnzipInputStream(file);
78
+ }
86
79
  }
@@ -0,0 +1,29 @@
1
+ package org.embulk.decoder.unzip;
2
+
3
+ import java.io.BufferedInputStream;
4
+ import java.io.IOException;
5
+ import java.io.InputStream;
6
+ import java.nio.charset.StandardCharsets;
7
+ import java.util.zip.ZipEntry;
8
+ import java.util.zip.ZipInputStream;
9
+
10
+ public class UnzipInputStream extends InputStream {
11
+
12
+ private ZipInputStream zis;
13
+
14
+ public UnzipInputStream(InputStream is) {
15
+ zis = new ZipInputStream(new BufferedInputStream(is), StandardCharsets.UTF_8);
16
+ }
17
+
18
+ @Override
19
+ public int read() throws IOException {
20
+
21
+ ZipEntry zipentry = zis.getNextEntry();
22
+ int v = -1;
23
+ if(zipentry != null)
24
+ v = zis.read();
25
+ return v;
26
+
27
+ }
28
+
29
+ }
@@ -1,9 +1,8 @@
1
1
  in:
2
2
  type: file
3
- path_prefix: /tmp/sample.csv
3
+ path_prefix: /tmp/test
4
4
  decoders:
5
5
  - type: unzip
6
- option1: 1
7
6
  parser:
8
7
  charset: UTF-8
9
8
  newline: CRLF
@@ -12,9 +11,7 @@ in:
12
11
  quote: '"'
13
12
  escape: ''
14
13
  null_string: 'NULL'
15
- header_line: true
14
+ header_line: false
16
15
  columns:
17
- - {name: col1, type: long}
18
- - {name: col2, type: long}
19
- - {name: col3, type: string}
16
+ - {name: col1, type: string}
20
17
  out: {type: stdout}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-decoder-unzip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
- - ''
7
+ - fundoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-31 00:00:00.000000000 Z
11
+ date: 2020-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -40,7 +40,7 @@ dependencies:
40
40
  version: '12.0'
41
41
  description: Decodes Unzip-encoded files read by other file input plugins.
42
42
  email:
43
- - ''
43
+ - fundoshi.chiclasico@gmail.com
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
@@ -49,7 +49,7 @@ files:
49
49
  - LICENSE.txt
50
50
  - README.md
51
51
  - build.gradle
52
- - classpath/embulk-decoder-unzip-0.1.0.jar
52
+ - classpath/embulk-decoder-unzip-0.1.1.jar
53
53
  - config/checkstyle/checkstyle.xml
54
54
  - config/checkstyle/default.xml
55
55
  - gradle/wrapper/gradle-wrapper.jar
@@ -59,8 +59,11 @@ files:
59
59
  - lib/embulk/decoder/unzip.rb
60
60
  - lib/embulk/guess/unzip.rb
61
61
  - src/main/java/org/embulk/decoder/unzip/UnzipDecoderPlugin.java
62
+ - src/main/java/org/embulk/decoder/unzip/UnzipInputStream.java
62
63
  - src/main/resources/config.yml
63
64
  - src/main/resources/sample.csv
65
+ - src/main/resources/test1.zip
66
+ - src/main/resources/test2.zip
64
67
  - src/test/java/org/embulk/decoder/unzip/TestUnzipDecoderPlugin.java
65
68
  homepage:
66
69
  licenses: