View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2011 Michael Mimo Moratti.
3    *  
4    * Michael Mimo Moratti licenses this file to you under the Apache License, version 2.0
5    * (the "License"); you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at:
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
11   * License for the specific language governing permissions and limitations
12   * under the License.
13   *******************************************************************************/
14  package ch.mimo.netty.handler.codec.icap;
15  
16  import org.jboss.netty.buffer.ChannelBuffer;
17  
18  /**
19   * Encodes an ICAP Request which takes an @see {@link IcapRequest} or @see {@link IcapChunk} to encode.
20   * 
21   * @author Michael Mimo Moratti (mimo@mimo.ch)
22   *
23   */
24  public class IcapRequestEncoder extends IcapMessageEncoder {
25  
26  	public IcapRequestEncoder() {
27  		super();
28  	}
29  	
30  	@Override
31  	protected int encodeInitialLine(ChannelBuffer buffer, IcapMessage message) throws Exception {
32  		IcapRequest request = (IcapRequest) message;
33  		int index = buffer.readableBytes();
34          buffer.writeBytes(request.getMethod().toString().getBytes(IcapCodecUtil.ASCII_CHARSET));
35          buffer.writeByte(IcapCodecUtil.SPACE);
36          buffer.writeBytes(request.getUri().getBytes(IcapCodecUtil.ASCII_CHARSET));
37          buffer.writeByte(IcapCodecUtil.SPACE);
38          buffer.writeBytes(request.getProtocolVersion().toString().getBytes(IcapCodecUtil.ASCII_CHARSET));
39          buffer.writeBytes(IcapCodecUtil.CRLF);
40          return buffer.readableBytes() - index;
41  	}
42  
43  }