001/*
002 * ====================================================================
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *   http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied.  See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 * ====================================================================
020 *
021 * This software consists of voluntary contributions made by many
022 * individuals on behalf of the Apache Software Foundation.  For more
023 * information on the Apache Software Foundation, please see
024 * <http://www.apache.org/>.
025 *
026 */
027
028package org.apache.http.impl.nio.codecs;
029
030import java.io.IOException;
031
032import org.apache.http.HttpResponse;
033import org.apache.http.message.LineFormatter;
034import org.apache.http.nio.reactor.SessionOutputBuffer;
035import org.apache.http.params.HttpParams;
036import org.apache.http.util.CharArrayBuffer;
037
038/**
039 * Default {@link org.apache.http.nio.NHttpMessageWriter} implementation
040 * for {@link HttpResponse}s.
041 *
042 * @since 4.1
043 */
044@SuppressWarnings("deprecation")
045public class DefaultHttpResponseWriter extends AbstractMessageWriter<HttpResponse> {
046
047    /**
048     * @deprecated (4.3) use
049     *   {@link DefaultHttpResponseWriter#DefaultHttpResponseWriter(SessionOutputBuffer, LineFormatter)}
050     */
051    @Deprecated
052    public DefaultHttpResponseWriter(final SessionOutputBuffer buffer,
053                              final LineFormatter formatter,
054                              final HttpParams params) {
055        super(buffer, formatter, params);
056    }
057
058    /**
059     * Creates an instance of DefaultHttpResponseWriter.
060     *
061     * @param buffer the session output buffer.
062     * @param formatter the line formatter If {@code null}
063     *   {@link org.apache.http.message.BasicLineFormatter#INSTANCE} will be used.
064     *
065     * @since 4.3
066     */
067    public DefaultHttpResponseWriter(
068            final SessionOutputBuffer buffer,
069            final LineFormatter formatter) {
070        super(buffer, formatter);
071    }
072
073    /**
074     * @since 4.3
075     */
076    public DefaultHttpResponseWriter(final SessionOutputBuffer buffer) {
077        super(buffer, null);
078    }
079
080    @Override
081    protected void writeHeadLine(final HttpResponse message) throws IOException {
082        final CharArrayBuffer buffer = lineFormatter.formatStatusLine(
083                this.lineBuf, message.getStatusLine());
084        this.sessionBuffer.writeLine(buffer);
085    }
086
087}