code: public synchronized  void setLastBlockSize(long blockId, long blockSize) {
      assert blocks.size() > 0;
      LocatedBlock last = blocks.get(blocks.size() - 1);
      if (underConstruction && blockSize > last.getBlockSize()) {
        assert blockId == last.getBlock().getBlockId();
        this.setFileLength(this.getFileLength() + blockSize - last.getBlockSize());
        last.setBlockSize(blockSize);
  
        if (LOG.isDebugEnabled()) {
          LOG.debug("DFSClient setting last block " + last + " to length "
              + blockSize + " filesize is now " + getFileLength());
        }
      }
    }
docs: If file is under construction, set block size of the last block. It updates
  file length in the same time.