Class: Swineherd::HadoopFileSystem::HadoopFile
- Inherits:
-
Object
- Object
- Swineherd::HadoopFileSystem::HadoopFile
- Defined in:
- lib/swineherd-fs/hadoopfilesystem.rb
Instance Attribute Summary collapse
-
#handle ⇒ Object
Returns the value of attribute handle.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(path, mode, fs, &blk) ⇒ HadoopFile
constructor
In order to open input and output streams we must pass around the hadoop fs object itself.
- #path ⇒ Object
- #read ⇒ Object
- #write(string) ⇒ Object
Constructor Details
#initialize(path, mode, fs, &blk) ⇒ HadoopFile
In order to open input and output streams we must pass around the hadoop fs object itself
176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/swineherd-fs/hadoopfilesystem.rb', line 176 def initialize path, mode, fs, &blk raise Errno::EISDIR,"#{path} is a directory" if fs.directory?(path) @path = Path.new(path) case mode when "r" @handle = fs.hdfs.open(@path).to_io(&blk) when "w" @handle = fs.hdfs.create(@path).to_io.to_outputstream if block_given? yield self self.close end end end |
Instance Attribute Details
#handle ⇒ Object
Returns the value of attribute handle.
171 172 173 |
# File 'lib/swineherd-fs/hadoopfilesystem.rb', line 171 def handle @handle end |
Instance Method Details
#close ⇒ Object
203 204 205 |
# File 'lib/swineherd-fs/hadoopfilesystem.rb', line 203 def close @handle.close end |
#path ⇒ Object
191 192 193 |
# File 'lib/swineherd-fs/hadoopfilesystem.rb', line 191 def path @path.toString() end |
#read ⇒ Object
195 196 197 |
# File 'lib/swineherd-fs/hadoopfilesystem.rb', line 195 def read @handle.read end |
#write(string) ⇒ Object
199 200 201 |
# File 'lib/swineherd-fs/hadoopfilesystem.rb', line 199 def write string @handle.write(string.to_java_string.get_bytes) end |