Source Code Cross Referenced for TextLineCodecFactory.java in  » Net » mina-2.0.0-M1 » org » apache » mina » filter » codec » textline » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » mina 2.0.0 M1 » org.apache.mina.filter.codec.textline 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one
003:         *  or more contributor license agreements.  See the NOTICE file
004:         *  distributed with this work for additional information
005:         *  regarding copyright ownership.  The ASF licenses this file
006:         *  to you under the Apache License, Version 2.0 (the
007:         *  "License"); you may not use this file except in compliance
008:         *  with the License.  You may obtain a copy of the License at
009:         *
010:         *    http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         *  Unless required by applicable law or agreed to in writing,
013:         *  software distributed under the License is distributed on an
014:         *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         *  KIND, either express or implied.  See the License for the
016:         *  specific language governing permissions and limitations
017:         *  under the License.
018:         *
019:         */
020:        package org.apache.mina.filter.codec.textline;
021:
022:        import java.nio.charset.Charset;
023:
024:        import org.apache.mina.common.BufferDataException;
025:        import org.apache.mina.common.IoSession;
026:        import org.apache.mina.filter.codec.ProtocolCodecFactory;
027:        import org.apache.mina.filter.codec.ProtocolDecoder;
028:        import org.apache.mina.filter.codec.ProtocolEncoder;
029:
030:        /**
031:         * A {@link ProtocolCodecFactory} that performs encoding and decoding between
032:         * a text line data and a Java string object.  This codec is useful especially
033:         * when you work with a text-based protocols such as SMTP and IMAP.
034:         *
035:         * @author The Apache MINA Project (dev@mina.apache.org)
036:         * @version $Rev: 596187 $, $Date: 2007-11-18 20:41:14 -0700 (Sun, 18 Nov 2007) $
037:         */
038:        public class TextLineCodecFactory implements  ProtocolCodecFactory {
039:
040:            private final TextLineEncoder encoder;
041:            private final TextLineDecoder decoder;
042:
043:            /**
044:             * Creates a new instance with the current default {@link Charset}.
045:             */
046:            public TextLineCodecFactory() {
047:                this (Charset.defaultCharset());
048:            }
049:
050:            /**
051:             * Creates a new instance with the specified {@link Charset}.  The
052:             * encoder uses a UNIX {@link LineDelimiter} and the decoder uses
053:             * the AUTO {@link LineDelimiter}.
054:             *
055:             * @param charset
056:             *  The charset to use in the encoding and decoding
057:             */
058:            public TextLineCodecFactory(Charset charset) {
059:                encoder = new TextLineEncoder(charset, LineDelimiter.UNIX);
060:                decoder = new TextLineDecoder(charset, LineDelimiter.AUTO);
061:            }
062:
063:            /**
064:             * Creates a new instance of TextLineCodecFactory.  This constructor
065:             * provides more flexibility for the developer.
066:             *
067:             * @param charset
068:             *  The charset to use in the encoding and decoding
069:             * @param encodingDelimiter
070:             *  The line delimeter for the encoder
071:             * @param decodingDelimiter
072:             *  The line delimeter for the decoder
073:             */
074:            public TextLineCodecFactory(Charset charset,
075:                    String encodingDelimiter, String decodingDelimiter) {
076:                encoder = new TextLineEncoder(charset, encodingDelimiter);
077:                decoder = new TextLineDecoder(charset, decodingDelimiter);
078:            }
079:
080:            /**
081:             * Creates a new instance of TextLineCodecFactory.  This constructor
082:             * provides more flexibility for the developer.
083:             *
084:             * @param charset
085:             *  The charset to use in the encoding and decoding
086:             * @param encodingDelimiter
087:             *  The line delimeter for the encoder
088:             * @param decodingDelimiter
089:             *  The line delimeter for the decoder
090:             */
091:            public TextLineCodecFactory(Charset charset,
092:                    LineDelimiter encodingDelimiter,
093:                    LineDelimiter decodingDelimiter) {
094:                encoder = new TextLineEncoder(charset, encodingDelimiter);
095:                decoder = new TextLineDecoder(charset, decodingDelimiter);
096:            }
097:
098:            public ProtocolEncoder getEncoder(IoSession session) {
099:                return encoder;
100:            }
101:
102:            public ProtocolDecoder getDecoder(IoSession session) {
103:                return decoder;
104:            }
105:
106:            /**
107:             * Returns the allowed maximum size of the encoded line.
108:             * If the size of the encoded line exceeds this value, the encoder
109:             * will throw a {@link IllegalArgumentException}.  The default value
110:             * is {@link Integer#MAX_VALUE}.
111:             * <p>
112:             * This method does the same job with {@link TextLineEncoder#getMaxLineLength()}.
113:             */
114:            public int getEncoderMaxLineLength() {
115:                return encoder.getMaxLineLength();
116:            }
117:
118:            /**
119:             * Sets the allowed maximum size of the encoded line.
120:             * If the size of the encoded line exceeds this value, the encoder
121:             * will throw a {@link IllegalArgumentException}.  The default value
122:             * is {@link Integer#MAX_VALUE}.
123:             * <p>
124:             * This method does the same job with {@link TextLineEncoder#setMaxLineLength(int)}.
125:             */
126:            public void setEncoderMaxLineLength(int maxLineLength) {
127:                encoder.setMaxLineLength(maxLineLength);
128:            }
129:
130:            /**
131:             * Returns the allowed maximum size of the line to be decoded.
132:             * If the size of the line to be decoded exceeds this value, the
133:             * decoder will throw a {@link BufferDataException}.  The default
134:             * value is <tt>1024</tt> (1KB).
135:             * <p>
136:             * This method does the same job with {@link TextLineDecoder#getMaxLineLength()}.
137:             */
138:            public int getDecoderMaxLineLength() {
139:                return decoder.getMaxLineLength();
140:            }
141:
142:            /**
143:             * Sets the allowed maximum size of the line to be decoded.
144:             * If the size of the line to be decoded exceeds this value, the
145:             * decoder will throw a {@link BufferDataException}.  The default
146:             * value is <tt>1024</tt> (1KB).
147:             * <p>
148:             * This method does the same job with {@link TextLineDecoder#setMaxLineLength(int)}.
149:             */
150:            public void setDecoderMaxLineLength(int maxLineLength) {
151:                decoder.setMaxLineLength(maxLineLength);
152:            }
153:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.