Class: Swineherd::HadoopFileSystem::HadoopFile

Inherits:
Object
  • Object
show all
Defined in:
lib/swineherd-fs/hadoopfilesystem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Raises:

  • (Errno::EISDIR)


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

#handleObject

Returns the value of attribute handle.



171
172
173
# File 'lib/swineherd-fs/hadoopfilesystem.rb', line 171

def handle
  @handle
end

Instance Method Details

#closeObject



203
204
205
# File 'lib/swineherd-fs/hadoopfilesystem.rb', line 203

def close
  @handle.close
end

#pathObject



191
192
193
# File 'lib/swineherd-fs/hadoopfilesystem.rb', line 191

def path
  @path.toString()
end

#readObject



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