Source Code Cross Referenced for CSVSink.java in  » Scripting » jython » com » ziclix » python » sql » pipe » csv » 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 » Scripting » jython » com.ziclix.python.sql.pipe.csv 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Jython Database Specification API 2.0
003:         *
004:         * $Id: CSVSink.java 2414 2005-02-23 04:26:23Z bzimmer $
005:         *
006:         * Copyright (c) 2001 brian zimmer <bzimmer@ziclix.com>
007:         *
008:         */
009:        package com.ziclix.python.sql.pipe.csv;
010:
011:        import com.ziclix.python.sql.pipe.Sink;
012:        import org.python.core.Py;
013:        import org.python.core.PyObject;
014:
015:        import java.io.PrintWriter;
016:
017:        /**
018:         * The CSVSink writes data out in a Comma Seperated Format.
019:         *
020:         * @author brian zimmer
021:         * @version $Revision: 2414 $
022:         */
023:        public class CSVSink implements  Sink {
024:
025:            /**
026:             * Field header
027:             */
028:            protected boolean header;
029:
030:            /**
031:             * Field delimiter
032:             */
033:            protected String delimiter;
034:
035:            /**
036:             * Field writer
037:             */
038:            protected PrintWriter writer;
039:
040:            /**
041:             * Field converters
042:             */
043:            protected PyObject converters;
044:
045:            /**
046:             * All data will be written to the given PrintWriter.
047:             *
048:             * @param writer the PrintWriter to which data will be written
049:             */
050:            public CSVSink(PrintWriter writer) {
051:                this (writer, Py.None);
052:            }
053:
054:            /**
055:             * All data will be written to the given PrintWriter.  If
056:             * the converters param is not None, then an attempt will
057:             * be made to convert the object using the given converter.
058:             *
059:             * @param writer     the PrintWriter to which data will be written
060:             * @param converters an indexed dictionary of callable objects used for converting objects to strings
061:             */
062:            public CSVSink(PrintWriter writer, PyObject converters) {
063:
064:                this .header = false;
065:                this .writer = writer;
066:                this .converters = converters;
067:                this .delimiter = ",";
068:            }
069:
070:            /**
071:             * Handle the data callback and write the row out.
072:             */
073:            public void row(PyObject row) {
074:
075:                String[] values = new String[row.__len__()];
076:
077:                if (this .header) {
078:                    for (int i = 0; i < row.__len__(); i++) {
079:                        values[i] = this .convert(Py.newInteger(i), row
080:                                .__getitem__(i));
081:                    }
082:                } else {
083:                    for (int i = 0; i < row.__len__(); i++) {
084:                        values[i] = row.__getitem__(i).__getitem__(0)
085:                                .toString();
086:                    }
087:
088:                    this .header = true;
089:                }
090:
091:                this .println(values);
092:            }
093:
094:            /**
095:             * Convert the object at index to a String.
096:             */
097:            protected String convert(PyObject index, PyObject object) {
098:
099:                if (this .converters != Py.None) {
100:                    PyObject converter = this .converters.__finditem__(index);
101:
102:                    if (converter != Py.None) {
103:                        object = converter.__call__(object);
104:                    }
105:                }
106:
107:                if ((object == Py.None) || (object == null)) {
108:                    return "";
109:                }
110:
111:                return CSVString.toCSV(object.toString());
112:            }
113:
114:            /**
115:             * Print the row of Strings.
116:             */
117:            protected void println(String[] row) {
118:
119:                for (int i = 0; i < row.length - 1; i++) {
120:                    this .writer.print(row[i]);
121:                    this .writer.print(this .delimiter);
122:                }
123:
124:                this .writer.println(row[row.length - 1]);
125:            }
126:
127:            /**
128:             * Method start
129:             */
130:            public void start() {
131:            }
132:
133:            /**
134:             * Method end
135:             */
136:            public void end() {
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.