hdfs_jruby 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a1cbb43a25387dc8a3ef571e63399526f970413a
4
- data.tar.gz: f9e7d92cc52874584f5403ea1630d0ed1bb59668
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTk1YjliNGRlYTE3MzIxODk2NGI5NzRhODkwOTlmMjljYWI0ZmYzZg==
5
+ data.tar.gz: !binary |-
6
+ OTI4NjYwNWJmZGEzN2YxNjI4MmVmOWM2YzNiNDkyMzg4OWI3NDFjOQ==
5
7
  SHA512:
6
- metadata.gz: 977e86a3dde5c17960c346559331f6dfa4418e066f3112a8e0ddc15b350a82388e0367f956a594685dc3fc94ff65d1d27d848224a27d3f415f52da0a3d5cd46e
7
- data.tar.gz: 2db1991b8b67829d5efc8ee6843509cd2a7c87e68c9aa7072cff01660850a83916f21bf206d7f78cb2d756d042a4ad04aa253ab0713bc964f449bd2140d70ab3
8
+ metadata.gz: !binary |-
9
+ ZGNlOGI1ZGE1ZTdlNGNjZmRlMzdkNWE4NDBmNjg4YWJlOWM2MWViNGY4ZTQ1
10
+ MThkZDZjZmIzNDIwOWRhMTMyZTE4YTdmMjY1MTEzMjdiNTk0YTllMjI1NTQ1
11
+ MzU5MTY4NGRkM2Q4MmNhNDI0NTk0NjFhY2UwMzMxNmM0OGM3MmU=
12
+ data.tar.gz: !binary |-
13
+ MWYyY2RiOGU2OWFmZjk3YTFmNjU5MmE3NTFhNDk4ZDE3ZjJhZDZmNWZhNjgx
14
+ ZjVhNDE0ZjVkMTY5YTQ2MzFkOTI2MTViNDU4MGMzMWY5ZWNiZDc4Y2JhYTdm
15
+ ZTNkYTExZGE5MTE3NGM5OTRmMmExN2VmNTdmMzljNzM5NDZkYzc=
data/README.md CHANGED
@@ -18,7 +18,14 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ require 'hdfs_jruby'
22
+
23
+ ...
24
+
25
+ Hdfs.ls(path) do | stat |
26
+ p stat
27
+ end
28
+
22
29
 
23
30
  ## Contributing
24
31
 
@@ -16,7 +16,6 @@ module Hdfs
16
16
  @stream = @fs.create(Hdfs::Path.new(path), false)
17
17
  elsif mode == "r"
18
18
  @stream = @fs.open(Hdfs::Path.new(path))
19
- @buf = java.nio.ByteBuffer.allocate(65536)
20
19
  elsif mode == "a"
21
20
  p = Hdfs::Path.new(path)
22
21
  if !@fs.exists(p)
@@ -32,7 +31,12 @@ module Hdfs
32
31
 
33
32
  def self.open(path, mode = "r")
34
33
  if block_given?
35
- yield(File.new(path, mode).to_io)
34
+ io = File.new(path, mode).to_io
35
+ begin
36
+ yield(io)
37
+ ensure
38
+ io.close
39
+ end
36
40
  else
37
41
  return File.new(path, mode).to_io
38
42
  end
@@ -1,3 +1,3 @@
1
1
  module Hdfs
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/hdfs_jruby.rb CHANGED
@@ -35,28 +35,52 @@ module Hdfs
35
35
 
36
36
  @conf = Hdfs::Configuration.new()
37
37
  @fs = Hdfs::FileSystem.get(@conf)
38
+
39
+ def ls(path)
40
+ p = _path(path)
41
+ list = @fs.globStatus(p)
42
+ ret_list = []
43
+ list.each do |stat|
44
+ if stat.isDir
45
+ sub_list = @fs.listStatus(stat.getPath)
46
+ sub_list.each do | s |
47
+ if block_given?
48
+ yield _conv(s)
49
+ else
50
+ ret_list << _conv(s)
51
+ end
52
+ end
53
+ else
54
+ if block_given?
55
+ yield _conv(stat)
56
+ else
57
+ ret_list << _conv(stat)
58
+ end
59
+ end
60
+ end
61
+ ret_list if ! block_given?
62
+ end
38
63
 
39
- def list(path, use_glob=true)
64
+ def list(path, opts={})
65
+ use_glob = opts[:glob] ? true : false
40
66
  p = _path(path)
41
- if ! block_given?
42
- raise "error"
67
+
68
+ list = nil
69
+ if use_glob
70
+ list = @fs.globStatus(p)
43
71
  else
44
- list = nil
45
- if use_glob
46
- list = @fs.globStatus(p)
47
- else
48
- list = @fs.listStatus(p)
72
+ list = @fs.listStatus(p)
73
+ end
74
+
75
+ if ! block_given?
76
+ ret_list = []
77
+ list.each do | stat |
78
+ ret_list << _conv(stat)
49
79
  end
80
+ return ret_list
81
+ else
50
82
  list.each do | stat |
51
- file_info = {}
52
- file_info['path'] = stat.getPath.to_s
53
- file_info['length'] = stat.getLen.to_i
54
- file_info['modificationTime'] = stat.getModificationTime.to_i
55
- file_info['owner'] = stat.getOwner.to_s
56
- file_info['group'] = stat.getGroup.to_s
57
- file_info['permission'] = stat.getPermission.toShort.to_i
58
- file_info['type'] = !stat.isDir ? 'FILE': 'DIRECTORY'
59
- yield file_info
83
+ yield _conv(stat)
60
84
  end
61
85
  end
62
86
  end
@@ -132,6 +156,7 @@ module Hdfs
132
156
  module_function :set_permission
133
157
  module_function :set_owner
134
158
  module_function :list
159
+ module_function :ls
135
160
 
136
161
  private
137
162
  def _path(path)
@@ -140,6 +165,19 @@ module Hdfs
140
165
  end
141
166
  Path.new(path)
142
167
  end
168
+
169
+ def _conv(stat)
170
+ file_info = {}
171
+ file_info['path'] = stat.getPath.to_s
172
+ file_info['length'] = stat.getLen.to_i
173
+ file_info['modificationTime'] = stat.getModificationTime.to_i
174
+ file_info['owner'] = stat.getOwner.to_s
175
+ file_info['group'] = stat.getGroup.to_s
176
+ file_info['permission'] = stat.getPermission.toShort.to_i
177
+ file_info['type'] = !stat.isDir ? 'FILE': 'DIRECTORY'
178
+ return file_info
179
+ end
143
180
 
144
181
  module_function :_path
182
+ module_function :_conv
145
183
  end
data/test/test_ls.rb CHANGED
@@ -1,8 +1,10 @@
1
1
 
2
2
  require 'hdfs_jruby'
3
3
 
4
- Hdfs.list(ARGV[0], true) do | stat |
5
- p stat
4
+ list = Hdfs.ls(ARGV[0])
5
+
6
+ list.each do |stat|
7
+ #p stat
6
8
  path = stat['path']
7
9
  length = stat['length']
8
10
  type = stat['type']
data/test/test_write.rb CHANGED
@@ -5,8 +5,12 @@ require 'hdfs_jruby/file'
5
5
  #print f.read
6
6
  #f.close
7
7
 
8
- f = Hdfs::File.open("test_w.txt", "w")
9
- p f.print "test..\ntest\n"
10
- p f.print "test..\ntest\n"
8
+ #f = Hdfs::File.open("test_w.txt", "w")
9
+ #p f.print "test..\ntest\n"
10
+ #p f.print "test..\ntest\n"
11
+ #f.close()
12
+
13
+ Hdfs::File.open("test_w.txt", "w") do |io|
14
+ io.print "test\n"
15
+ end
11
16
 
12
- f.close()
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hdfs_jruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - shinji ikeda
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-24 00:00:00.000000000 Z
11
+ date: 2014-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
- version_requirements: !ruby/object:Gem::Requirement
15
+ requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
- requirement: !ruby/object:Gem::Requirement
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
21
23
  requirements:
22
24
  - - ~>
23
25
  - !ruby/object:Gem::Version
24
26
  version: '1.6'
25
- prerelease: false
26
- type: :development
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
- version_requirements: !ruby/object:Gem::Requirement
29
+ requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- requirement: !ruby/object:Gem::Requirement
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
35
37
  requirements:
36
- - - '>='
38
+ - - ! '>='
37
39
  - !ruby/object:Gem::Version
38
40
  version: '0'
39
- prerelease: false
40
- type: :development
41
41
  description: ''
42
42
  email:
43
43
  - gm.ikeda@gmail.com
@@ -68,24 +68,24 @@ homepage: ''
68
68
  licenses:
69
69
  - MIT
70
70
  metadata: {}
71
- post_install_message:
71
+ post_install_message:
72
72
  rdoc_options: []
73
73
  require_paths:
74
74
  - lib
75
75
  required_ruby_version: !ruby/object:Gem::Requirement
76
76
  requirements:
77
- - - '>='
77
+ - - ! '>='
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - '>='
82
+ - - ! '>='
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubyforge_project:
86
+ rubyforge_project:
87
87
  rubygems_version: 2.2.2
88
- signing_key:
88
+ signing_key:
89
89
  specification_version: 4
90
90
  summary: jruby hdfs api
91
91
  test_files: