summaryrefslogtreecommitdiffstats
path: root/simple/simple-http/src/main/java/org/simpleframework/http/core/EmptyEncoder.java
blob: 7ec78fb82cb90ff9b520be4767e3773673777781 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * EmptyEncoder.java February 2007
 *
 * Copyright (C) 2001, Niall Gallagher <niallg@users.sf.net>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 * implied. See the License for the specific language governing 
 * permissions and limitations under the License.
 */

package org.simpleframework.http.core;

import java.io.IOException;
import java.nio.ByteBuffer;

import org.simpleframework.transport.ByteWriter;

/**
 * The <code>EmptyEncoder</code> object is a producer used if there
 * is not response body to be delivered. Typically this is used when
 * the HTTP request method is HEAD or if there is some status code
 * sent to the client that does not require a response body.
 *
 * @author Niall Gallagher
 */  
class EmptyEncoder implements BodyEncoder {
   
   /**
    * This is the observer that is used to process the pipeline.
    */
   private final BodyObserver observer;
   
   /**
    * This is the writer that is passed to the monitor when ready.
    */
   private final ByteWriter writer;
   
   /**
    * Constructor for the <code>EmptyEncoder</code> object. Once 
    * created this producer will signal the kernel the the next
    * request is ready to read from the HTTP pipeline as there is
    * no content to be delivered with this producer object.
    *
    * @param writer this is used to send to the underlying transport
    * @param observer this is used to deliver signals to the kernel   
    */         
   public EmptyEncoder(BodyObserver observer, ByteWriter writer) {    
      this.observer = observer;
      this.writer = writer;
   }
  
   /**
    * This method performs no operation. Because this producer is
    * not required to generate a response body this will ignore all
    * data that is provided to sent to the underlying transport.
    *
    * @param array this is the array of bytes to send to the client
    */  
   public void encode(byte[] array) throws IOException {
      return;
   }
  
   /**
    * This method performs no operation. Because this producer is
    * not required to generate a response body this will ignore all
    * data that is provided to sent to the underlying transport.
    *
    * @param array this is the array of bytes to send to the client
    * @param off this is the offset within the array to send from
    * @param size this is the number of bytes that are to be sent    
    */     
   public void encode(byte[] array, int off, int size) throws IOException {
      return;
   }
   
   /**
    * This method is used to encode the provided buffer of bytes in
    * a HTTP/1.1 compliant format and sent it to the client. Once
    * the data has been encoded it is handed to the transport layer
    * within the server, which may choose to buffer the data if the
    * content is too small to send efficiently or if the socket is
    * not write ready.
    *
    * @param buffer this is the buffer of bytes to send to the client
    */         
   public void encode(ByteBuffer buffer) throws IOException {
      return;
   }

   /**
    * This method is used to encode the provided buffer of bytes in
    * a HTTP/1.1 compliant format and sent it to the client. Once
    * the data has been encoded it is handed to the transport layer
    * within the server, which may choose to buffer the data if the
    * content is too small to send efficiently or if the socket is
    * not write ready.
    *
    * @param buffer this is the buffer of bytes to send to the client
    * @param off this is the offset within the buffer to send from
    * @param size this is the number of bytes that are to be sent
    */          
   public void encode(ByteBuffer buffer, int off, int size) throws IOException {
      return;
   }
   
   /**
    * This method performs no operation. Because this producer is
    * not required to generate a response body this will ignore all
    * data that is provided to sent to the underlying transport.
    */   
   public void flush() throws IOException {
      return;
   }
 
   /**
    * This method performs no operation. Because this producer is
    * not required to generate a response body this will ignore all
    * data that is provided to sent to the underlying transport.
    */   
   public void close() throws IOException {
      observer.ready(writer);
   }
}