Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/extensions/jruby.rb

Class Method Summary collapse

Class Method Details

.binwrite(path, data) ⇒ Object

何故かエンコーディングエラーが出るため



20
21
22
23
24
# File 'lib/extensions/jruby.rb', line 20

def self.binwrite(path, data)
  open(path, "wb") do |fp|
    fp.write(data)
  end
end

.mtime(path) ⇒ Object

-Dfile.encoding=UTF-8 を指定するとなぜか File.mtime がマルチバイト文字を含むパスを認識出来ないため



27
28
29
30
31
# File 'lib/extensions/jruby.rb', line 27

def self.mtime(path)
  java_path = java.nio.file.FileSystems.default.getPath(path)
  java_file_time = java.nio.file.Files.getLastModifiedTime(java_path)
  Time.parse(java_file_time.to_s).getlocal("+09:00")
end

.write(path, string, *options) ⇒ Object



20
21
22
23
24
25
# File 'lib/extension.rb', line 20

def File.write(path, string, *options)
  dirname = File.dirname(path)
  temp_path = File.join(dirname, SecureRandom.hex(15))
  super(temp_path, string, *options)
  File.rename(temp_path, path)
end