Source Code Cross Referenced for TextLineWriter.java in  » Source-Control » sourcejammer » org » sourcejammer » server » source » 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 » Source Control » sourcejammer » org.sourcejammer.server.source 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright (C) 2001, 2002 Robert MacGrogan
003:         *
004:         *  This library is free software; you can redistribute it and/or
005:         *  modify it under the terms of the GNU Lesser General Public
006:         *  License as published by the Free Software Foundation; either
007:         *  version 2.1 of the License, or (at your option) any later version.
008:         *
009:         *  This library is distributed in the hope that it will be useful,
010:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:         *  Lesser General Public License for more details.
013:         *
014:         *  You should have received a copy of the GNU Lesser General Public
015:         *  License along with this library; if not, write to the Free Software
016:         *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017:         *
018:         *
019:         * $Archive: SourceJammer$
020:         * $FileName: TextLineWriter.java$
021:         * $FileID: 4487$
022:         *
023:         * Last change:
024:         * $AuthorName: Rob MacGrogan$
025:         * $Date: 4/23/03 5:20 PM$
026:         * $Comment: Replaced GPL header with LGPL header.$
027:         *
028:         * $KeyWordsOff: $
029:         */
030:
031:        package org.sourcejammer.server.source;
032:
033:        /**
034:         * Title:        SourceJammer
035:         * Description:  Server code for SourceJammer Java open-source source control project.
036:         * Copyright:    Copyright (c) 2001
037:         * Company:      Robert MacGrogan
038:         * @author Robert MacGrogan
039:         * @version 1.0
040:         */
041:
042:        import org.sourcejammer.util.AppConfig;
043:        import org.sourcejammer.server.make.EndOfSourceException;
044:
045:        /**
046:         * @deprecated This clas is deprecated. Only kept in here in case conversion
047:         * from old text file format is required.
048:         * 
049:         * This class is used to append lines into a char array, using a specified
050:         * end of line char array (typically linefeed or carriage return / linefeed.
051:         *
052:         * The lines passed into this class should not include the end of line
053:         * characters. If the end of line characters are included, these characters
054:         * will be doubled in the final output.
055:         */
056:        public class TextLineWriter implements  TextLineAdder,
057:                java.io.Serializable {
058:
059:            private char[] mcaText;
060:            private int miIndex;
061:            private char[] mcaEndOfLine;
062:
063:            private static final int DEFAULT_BUFFER_START_SIZE = 10000;
064:
065:            /**
066:             * Default constructor. Creates a TextLineWriter with default
067:             * buffer size and default end of line characters.
068:             */
069:            public TextLineWriter() {
070:                this (DEFAULT_BUFFER_START_SIZE);
071:            }
072:
073:            /**
074:             * Constructs a TextLineWriter with the passed-in starting buffer size
075:             * and the default end of line characters.<br /><br />
076:             *
077:             * It is important to use an accurate starting buffer size. The buffer
078:             * will resize automatically if the output grows larger than the starting
079:             * size, but the process of resizing the buffer is fairly inefficient.
080:             *
081:             * @param size - starting size of the buffer (number of characters
082:             *               expected in the final output.
083:             */
084:            public TextLineWriter(int size) {
085:                this (size, AppConfig.getInstance().getDefaultEndOfLine());
086:            }
087:
088:            /**
089:             * Constructs a TextLineWriter with the passed-in end of line characters
090:             * using the default buffer size.
091:             *
092:             * @param endOfLine -- a character array containing the end of line characters
093:             *               to use for the output of this TextLineWriter.
094:             */
095:            public TextLineWriter(char[] endOfLine) {
096:                this (DEFAULT_BUFFER_START_SIZE, endOfLine);
097:            }
098:
099:            /**
100:             * Constructs a TextLineWriter with the passed-in starting buffer size
101:             * and end of line characters.
102:             *
103:             * @param size - starting size of the buffer (number of characters
104:             *               expected in the final output.
105:             * @param endOfLine -- a character array containing the end of line characters
106:             *               to use for the output of this TextLineWriter.
107:             */
108:            public TextLineWriter(int size, char[] endOfLine) {
109:                mcaText = new char[size];
110:                mcaEndOfLine = endOfLine;
111:                miIndex = 0;
112:            }
113:
114:            /**
115:             * Adds a line to this TextLineWriter. This class will append the end of line
116:             * characters to the end of the line.
117:             *
118:             * @param line -- a line of text as a char array.
119:             */
120:            public void writeLine(char[] line) {
121:                if (miIndex + (line.length + mcaEndOfLine.length) >= mcaText.length) {
122:                    redimCharArray();
123:                }
124:                for (int i = 0; i < line.length; i++) {
125:                    mcaText[miIndex] = line[i];
126:                    miIndex++;
127:                }
128:                //System.out.print("xx " + String.valueOf(line));
129:                for (int i = 0; i < mcaEndOfLine.length; i++) {
130:                    //System.out.print("EOL char.");
131:                    mcaText[miIndex] = mcaEndOfLine[i];
132:                    miIndex++;
133:                }
134:                //System.out.println();
135:            }
136:
137:            /**
138:             * Adds a line to this TextLineWriter. This class will append the end of line
139:             * characters to the end of the line.
140:             *
141:             * @param line -- a line of text as a String.
142:             */
143:            public void writeLine(String sLine) {
144:                char[] line = sLine.toCharArray();
145:                writeLine(line);
146:            }
147:
148:            /**
149:             * Writes the entire contents of the TextLineIterator to this TextLineWriter,
150:             * beginning with the current line in the iterator.
151:             *
152:             * @param oIterator -- a TextLineIterator.
153:             */
154:            public void write(TextLineIterator oIterator) {
155:                try {
156:                    while (oIterator.hasMoreLines()) {
157:                        writeLine(oIterator.getNextLine());
158:                    }
159:                } catch (EndOfSourceException ex) {
160:                    //ignore. Just Stop adding lines.
161:                }
162:            }
163:
164:            /**
165:             * Writes the contents of this TextLineWriter to a char array. The char array
166:             * includes the end of line characters.
167:             */
168:            public char[] toCharArray() {
169:                //This ensures we don't return a char array with a bunch of empty chars.
170:                //And that a superfluous eol char is not appended to end of file.
171:                int iReturnSize = miIndex - mcaEndOfLine.length;
172:                char[] caReturn = new char[iReturnSize];
173:                for (int i = 0; i < iReturnSize; i++) {
174:                    caReturn[i] = mcaText[i];
175:                }
176:                return caReturn;
177:            }
178:
179:            /**
180:             * Resizes the buffer for this TextLineWriter.<br /><br />
181:             *
182:             * Avoid calling this method if possible. It will be pretty slow.
183:             */
184:            private void redimCharArray() {
185:                if (mcaText.length * 10 >= Integer.MAX_VALUE) {
186:                    //throw exception
187:                }
188:                int iNewSize = mcaText.length * 10;
189:                char[] caBuf = new char[iNewSize];
190:                for (int i = 0; i < mcaText.length; i++) {
191:                    caBuf[i] = mcaText[i];
192:                }
193:                mcaText = caBuf;
194:            }
195:
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.