Note: does not {@link java.io.Writer#flush()} before closing.

@param socket
@param writer
974225
public static void closeQuietly(@Nullable Socket socket, @Nullable Writer writer) {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {

            }
        }
        closeQuietly(socket);
    }
614460
@Override
  public void closeWrite() throws IOException
  {
    if (_isCloseWrite) {
      return;
    }
    
    _isCloseWrite = true;
    
    //OutputStream os = _os;
    //_os = null;
    
    boolean isShutdownOutput = false;

    // since the output stream is opened lazily, we might
    // need to open it
    if (_s != null) {
      try {
        _s.shutdownOutput();
        
        isShutdownOutput = true;
      } catch (UnsupportedOperationException e) {
        log.log(Level.FINEST, e.toString(), e);
      } catch (Exception e) {
        log.finer(e.toString());
        log.log(Level.FINEST, e.toString(), e);
      }
    }

    /*
    // SSLSocket doesn't support shutdownOutput()
    if (! isShutdownOutput && os != null) {
      os.close();
    }
    */
  }
1301383
@Override
    public void write(int data) throws IOException {
        ensureBufferAvailable();
        buffer.backingBuffer().put((byte) data);
        if (!buffer.hasRemaining()) {
            flush(false);
        }
    }
195403
protected synchronized void writerDidExit ()
    {
        // clear out our writer reference
        _writer = null;
        log.debug("Writer thread exited.");

        // let the client observers know that we're logged off
        notifyClientObservers(new ObserverOps.Session(_client) {
            @Override protected void notify (SessionObserver obs) {
                obs.clientDidLogoff(_client);
            }
        });

        // now that the writer thread has gone away, we can safely close our socket and let the
        // client know that the logoff process has completed
        closeChannel();

        // let the client know when we finally go away
        if (_reader == null) {
            clientCleanup(_logonError);
        }
    }
565593
@Override
  public void write(Buffer buffer, boolean isEnd)
    throws IOException
  {
    if (_s == null) {
      buffer.free();
      return;
    }
    
    try {
      _needsFlush = true;
      
      if (buffer.isDirect()) {
        _totalWriteBytes += buffer.length(); 
        _s.write(buffer.direct());
        return;
      }
      
      _totalWriteBytes += buffer.length();
      
      while (buffer.length() > 0) {
        _writeBuffer.clear();
        
        buffer.read(_writeBuffer);
        _writeBuffer.flip();
        
        _s.write(_writeBuffer);
      }
    } catch (IOException e) {
      IOException exn = ClientDisconnectException.create(this + ":" + e, e);
      
      try {
        close();
      } catch (IOException e1) {
      }

      throw exn;
    } finally {
      buffer.free();
    }
  }
98033
private void flushBuffer(ByteBuffer buffer, WritableByteChannel output) throws IOException {
    buffer.flip();
    output.write(buffer);
    buffer.flip();
    buffer.limit(buffer.capacity());
  }
232970
protected void flushBuffer() throws IOException {
		if (capacity == 0) {
			ostream.write(buffer);
			capacity = BITS_IN_BYTE;
			buffer = 0;
			len++;
		}
	}
500473
@Override
    public void flush() throws IOException {
        checkWriter();
        writer.flush();
        try {
            contentStoreUtil.storeContentStream(tempFile,
                                                spaceId,
                                                contentId,
                                                mimetype);
        } catch (DuraCloudRuntimeException ex) {
            throw new IOException("flush failed: " + ex.getMessage(), ex);
        }
    }
785399
@Override
    public void flush() throws IOException {

        if (_callback != null) {
            if (!this._isReady) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Cannot flush stream , output not ready: " + this);
                }
                return;
            }
            else {
                validate();
                flushBuffers();
            }
        }
        else {
            super.flush();
        }

    }
797827
@Override
    public void close() throws IOException {
        dispose();

        if(socket != null) {
            socket.close();
            socket = null;
        }
    }
516070
void closeWriter() throws IOException {
    checkState(isRunning(), "Cannot read items from a %s StreamService", state());
    checkState(socketWriter != null, "Attempted to close the socket before it was opened.");
    try {
      socketWriter.close();
    } catch (IOException e) {
      notifyFailed(e);
      throw e;
    }
    closeStream();
  }
432506
@Override
  public void closeWrite() throws IOException
  {
    if (_isCloseWrite) {
      return;
    }
    
    _isCloseWrite = true;
    
    OutputStream os = _os;
    _os = null;
    
    boolean isShutdownOutput = false;

    // since the output stream is opened lazily, we might
    // need to open it
    if (_s instanceof SSLSocket) {
      // ssl socket cannot be half-closed
      log.finer(L.l("sslSocket can not be half-closed"));
      return;
    }
    else if (_s != null) {
      try {
        _s.shutdownOutput();
        
        isShutdownOutput = true;
      } catch (UnsupportedOperationException e) {
        log.log(Level.FINEST, e.toString(), e);
      } catch (Exception e) {
        log.finer(e.toString());
        log.log(Level.FINEST, e.toString(), e);
      }
    }

    // SSLSocket doesn't support shutdownOutput()
    if (! isShutdownOutput && os != null) {
      os.close();
    }
  }
268277
public void flush() throws IOException {
    // check if the stream has been closed
    checkError();
    
    // how many bytes were written to the buffer
    long totalBytesWritten = buffer.totalWritten();
    
    // unblock reads from the buffer
    buffer.unblockReads();
    
    // wait until the write thread transfers everything from the
    // buffer to the stream
    while (writeThread.totalBytesTransferred < totalBytesWritten) {
      BufferedByteInputOutput.sleep(1);
    }
    
    InjectionHandler.processEvent(
        InjectionEventCore.BUFFEREDBYTEOUTPUTSTREAM_FLUSH,
        writeThread.totalBytesTransferred);
    
    // check error
    checkError();
    
    // block reads
    buffer.blockReads();
    
    // flush the underlying buffer
    underlyingOutputStream.flush();
  }
1319800
void flush(OutputStream out, String encoding)
         throws IOException
    {
        flush(new OutputStreamWriter(out,encoding));
    }
782185
@Override
  public void close()
    throws IOException
  {
    Socket s = _s;
    _s = null;

    if (s != null) {
      try {
        s.close();
      } catch (Exception e) {
      }
    }
  }
719943
public void write()
        throws IOException
    {
        BufferedWriter writer = new BufferedWriter( new OutputStreamWriter( m_outputStream ) );
        for( String line : m_content )
        {
            writer.write( line );
            writer.newLine();
        }
        writer.flush();
        writer.close();
    }
1359769
def flush(self):
        '''
        '''
        with self._lock:
            if self._closed:
                raise IOError('Writer is closed')
            self._byte_queue.join()
            self._writer.flush()