##### Coverage Report - com.sun.grizzly.util.StreamAlgorithm

Classes in this File | Line Coverage | Branch Coverage | Complexity
StreamAlgorithm |
N/A | N/A
N/A | N/A
| 1.0;1

1 |  |
     /*
2 |  |
      *
3 |  |
      * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 |  |
      *
5 |  |
      * Copyright 2007-2008 Sun Microsystems, Inc. All rights reserved.
6 |  |
      *
7 |  |
      * The contents of this file are subject to the terms of either the GNU
8 |  |
      * General Public License Version 2 only ("GPL") or the Common Development
9 |  |
      * and Distribution License("CDDL") (collectively, the "License").  You
10 |  |
      * may not use this file except in compliance with the License. You can obtain
11 |  |
      * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
12 |  |
      * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
13 |  |
      * language governing permissions and limitations under the License.
14 |  |
      *
15 |  |
      * When distributing the software, include this License Header Notice in each
16 |  |
      * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
17 |  |
      * Sun designates this particular file as subject to the "Classpath" exception
18 |  |
      * as provided by Sun in the GPL Version 2 section of the License file that
19 |  |
      * accompanied this code.  If applicable, add the following below the License
20 |  |
      * Header, with the fields enclosed by brackets [] replaced by your own
21 |  |
      * identifying information: "Portions Copyrighted [year]
22 |  |
      * [name of copyright owner]"
23 |  |
      *
24 |  |
      * Contributor(s):
25 |  |
      *
26 |  |
      * If you wish your version of this file to be governed by only the CDDL or
27 |  |
      * only the GPL Version 2, indicate your decision by adding "[Contributor]
28 |  |
      * elects to include this software in this distribution under the [CDDL or GPL
29 |  |
      * Version 2] license."  If you don't indicate a single choice of license, a
30 |  |
      * recipient has the option to distribute your version of this file under
31 |  |
      * either the CDDL, the GPL Version 2 or to extend the choice of license to
32 |  |
      * its licensees as provided above.  However, if you add GPL Version 2 code
33 |  |
      * and therefore, elected the GPL Version 2 license, then the option applies
34 |  |
      * only if the new code is made subject to such option by the copyright
35 |  |
      * holder.
36 |  |
      *
37 |  |
      */
38 |  |
     package com.sun.grizzly.util;
39 |  |
40 |  |
     import java.nio.ByteBuffer;
41 |  |
     import java.nio.channels.SocketChannel;
42 |  |
     /**
43 |  |
      * Generic parsing interface that can be used to implement protocol
44 |  |
      * specific logic parsing.
45 |  |
      *
46 |  |
      * @deprecated Use the ProtocolParser instead.
47 |  |
      *
48 |  |
      * @author Jean-Francois Arcand
49 |  |
      */
50 |  |
     public interface StreamAlgorithm{
51 |  |
52 |  |
53 |  |
         /**
54 |  |
          * Return the stream content-length. If the content-length wasn't parsed,
55 |  |
          * return -1.
56 |  |
          * @return  content length or -1 if content length was not parsed
57 |  |
          */
58 |  |
         public int contentLength();
59 |  |
60 |  |
61 |  |
         /**
62 |  |
          * Return the stream header length. The header length is the length between
63 |  |
          * the start of the stream and the first occurance of character '\r\n' .
64 |  |
          * @return  header length
65 |  |
          */
66 |  |
         public int headerLength();
67 |  |
68 |  |
69 |  |
         /**
70 |  |
          * Allocate a {@link ByteBuffer}
71 |  |
          * @param useDirect allocate a direct {@link ByteBuffer}.
72 |  |
          * @param useView allocate a view {@link ByteBuffer}.
73 |  |
          * @param size the size of the newly created {@link ByteBuffer}.
74 |  |
          * @return a new {@link ByteBuffer}
75 |  |
          */
76 |  |
         public ByteBuffer allocate(boolean useDirect, boolean useView, int size);
77 |  |
78 |  |
79 |  |
         /**
80 |  |
          * Before parsing the bytes, initialize and prepare the algorithm.
81 |  |
          * @param byteBuffer the {@link ByteBuffer} used by this algorithm
82 |  |
          * @return {@link ByteBuffer} used by this algorithm
83 |  |
          */
84 |  |
         public ByteBuffer preParse(ByteBuffer byteBuffer);
85 |  |
86 |  |
87 |  |
         /**
88 |  |
          * Parse the {@link ByteBuffer} and try to determine if the bytes
89 |  |
          * stream has been fully read from the {@link SocketChannel}.
90 |  |
          * @param byteBuffer the bytes read.
91 |  |
          * @return true if the algorithm determines the end of the stream.
92 |  |
          */
93 |  |
         public boolean parse(ByteBuffer byteBuffer);
94 |  |
95 |  |
96 |  |
         /**
97 |  |
          * After parsing the bytes, post process the {@link ByteBuffer}
98 |  |
          * @param byteBuffer the {@link ByteBuffer} used by this algorithm
99 |  |
          * @return {@link ByteBuffer} used by this algorithm
100 |  |
          */
101 |  |
         public ByteBuffer postParse(ByteBuffer byteBuffer);
102 |  |
103 |  |
104 |  |
         /**
105 |  |
          * Recycle the algorithm.
106 |  |
          */
107 |  |
         public void recycle();
108 |  |
109 |  |
110 |  |
         /**
111 |  |
          * Rollback the {@link ByteBuffer} to its previous state in case
112 |  |
          * an error as occured.
113 |  |
          * @param byteBuffer
114 |  |
          * @return  {@link ByteBuffer}
115 |  |
          */
116 |  |
         public ByteBuffer rollbackParseState(ByteBuffer byteBuffer);
117 |  |
118 |  |
119 |  |
         /**
120 |  |
          * The {@link Interceptor} associated with this algorithm.
121 |  |
          * @return {@link Interceptor}
122 |  |
          */
123 |  |
         public Interceptor getHandler();
124 |  |
125 |  |
126 |  |
         /**
127 |  |
          * Set the {@link SocketChannel} used by this algorithm
128 |  |
          * @param socketChannel set {@link SocketChannel}
129 |  |
          */
130 |  |
         public void setSocketChannel(SocketChannel socketChannel);
131 |  |
132 |  |
133 |  |
         /**
134 |  |
          * Set the <code>port</code> this algorithm is used.
135 |  |
          * @param port  port number
136 |  |
          */
137 |  |
         public void setPort(int port);
138 |  |
139 |  |
140 |  |
         /**
141 |  |
          * Return the port
142 |  |
          * @return  port number being used
143 |  |
          */
144 |  |
         public int getPort();
145 |  |
146 |  |
     }
147 |  |