Source Code Cross Referenced for StringBufferInputStream.java in  » Apache-Harmony-Java-SE » java-package » java » 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 » Apache Harmony Java SE » java package » java.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package java.io;
019:
020:        import org.apache.harmony.luni.util.Msg;
021:
022:        /**
023:         * StringBufferInputStream is a class for to allow a String to be used as an
024:         * InputStream.
025:         * 
026:         * @deprecated Use StringReader
027:         */
028:        @Deprecated
029:        public class StringBufferInputStream extends InputStream {
030:            /**
031:             * The String containing the data to read.
032:             */
033:            protected String buffer;
034:
035:            /**
036:             * The total number of characters inside the buffer.
037:             */
038:            protected int count;
039:
040:            /**
041:             * The current position within the String buffer.
042:             */
043:            protected int pos;
044:
045:            /**
046:             * Constructs a new StringBufferInputStream on the String <code>str</code>.
047:             * 
048:             * @param str
049:             *            the String to read characters from.
050:             */
051:            public StringBufferInputStream(String str) {
052:                if (str == null) {
053:                    throw new NullPointerException();
054:                }
055:                buffer = str;
056:                count = str.length();
057:            }
058:
059:            /**
060:             * Answers an int representing then number of characters that are available
061:             * to read.
062:             * 
063:             * @return the number of characters available.
064:             * 
065:             */
066:            @Override
067:            public synchronized int available() {
068:                return count - pos;
069:            }
070:
071:            /**
072:             * Reads a single byte from this InputStream and returns the result as an
073:             * int. The low-order byte is returned or -1 of the end of stream was
074:             * encountered.
075:             * 
076:             * @return the byte read or -1 if end of stream.
077:             */
078:            @Override
079:            public synchronized int read() {
080:                return pos < count ? buffer.charAt(pos++) & 0xFF : -1;
081:            }
082:
083:            /**
084:             * Reads at most <code>length</code> bytes from this InputStream and
085:             * stores them in byte array <code>b</code> starting at
086:             * <code>offset</code>. Answer the number of bytes actually read or -1 if
087:             * no bytes were read and end of stream was encountered.
088:             * 
089:             * @param b
090:             *            the byte array in which to store the read bytes.
091:             * @param offset
092:             *            the offset in <code>b</code> to store the read bytes.
093:             * @param length
094:             *            the maximum number of bytes to store in <code>b</code>.
095:             * @return the number of bytes actually read or -1 if end of stream.
096:             */
097:            @Override
098:            public synchronized int read(byte b[], int offset, int length) {
099:                // According to 22.7.6 should return -1 before checking other
100:                // parameters.
101:                if (pos >= count) {
102:                    return -1;
103:                }
104:                if (b == null) {
105:                    throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
106:                }
107:                // avoid int overflow
108:                if (offset < 0 || offset > b.length || length < 0
109:                        || length > b.length - offset) {
110:                    throw new ArrayIndexOutOfBoundsException();
111:                }
112:                if (length == 0) {
113:                    return 0;
114:                }
115:
116:                int copylen = count - pos < length ? count - pos : length;
117:                for (int i = 0; i < copylen; i++) {
118:                    b[offset + i] = (byte) buffer.charAt(pos + i);
119:                }
120:                pos += copylen;
121:                return copylen;
122:            }
123:
124:            /**
125:             * Reset this InputStream to position 0. Reads/Skips will now take place
126:             * from this position.
127:             * 
128:             */
129:            @Override
130:            public synchronized void reset() {
131:                pos = 0;
132:            }
133:
134:            /**
135:             * Skips <code>count</code> number of characters in this InputStream.
136:             * Subsequent <code>read()</code>'s will not return these characters
137:             * unless <code>reset()</code> is used.
138:             * 
139:             * @param n
140:             *            the number of characters to skip.
141:             * @return the number of characters actually skipped.
142:             */
143:            @Override
144:            public synchronized long skip(long n) {
145:                if (n <= 0) {
146:                    return 0;
147:                }
148:
149:                int numskipped;
150:                if (this .count - pos < n) {
151:                    numskipped = this .count - pos;
152:                    pos = this .count;
153:                } else {
154:                    numskipped = (int) n;
155:                    pos += n;
156:                }
157:                return numskipped;
158:            }
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.