Class: Swineherd::HadoopFileSystem::HadoopFile
- Inherits:
-
Object
- Object
- Swineherd::HadoopFileSystem::HadoopFile
- Defined in:
- lib/swineherd/filesystem/hadoopfilesystem.rb
Instance Attribute Summary collapse
-
#handle ⇒ Object
Returns the value of attribute handle.
-
#hdfs ⇒ Object
Returns the value of attribute hdfs.
-
#path ⇒ Object
Returns the value of attribute path.
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.
- #puts(string) ⇒ Object
- #read ⇒ Object
- #readline ⇒ 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
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/swineherd/filesystem/hadoopfilesystem.rb', line 186 def initialize path, mode, fs, &blk @fs = fs @path = Path.new(path) case mode when "r" then raise "#{@fs.type(path)} is not a readable file - #{path}" unless @fs.type(path) == "file" @handle = @fs.hdfs.open(@path).to_io(&blk) when "w" then # Open path for writing raise "Path #{path} is a directory." unless (@fs.type(path) == "file") || (@fs.type(path) == "unknown") @handle = @fs.hdfs.create(@path).to_io.to_outputstream if block_given? yield self self.close # muy muy importante end end end |
Instance Attribute Details
#handle ⇒ Object
Returns the value of attribute handle.
181 182 183 |
# File 'lib/swineherd/filesystem/hadoopfilesystem.rb', line 181 def handle @handle end |
#hdfs ⇒ Object
Returns the value of attribute hdfs.
181 182 183 |
# File 'lib/swineherd/filesystem/hadoopfilesystem.rb', line 181 def hdfs @hdfs end |
#path ⇒ Object
Returns the value of attribute path.
181 182 183 |
# File 'lib/swineherd/filesystem/hadoopfilesystem.rb', line 181 def path @path end |
Instance Method Details
#close ⇒ Object
220 221 222 |
# File 'lib/swineherd/filesystem/hadoopfilesystem.rb', line 220 def close @handle.close end |
#puts(string) ⇒ Object
216 217 218 |
# File 'lib/swineherd/filesystem/hadoopfilesystem.rb', line 216 def puts string write(string+"\n") end |
#read ⇒ Object
204 205 206 |
# File 'lib/swineherd/filesystem/hadoopfilesystem.rb', line 204 def read @handle.read end |
#readline ⇒ Object
208 209 210 |
# File 'lib/swineherd/filesystem/hadoopfilesystem.rb', line 208 def readline @handle.readline end |
#write(string) ⇒ Object
212 213 214 |
# File 'lib/swineherd/filesystem/hadoopfilesystem.rb', line 212 def write string @handle.write(string.to_java_string.get_bytes) end |