Source Code Cross Referenced for EncodingServer.java in  » Swing-Library » jEdit » org » gjt » sp » jedit » io » 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 » Swing Library » jEdit » org.gjt.sp.jedit.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * :tabSize=8:indentSize=8:noTabs=false:
003:         * :folding=explicit:collapseFolds=1:
004:         *
005:         * Copyright (C) 2007 Kazutoshi Satoda
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or any later version.
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         */
020:
021:        package org.gjt.sp.jedit.io;
022:
023:        //{{{ Imports
024:        import java.io.InputStream;
025:        import java.io.OutputStream;
026:        import java.io.Reader;
027:        import java.io.Writer;
028:        import java.io.IOException;
029:        import java.nio.charset.Charset;
030:        import java.nio.charset.IllegalCharsetNameException;
031:        import java.nio.charset.UnsupportedCharsetException;
032:        import java.util.Set;
033:        import java.util.HashSet;
034:        import java.util.Iterator;
035:        import java.util.Arrays;
036:
037:        import org.gjt.sp.jedit.jEdit;
038:        import org.gjt.sp.jedit.ServiceManager;
039:
040:        //}}}
041:
042:        /**
043:         * A class for some static methods to deal with encodings.
044:         *
045:         * @since 4.3pre10
046:         * @author Kazutoshi Satoda
047:         */
048:        public class EncodingServer {
049:            //{{{ getEncoding() method
050:            /**
051:             * Returns an instance of Encoding for specified name.
052:             * The name is used for search the following domains in the
053:             * listed order.
054:             *   - java.nio.charset.Charset
055:             *   - jEdit ServiceManager
056:             */
057:            public static Encoding getEncoding(String name) {
058:                try {
059:                    return new CharsetEncoding(name);
060:                } catch (IllegalCharsetNameException e) {
061:                    // just failed
062:                } catch (UnsupportedCharsetException e) {
063:                    // just failed
064:                }
065:
066:                Object namedService = ServiceManager.getService(serviceClass,
067:                        name);
068:                if (namedService != null && namedService instanceof  Encoding) {
069:                    return (Encoding) namedService;
070:                }
071:
072:                // UnsupportedCharsetException is for java.nio.charset,
073:                // but throw this here too so that this can be caught as
074:                // an encoding error by catch clause for general I/O code.
075:                throw new UnsupportedCharsetException("No such encoding: \""
076:                        + name + "\"");
077:            } //}}}
078:
079:            //{{{ getAvailableNames() method
080:            /**
081:             * Returns the set of all available encoding names.
082:             */
083:            public static Set<String> getAvailableNames() {
084:                Set<String> set = new HashSet<String>();
085:                set.addAll(Charset.availableCharsets().keySet());
086:                set.addAll(Arrays.asList(ServiceManager
087:                        .getServiceNames(serviceClass)));
088:                return set;
089:            } //}}}
090:
091:            //{{{ getSelectedNames() method
092:            /**
093:             * Returns the set of user selected encoding names.
094:             */
095:            public static Set<String> getSelectedNames() {
096:                Set<String> set = getAvailableNames();
097:                Iterator<String> i = set.iterator();
098:                while (i.hasNext()) {
099:                    String name = i.next();
100:                    if (jEdit.getBooleanProperty("encoding.opt-out." + name,
101:                            false)) {
102:                        i.remove();
103:                    }
104:                }
105:                return set;
106:            } //}}}
107:
108:            //{{{ getTextReader() method
109:            /**
110:             * Returns a Reader object that reads the InputStream with
111:             * the encoding. This method is same with
112:             * "getEncoding(encoding).getTextReader(in)".
113:             */
114:            public static Reader getTextReader(InputStream in, String encoding)
115:                    throws IOException {
116:                return getEncoding(encoding).getTextReader(in);
117:            } //}}}
118:
119:            //{{{ getTextWriter() method
120:            /**
121:             * Returns a Writer object that writes to the OutputStream with
122:             * the encoding. This method is same with
123:             * "getEncoding(encoding).getTextWriter(out)".
124:             */
125:            public static Writer getTextWriter(OutputStream out, String encoding)
126:                    throws IOException {
127:                return getEncoding(encoding).getTextWriter(out);
128:            } //}}}
129:
130:            //{{{ hasEncoding() method
131:            /**
132:             * Returns if the specified name is supported as a name for an Encoding.
133:             */
134:            public static boolean hasEncoding(String name) {
135:                try {
136:                    if (Charset.isSupported(name)) {
137:                        return true;
138:                    }
139:                } catch (IllegalCharsetNameException e) {
140:                    // The name is illegal for java.nio.charset.Charset.
141:                    // But it may be legal for service name.
142:                }
143:
144:                return Arrays.asList(
145:                        ServiceManager.getServiceNames(serviceClass)).contains(
146:                        name);
147:            } //}}}
148:
149:            //{{{ Private members
150:            private static final String serviceClass = "org.gjt.sp.jedit.io.Encoding";
151:            //}}}
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.