public void close() throws IOException {
    if (debugLeaks) {
      openFiles.remove(location);
      if (showOpen) System.out.println("  close " + location);
    }

    if (file == null)
      return;

    // If we are writing and the buffer has been modified, flush the contents
    // of the buffer.
    flush();

    /*
    if (!readonly && bufferModified) {
      file.seek(bufferStart);
      file.write(buffer, 0, dataSize);
    }  */

    // may need to extend file, in case no fill is being used
    // may need to truncate file in case overwriting a longer file
    // use only if minLength is set (by N3iosp)
    long fileSize = file.length();
    if (!readonly && (minLength != 0) && (minLength != fileSize)) {
      file.setLength(minLength);
      // System.out.println("TRUNCATE!!! minlength="+minLength);
    }

    // Close the underlying file object.
    file.close();
    file = null;  // help the gc
  }