diff src/org/eclipse/jetty/server/HttpOutput.java @ 972:5ee36654b383

simplify AbstractHttpConnection
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 15 Oct 2016 22:42:05 -0600
parents 3428c60d7cfc
children dbecd7faa1f5
line wrap: on
line diff
--- a/src/org/eclipse/jetty/server/HttpOutput.java	Fri Oct 14 13:06:06 2016 -0600
+++ b/src/org/eclipse/jetty/server/HttpOutput.java	Sat Oct 15 22:42:05 2016 -0600
@@ -41,143 +41,143 @@
  */
 public class HttpOutput extends ServletOutputStream 
 {
-    protected final AbstractHttpConnection _connection;
-    protected final AbstractGenerator _generator;
-    private boolean _closed;
-    private ByteArrayBuffer _onebyte;
-    
-    // These are held here for reuse by Writer
-    String _characterEncoding;
-    Writer _converter;
-    char[] _chars;
-    ByteArrayOutputStream2 _bytes;
+	protected final AbstractHttpConnection _connection;
+	protected final AbstractGenerator _generator;
+	private boolean _closed;
+	private ByteArrayBuffer _onebyte;
+	
+	// These are held here for reuse by Writer
+	String _characterEncoding;
+	Writer _converter;
+	char[] _chars;
+	ByteArrayOutputStream2 _bytes;
 
-    /* ------------------------------------------------------------ */
-    public HttpOutput(AbstractHttpConnection connection)
-    {
-        _connection=connection;
-        _generator=(AbstractGenerator)connection.getGenerator();
-    }
+	/* ------------------------------------------------------------ */
+	public HttpOutput(AbstractHttpConnection connection)
+	{
+		_connection = connection;
+		_generator = connection._generator;
+	}
 
-    /* ------------------------------------------------------------ */
-    public int getMaxIdleTime()
-    {
-        return _connection.getMaxIdleTime();
-    }
-    
-    /* ------------------------------------------------------------ */
-    public boolean isWritten()
-    {
-        return _generator.getContentWritten()>0;
-    }
-    
-    /* ------------------------------------------------------------ */
-    /*
-     * @see java.io.OutputStream#close()
-     */
-    @Override
-    public void close() throws IOException
-    {
-        _closed=true;
-    }
-    
-    /* ------------------------------------------------------------ */
-    public boolean isClosed()
-    {
-        return _closed;
-    }
-    
-    /* ------------------------------------------------------------ */
-    public void reopen()
-    {
-        _closed=false;
-    }
-    
-    /* ------------------------------------------------------------ */
-    @Override
-    public void flush() throws IOException
-    {
-        _generator.flush(getMaxIdleTime());
-    }
+	/* ------------------------------------------------------------ */
+	public int getMaxIdleTime()
+	{
+		return _connection.getMaxIdleTime();
+	}
+	
+	/* ------------------------------------------------------------ */
+	public boolean isWritten()
+	{
+		return _generator.getContentWritten()>0;
+	}
+	
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see java.io.OutputStream#close()
+	 */
+	@Override
+	public void close() throws IOException
+	{
+		_closed=true;
+	}
+	
+	/* ------------------------------------------------------------ */
+	public boolean isClosed()
+	{
+		return _closed;
+	}
+	
+	/* ------------------------------------------------------------ */
+	public void reopen()
+	{
+		_closed=false;
+	}
+	
+	/* ------------------------------------------------------------ */
+	@Override
+	public void flush() throws IOException
+	{
+		_generator.flush(getMaxIdleTime());
+	}
 
-    /* ------------------------------------------------------------ */
-    @Override
-    public void write(byte[] b, int off, int len) throws IOException
-    {
-        write(new ByteArrayBuffer(b,off,len));
-    }
+	/* ------------------------------------------------------------ */
+	@Override
+	public void write(byte[] b, int off, int len) throws IOException
+	{
+		write(new ByteArrayBuffer(b,off,len));
+	}
 
-    /* ------------------------------------------------------------ */
-    /*
-     * @see java.io.OutputStream#write(byte[])
-     */
-    @Override
-    public void write(byte[] b) throws IOException
-    {
-        write(new ByteArrayBuffer(b));
-    }
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see java.io.OutputStream#write(byte[])
+	 */
+	@Override
+	public void write(byte[] b) throws IOException
+	{
+		write(new ByteArrayBuffer(b));
+	}
 
-    
-    /* ------------------------------------------------------------ */
-    /*
-     * @see java.io.OutputStream#write(int)
-     */
-    @Override
-    public void write(int b) throws IOException
-    {
-        if (_onebyte==null)
-            _onebyte=new ByteArrayBuffer(1);
-        else
-            _onebyte.clear();
-        _onebyte.put((byte)b);
-        write(_onebyte);
-    }
+	
+	/* ------------------------------------------------------------ */
+	/*
+	 * @see java.io.OutputStream#write(int)
+	 */
+	@Override
+	public void write(int b) throws IOException
+	{
+		if (_onebyte==null)
+			_onebyte=new ByteArrayBuffer(1);
+		else
+			_onebyte.clear();
+		_onebyte.put((byte)b);
+		write(_onebyte);
+	}
 
-    /* ------------------------------------------------------------ */
-    private void write(Buffer buffer) throws IOException
-    {
-        if (_closed)
-            throw new IOException("Closed");
-        if (!_generator.isOpen())
-            throw new EofException();
-        
-        // Block until we can add _content.
-        while (_generator.isBufferFull())
-        {
-            _generator.blockForOutput(getMaxIdleTime());
-            if (_closed)
-                throw new IOException("Closed");
-            if (!_generator.isOpen())
-                throw new EofException();
-        }
+	/* ------------------------------------------------------------ */
+	private void write(Buffer buffer) throws IOException
+	{
+		if (_closed)
+			throw new IOException("Closed");
+		if (!_generator.isOpen())
+			throw new EofException();
+		
+		// Block until we can add _content.
+		while (_generator.isBufferFull())
+		{
+			_generator.blockForOutput(getMaxIdleTime());
+			if (_closed)
+				throw new IOException("Closed");
+			if (!_generator.isOpen())
+				throw new EofException();
+		}
 
-        // Add the _content
-        _generator.addContent(buffer, Generator.MORE);
+		// Add the _content
+		_generator.addContent(buffer, Generator.MORE);
 
-        // Have to flush and complete headers?
-        
-        if (_generator.isAllContentWritten())
-        {
-            flush();
-            close();
-        } 
-        else if (_generator.isBufferFull())
-            _connection.commitResponse(Generator.MORE);
+		// Have to flush and complete headers?
+		
+		if (_generator.isAllContentWritten())
+		{
+			flush();
+			close();
+		} 
+		else if (_generator.isBufferFull())
+			_connection.commitResponse(Generator.MORE);
 
-        // Block until our buffer is free
-        while (buffer.length() > 0 && _generator.isOpen())
-        {
-            _generator.blockForOutput(getMaxIdleTime());
-        }
-    }
+		// Block until our buffer is free
+		while (buffer.length() > 0 && _generator.isOpen())
+		{
+			_generator.blockForOutput(getMaxIdleTime());
+		}
+	}
 
-    /* ------------------------------------------------------------ */
-    /* 
-     * @see javax.servlet.ServletOutputStream#print(java.lang.String)
-     */
-    @Override
-    public void print(String s) throws IOException
-    {
-        write(s.getBytes());
-    }
+	/* ------------------------------------------------------------ */
+	/* 
+	 * @see javax.servlet.ServletOutputStream#print(java.lang.String)
+	 */
+	@Override
+	public void print(String s) throws IOException
+	{
+		write(s.getBytes());
+	}
 }