Source Code Cross Referenced for PaddingStringBuffer.java in  » Web-Crawler » heritrix » org » archive » util » 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 » Web Crawler » heritrix » org.archive.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (C) 2003 Internet Archive.
002:         *
003:         * This file is part of the Heritrix web crawler (crawler.archive.org).
004:         *
005:         * Heritrix is free software; you can redistribute it and/or modify
006:         * it under the terms of the GNU Lesser Public License as published by
007:         * the Free Software Foundation; either version 2.1 of the License, or
008:         * any later version.
009:         *
010:         * Heritrix is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013:         * GNU Lesser Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser Public License
016:         * along with Heritrix; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         *
019:         * PaddingStringBuffer.java
020:         * Created on Oct 23, 2003
021:         *
022:         * $Header$
023:         */
024:        package org.archive.util;
025:
026:        /**
027:         * StringBuffer-like utility which can add spaces to reach a certain column.  It
028:         * allows you to append {@link String}, <code>long</code> and <code>int</code>s
029:         * to the buffer.
030:         * <p>
031:         * Note: This class counts from 1, not 0.
032:         * <p>
033:         * It uses a StringBuffer behind the scenes.
034:         * <p>
035:         * To write a string with multiple lines, it is advisible to use the
036:         * {@link #newline() newline()} function. Regular appending of strings with
037:         * newlines (\n) character should be safe though. Right appending of strings
038:         * with such characters is <i>not</i> safe.
039:         *
040:         * @author Gordon Mohr
041:         */
042:        public final class PaddingStringBuffer {
043:            // The buffer.
044:            StringBuffer buffer;
045:            // Location in current line
046:            int linePos;
047:
048:            /** 
049:             * Create a new PaddingStringBuffer
050:             *
051:             */
052:            public PaddingStringBuffer() {
053:                buffer = new StringBuffer();
054:                linePos = 0;
055:            }
056:
057:            /** append a string directly to the buffer
058:             * @param string the string to append
059:             * @return This wrapped buffer w/ the passed string appended.
060:             */
061:            public PaddingStringBuffer append(String string) {
062:                buffer.append(string);
063:                if (string.indexOf('\n') == -1) {
064:                    linePos += string.length();
065:                } else {
066:                    while (string.indexOf('\n') == -1) {
067:                        string = string.substring(string.indexOf('\n'));
068:                    }
069:                    linePos = string.length();
070:                }
071:                return this ;
072:            }
073:
074:            /**
075:             * Append a string, right-aligned to the given columm.  If the buffer
076:             * length is already greater than the column specified, it simply appends
077:             * the string
078:             *
079:             * @param col the column to right-align to
080:             * @param string the string, must not contain multiple lines.
081:             * @return This wrapped buffer w/ append string, right-aligned to the
082:             * given column.
083:             */
084:            public PaddingStringBuffer raAppend(int col, String string) {
085:                padTo(col - string.length());
086:                append(string);
087:                return this ;
088:            }
089:
090:            /** Pad to a given column.  If the buffer size is already greater than the
091:             * column, nothing is done.
092:             * @param col
093:             * @return The buffer padded to <code>i</code>.
094:             */
095:            public PaddingStringBuffer padTo(int col) {
096:                while (linePos < col) {
097:                    buffer.append(" ");
098:                    linePos++;
099:                }
100:                return this ;
101:            }
102:
103:            /** append an <code>int</code> to the buffer.
104:             * @param i the int to append
105:             * @return This wrapped buffer with <code>i</code> appended.
106:             */
107:            public PaddingStringBuffer append(int i) {
108:                append(Integer.toString(i));
109:                return this ;
110:            }
111:
112:            /**
113:             * Append an <code>int</code> right-aligned to the given column.  If the
114:             * buffer length is already greater than the column specified, it simply
115:             * appends the <code>int</code>.
116:             *
117:             * @param col the column to right-align to
118:             * @param i   the int to append
119:             * @return This wrapped buffer w/ appended int, right-aligned to the
120:             *         given column.
121:             */
122:            public PaddingStringBuffer raAppend(int col, int i) {
123:                return raAppend(col, Integer.toString(i));
124:            }
125:
126:            /** append a <code>long</code> to the buffer.
127:             * @param lo the <code>long</code> to append
128:             * @return This wrapped buffer w/ appended long.
129:             */
130:            public PaddingStringBuffer append(long lo) {
131:                append(Long.toString(lo));
132:                return this ;
133:            }
134:
135:            /**Append a <code>long</code>, right-aligned to the given column.  If the
136:             * buffer length is already greater than the column specified, it simply
137:             * appends the <code>long</code>.
138:             * @param col the column to right-align to
139:             * @param lo the long to append
140:             * @return This wrapped buffer w/ appended long, right-aligned to the
141:             * given column.
142:             */
143:            public PaddingStringBuffer raAppend(int col, long lo) {
144:                return raAppend(col, Long.toString(lo));
145:            }
146:
147:            /** reset the buffer back to empty */
148:            public void reset() {
149:                buffer = new StringBuffer();
150:                linePos = 0;
151:            }
152:
153:            /* (non-Javadoc)
154:             * @see java.lang.Object#toString()
155:             */
156:            public String toString() {
157:                return buffer.toString();
158:            }
159:
160:            /**
161:             * Forces a new line in the buffer.
162:             */
163:            public PaddingStringBuffer newline() {
164:                buffer.append("\n");
165:                linePos = 0;
166:                return this;
167:            }
168:
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.