private void setupModes() {
    data.closedWrite = false;
    data.closedRead = false;

    if (data.modes.isReadOnly()) data.closedWrite = true;
    if (!data.modes.isReadable()) data.closedRead = true;
  }
  @JRubyMethod
  @Override
  public IRubyObject close_write() {
    checkWritable();
    data.closedWrite = true;

    return getRuntime().getNil();
  }
  @JRubyMethod
  @Override
  public IRubyObject close() {
    checkInitialized();
    checkOpen();

    data.closedRead = true;
    data.closedWrite = true;

    return getRuntime().getNil();
  }
  @JRubyMethod(name = "reopen", required = 0, optional = 2)
  @Override
  public IRubyObject reopen(IRubyObject[] args) {
    if (args.length == 1 && !(args[0] instanceof RubyString)) {
      return initialize_copy(args[0]);
    }

    // reset the state
    doRewind();
    data.closedRead = false;
    data.closedWrite = false;
    return initialize(args, Block.NULL_BLOCK);
  }
 private void doFinalize() {
   data.closedRead = true;
   data.closedWrite = true;
   data.internal = null;
 }