示例#1
0
    @JRubyMethod(name = "new", frame = true, meta = true)
    public static RubyGzipFile newInstance(IRubyObject recv, Block block) {
      RubyClass klass = (RubyClass) recv;

      RubyGzipFile result = (RubyGzipFile) klass.allocate();

      result.callInit(new IRubyObject[0], block);

      return result;
    }
示例#2
0
    private static IRubyObject wrapBlock(ThreadContext context, RubyGzipFile instance, Block block)
        throws IOException {
      if (block.isGiven()) {
        try {
          block.yield(context, instance);

          return instance.getRuntime().getNil();
        } finally {
          if (!instance.isClosed()) instance.close();
        }
      }

      return instance;
    }
示例#3
0
 @JRubyMethod(name = "open", required = 1, frame = true, meta = true)
 public static IRubyObject open(
     final ThreadContext context, IRubyObject recv, IRubyObject filename, Block block)
     throws IOException {
   Ruby runtime = recv.getRuntime();
   IRubyObject io =
       RuntimeHelpers.invoke(
           context, runtime.getFile(), "open", filename, runtime.newString("rb"));
   RubyGzipReader gzio = newInstance(recv, new IRubyObject[] {io}, block);
   return RubyGzipFile.wrapBlock(context, gzio, block);
 }
示例#4
0
    @JRubyMethod(name = "open", required = 1, optional = 2, frame = true, meta = true)
    public static IRubyObject open(
        final ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block)
        throws IOException {
      Ruby runtime = recv.getRuntime();
      IRubyObject level = runtime.getNil();
      IRubyObject strategy = runtime.getNil();

      if (args.length > 1) {
        level = args[1];
        if (args.length > 2) strategy = args[2];
      }

      IRubyObject io =
          RuntimeHelpers.invoke(
              context, runtime.getFile(), "open", args[0], runtime.newString("wb"));
      RubyGzipWriter gzio = newGzipWriter(recv, new IRubyObject[] {io, level, strategy}, block);
      return RubyGzipFile.wrapBlock(context, gzio, block);
    }