@Deprecated private static void cleanupPOpen(POpenTuple tuple) { if (tuple.input.openFile.isOpen()) { try { tuple.input.close(); } catch (RaiseException re) {} } if (tuple.output.openFile.isOpen()) { try { tuple.output.close(); } catch (RaiseException re) {} } if (tuple.error.openFile.isOpen()) { try { tuple.error.close(); } catch (RaiseException re) {} } }
@JRubyMethod @Override public IRubyObject inspect() { StringBuilder val = new StringBuilder(); val.append("#<File:").append(path); if(!openFile.isOpen()) { val.append(" (closed)"); } val.append(">"); return getRuntime().newString(val.toString()); }
@Deprecated private static void cleanupPOpen(POpenTuple tuple) { if (tuple.input.openFile.isOpen()) { try { tuple.input.close(); } catch (RaiseException re) {} } if (tuple.output.openFile.isOpen()) { try { tuple.output.close(); } catch (RaiseException re) {} } if (tuple.error.openFile.isOpen()) { try { tuple.error.close(); } catch (RaiseException re) {} } }
@JRubyMethod @Override public IRubyObject inspect() { StringBuilder val = new StringBuilder(); val.append("#<File:").append(path); if(!openFile.isOpen()) { val.append(" (closed)"); } val.append(">"); return getRuntime().newString(val.toString()); }
@JRubyMethod @Override public IRubyObject inspect() { StringBuilder val = new StringBuilder(); val.append("#<Tempfile:").append(path); if(!openFile.isOpen()) { val.append(" (closed)"); } val.append(">"); return getRuntime().newString(val.toString()); }
@JRubyMethod @Override public IRubyObject inspect() { StringBuilder val = new StringBuilder(); val.append("#<Tempfile:").append(path); if(!openFile.isOpen()) { val.append(" (closed)"); } val.append(">"); return getRuntime().newString(val.toString()); }
@JRubyMethod(rest = true, meta = true) public static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { RubyUDPSocket sock = (RubyUDPSocket) recv.callMethod(context, "new", args); if (!block.isGiven()) { return sock; } try { return block.yield(context, sock); } finally { if (sock.openFile.isOpen()) { sock.close(); } } }
@JRubyMethod(rest = true, meta = true) public static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { RubyUDPSocket sock = (RubyUDPSocket) recv.callMethod(context, "new", args); if (!block.isGiven()) { return sock; } try { return block.yield(context, sock); } finally { if (sock.openFile.isOpen()) { sock.close(); } } }
@JRubyMethod(rest = true, meta = true) public static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { RubyUDPSocket sock = (RubyUDPSocket) recv.callMethod(context, "new", args); if (!block.isGiven()) { return sock; } try { return block.yield(context, sock); } finally { if (sock.openFile.isOpen()) { sock.close(); } } }
@JRubyMethod(rest = true, meta = true) public static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { RubyUDPSocket sock = (RubyUDPSocket) recv.callMethod(context, "new", args); if (!block.isGiven()) { return sock; } try { return block.yield(context, sock); } finally { if (sock.openFile.isOpen()) { sock.close(); } } }
@Override @JRubyMethod public IRubyObject close_read(ThreadContext context) { Ruby runtime = context.runtime; if (!openFile.isOpen()) { throw context.runtime.newIOError("not opened for reading"); } if (!openFile.isWritable()) { close(); } else { // shutdown read try { shutdownInternal(context, 0); } catch (BadDescriptorException e) { throw runtime.newErrnoEBADFError(); } } return context.nil; }
@Override @JRubyMethod public IRubyObject close_read(ThreadContext context) { Ruby runtime = context.runtime; if (!openFile.isOpen()) { throw context.runtime.newIOError("not opened for reading"); } if (!openFile.isWritable()) { close(); } else { // shutdown read try { shutdownInternal(context, 0); } catch (BadDescriptorException e) { throw runtime.newErrnoEBADFError(); } } return context.nil; }
@JRubyMethod @Override public IRubyObject inspect() { final OpenFile openFile = this.openFile; if (openFile == null) return super.inspect(); String className = getMetaClass().getRealClass().getName(); String path = openFile.getPath(); String status = ""; if (path == null || path == "") { if (openFile.fd() == null) { path = ""; status = "(closed)"; } else { path = "fd " + openFile.fd().bestFileno(); } } else if (!openFile.isOpen()) { status = " (closed)"; } return getRuntime().newString("#<" + className + ':' + path + status + '>'); }
@JRubyMethod @Override public IRubyObject inspect() { final OpenFile openFile = this.openFile; if (openFile == null) return super.inspect(); String className = getMetaClass().getRealClass().getName(); String path = openFile.getPath(); String status = ""; if (path == null || path == "") { if (openFile.fd() == null) { path = ""; status = "(closed)"; } else { path = "fd " + openFile.fd().bestFileno(); } } else if (!openFile.isOpen()) { status = " (closed)"; } return getRuntime().newString("#<" + className + ':' + path + status + '>'); }
@Override public IRubyObject inspect() { Ruby runtime = getRuntime(); if (!runtime.is1_9()) return super.inspect(); if (openFile == null) return super.inspect(); Stream stream = openFile.getMainStream(); String className = getMetaClass().getRealClass().getName(); String path = openFile.getPath(); String status = ""; if (path == null) { if (stream == null) { path = ""; status = "(closed)"; } else { path = "fd " + runtime.getFileno(stream.getDescriptor()); } } else if (!openFile.isOpen()) { status = " (closed)"; } String inspectStr = "#<" + className + ":" + path + status + ">"; return runtime.newString(inspectStr); }
@Override public IRubyObject inspect() { Ruby runtime = getRuntime(); if (!runtime.is1_9()) return super.inspect(); if (openFile == null) return super.inspect(); Stream stream = openFile.getMainStream(); String className = getMetaClass().getRealClass().getName(); String path = openFile.getPath(); String status = ""; if (path == null) { if (stream == null) { path = ""; status = "(closed)"; } else { path = "fd " + runtime.getFileno(stream.getDescriptor()); } } else if (!openFile.isOpen()) { status = " (closed)"; } String inspectStr = "#<" + className + ":" + path + status + ">"; return runtime.newString(inspectStr); }
@JRubyMethod public RubyString inspect(ThreadContext context) { final String path = openFile.getPath(); ByteList str = new ByteList(path.length() + 8); str.append('#').append('<'); str.append(((RubyString) getMetaClass().to_s()).getByteList()); str.append(':').append( RubyEncoding.encodeUTF8(path) ); if (!openFile.isOpen()) { str.append(' ').append('('); str.append('c').append('l').append('o').append('s').append('e').append('d'); str.append(')'); } str.append('>'); // MRI knows whether path is UTF-8 so it might return ASCII-8BIT (we do not check) str.setEncoding(UTF8Encoding.INSTANCE); return RubyString.newStringLight(context.runtime, str); }
@JRubyMethod public RubyString inspect(ThreadContext context) { final String path = openFile.getPath(); ByteList str = new ByteList(path.length() + 8); str.append('#').append('<'); str.append(((RubyString) getMetaClass().to_s()).getByteList()); str.append(':').append( RubyEncoding.encodeUTF8(path) ); if (!openFile.isOpen()) { str.append(' ').append('('); str.append('c').append('l').append('o').append('s').append('e').append('d'); str.append(')'); } str.append('>'); // MRI knows whether path is UTF-8 so it might return ASCII-8BIT (we do not check) str.setEncoding(UTF8Encoding.INSTANCE); return RubyString.newStringLight(context.runtime, str); }