code: private synchronized void closeInternal() throws IOException {
      dfsClient.checkOpen();
      isClosed();
  
      try {
          eventStartWrite();
  
          flushBuffer(true, false);       // flush from all upper layers
  
          eventCloseAfterFlushBuffer();
          
          // Mark that this packet is the last packet in block.
          // If there are no outstanding packets and the last packet
          // was not the last one in the current block, then create a
          // packet with empty payload.
          synchronized (dataQueue) {
            if (currentPacket == null && bytesCurBlock != 0) {
              WritePacketClientProfile pktProfile = null;
              if (getProfileData() != null) {
                pktProfile = getProfileData().getWritePacketClientProfile();
              }
              currentPacket = DFSOutputStreamPacketFactory.getPacket(
                DFSOutputStream.this, ifPacketIncludeVersion(),
                getPacketVersion(), packetSize, chunksPerPacket, bytesCurBlock, pktProfile);
            }
            if (currentPacket != null) {
              currentPacket.lastPacketInBlock = true;
            }
          }
                  
        flushInternal();             // flush all data to Datanodes
        isClosed(); // check to see if flushInternal had any exceptions
        closed = true; // allow closeThreads() to showdown threads
  
        closeThreads();
  
        synchronized (dataQueue) {
          if (blockStream != null) {
            blockStream.writeInt(0); // indicate end-of-block to datanode
            blockStream.close();
            blockReplyStream.close();
          }
          if (s != null) {
            for (int i = 0; i < s.length; i++) {
              s[i].close();
            }
            s = null;
          }
        }
  
        streamer = null;
        blockStream = null;
        blockReplyStream = null;
  
        eventCloseReceivedAck();
        
        dfsClient.closeFile(src, lastBlkOffset, getLastBlock());
        
        eventEndClose();
      } finally {
        closed = true;
      }
    }
docs: Closes this output stream and releases any system
  resources associated with this stream.