Source Code Cross Referenced for DeviceBuffer.java in  » Swing-Library » wings3 » org » wings » 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 » wings3 » org.wings.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2000,2005 wingS development team.
003:         *
004:         * This file is part of wingS (http://wingsframework.org).
005:         *
006:         * wingS is free software; you can redistribute it and/or modify
007:         * it under the terms of the GNU Lesser General Public License
008:         * as published by the Free Software Foundation; either version 2.1
009:         * of the License, or (at your option) any later version.
010:         *
011:         * Please see COPYING for the complete licence.
012:         */
013:        package org.wings.io;
014:
015:        import java.io.IOException;
016:
017:        /**
018:         * A Device, that buffers the data written to it to be
019:         * written to some other Device later (see {@link #writeTo(Device)})
020:         *
021:         * @author <a href="mailto:haaf@mercatis.de">Armin Haaf</a>
022:         */
023:        public final class DeviceBuffer implements  Device {
024:            //  private static final byte[] NULL_STRING = "null".getBytes();
025:
026:            private byte[] buffer;
027:
028:            private int position = 0;
029:
030:            private int capacityIncrement;
031:
032:            public DeviceBuffer(int initialCapacity, int capacityIncrement) {
033:                buffer = new byte[initialCapacity];
034:                this .capacityIncrement = capacityIncrement;
035:            }
036:
037:            public boolean isSizePreserving() {
038:                return true;
039:            }
040:
041:            public DeviceBuffer(int initialCapacity) {
042:                this (initialCapacity, -1);
043:            }
044:
045:            public DeviceBuffer() {
046:                this (2000);
047:            }
048:
049:            public void flush() {
050:            }
051:
052:            public void close() {
053:            }
054:
055:            /**
056:             * Print a String.
057:             */
058:            public Device print(String s) throws IOException {
059:
060:                if (s == null)
061:                    return print("null");
062:
063:                int len = s.length();
064:                for (int i = 0; i < len; i++) {
065:                    //
066:                    // XXX NOTE:  This is clearly incorrect for many strings,
067:                    // but is the only consistent approach within the current
068:                    // servlet framework.  It must suffice until servlet output
069:                    // streams properly encode their output.
070:                    //
071:                    write((byte) s.charAt(i));
072:                }
073:                return this ;
074:
075:                /*
076:                  correct implementation would be someting like
077:                 byte[] bytes = NULL_STRING;
078:                 if ( s!=null )
079:                 bytes = s.getBytes();
080:
081:                 return write(bytes);
082:                 */
083:            }
084:
085:            /**
086:             * Print an array of chars.
087:             */
088:            public Device print(char[] c) throws IOException {
089:                return print(c, 0, c.length - 1);
090:            }
091:
092:            /**
093:             * Print a character array.
094:             */
095:            public Device print(char[] c, int start, int len)
096:                    throws IOException {
097:                final int end = start + len;
098:                for (int i = start; i < end; i++)
099:                    print(c[i]);
100:                return this ;
101:            }
102:
103:            /**
104:             * Print an integer.
105:             */
106:            public Device print(int i) throws IOException {
107:                return print(String.valueOf(i));
108:            }
109:
110:            /**
111:             * Print any Object
112:             */
113:            public Device print(Object o) throws IOException {
114:                if (o != null)
115:                    return print(o.toString());
116:                else
117:                    return print("null");
118:            }
119:
120:            /**
121:             * Print a character.
122:             */
123:            public Device print(char c) throws IOException {
124:                return print(String.valueOf(c));
125:            }
126:
127:            /**
128:             * Writes the specified byte to this data output stream.
129:             */
130:            public Device write(int c) throws IOException {
131:                return print(String.valueOf(c));
132:            }
133:
134:            /**
135:             * Writes b.length bytes from the specified byte array to this
136:             * output stream.
137:             *
138:             * @throws IOException
139:             */
140:            public Device write(byte b) throws IOException {
141:                while (position + 1 > buffer.length)
142:                    incrementCapacity();
143:                buffer[position++] = b;
144:                return this ;
145:            }
146:
147:            /**
148:             * Writes b.length bytes from the specified byte array to this
149:             * output stream.
150:             */
151:            public Device write(byte b[]) throws IOException {
152:                return write(b, 0, b.length);
153:            }
154:
155:            public void clear() {
156:                position = 0;
157:            }
158:
159:            private void incrementCapacity() {
160:                byte[] oldBuffer = buffer;
161:
162:                int newCapacity = (capacityIncrement > 0) ? (buffer.length + capacityIncrement)
163:                        : (buffer.length * 2);
164:
165:                buffer = new byte[newCapacity];
166:                System.arraycopy(oldBuffer, 0, buffer, 0, position);
167:            }
168:
169:            /**
170:             * Writes len bytes from the specified byte array starting at offset
171:             * off to this output stream.
172:             */
173:            public Device write(byte b[], int off, int len) throws IOException {
174:                while (position + len > buffer.length)
175:                    incrementCapacity();
176:
177:                System.arraycopy(b, off, buffer, position, len);
178:                position += len;
179:
180:                return this ;
181:            }
182:
183:            public void writeTo(Device d) {
184:                try {
185:                    d.write(buffer, 0, position);
186:                } catch (IOException ignore) {
187:                }
188:            }
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.