Software Developer

Friday, June 26, 2009

Simple but very flexible and usefull terminal encoding converter


#!/usr/bin/jruby

require "java"

def help
p "cnvrt <...>"
end


if (ARGV.size > 0)
begin
charset = java.nio.charset.Charset.for_name ARGV[0]
ARGV.delete_at 0
ARGV.each {|a|
bytes = java.lang.String.new(a).getBytes
buffer = java.nio.ByteBuffer.wrap(bytes)
puts charset.decode(buffer)
}
rescue
p $!
end
else
help
end

1 comment:

Alёna said...

Знаешь, Серёжик, мне кажется, на этом блоге не хватает картинок :):):)