Source Code Cross Referenced for FastInputStream.java in  » JMX » je » com » sleepycat » 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 » JMX » je » com.sleepycat.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*-
002:         * See the file LICENSE for redistribution information.
003:         *
004:         * Copyright (c) 2000,2008 Oracle.  All rights reserved.
005:         *
006:         * $Id: FastInputStream.java,v 1.18.2.2 2008/01/07 15:14:21 cwl Exp $
007:         */
008:
009:        package com.sleepycat.util;
010:
011:        import java.io.IOException;
012:        import java.io.InputStream;
013:
014:        /**
015:         * A replacement for ByteArrayInputStream that does not synchronize every
016:         * byte read.
017:         *
018:         * <p>This class extends {@link InputStream} and its <code>read()</code>
019:         * methods allow it to be used as a standard input stream.  In addition, it
020:         * provides <code>readFast()</code> methods that are not declared to throw
021:         * <code>IOException</code>.  <code>IOException</code> is never thrown by this
022:         * class.</p>
023:         *
024:         * @author Mark Hayes
025:         */
026:        public class FastInputStream extends InputStream {
027:
028:            protected int len;
029:            protected int off;
030:            protected int mark;
031:            protected byte[] buf;
032:
033:            /**
034:             * Creates an input stream.
035:             *
036:             * @param buffer the data to read.
037:             */
038:            public FastInputStream(byte[] buffer) {
039:
040:                buf = buffer;
041:                len = buffer.length;
042:            }
043:
044:            /**
045:             * Creates an input stream.
046:             *
047:             * @param buffer the data to read.
048:             *
049:             * @param offset the byte offset at which to begin reading.
050:             *
051:             * @param length the number of bytes to read.
052:             */
053:            public FastInputStream(byte[] buffer, int offset, int length) {
054:
055:                buf = buffer;
056:                off = offset;
057:                len = offset + length;
058:            }
059:
060:            // --- begin ByteArrayInputStream compatible methods ---
061:
062:            public int available() {
063:
064:                return len - off;
065:            }
066:
067:            public boolean markSupported() {
068:
069:                return true;
070:            }
071:
072:            public void mark(int readLimit) {
073:
074:                mark = off;
075:            }
076:
077:            public void reset() {
078:
079:                off = mark;
080:            }
081:
082:            public long skip(long count) {
083:
084:                int myCount = (int) count;
085:                if (myCount + off > len) {
086:                    myCount = len - off;
087:                }
088:                skipFast(myCount);
089:                return myCount;
090:            }
091:
092:            public int read() throws IOException {
093:
094:                return readFast();
095:            }
096:
097:            public int read(byte[] toBuf) throws IOException {
098:
099:                return readFast(toBuf, 0, toBuf.length);
100:            }
101:
102:            public int read(byte[] toBuf, int offset, int length)
103:                    throws IOException {
104:
105:                return readFast(toBuf, offset, length);
106:            }
107:
108:            // --- end ByteArrayInputStream compatible methods ---
109:
110:            /**
111:             * Equivalent to <code>skip()<code> but takes an int parameter instead of a
112:             * long, and does not check whether the count given is larger than the
113:             * number of remaining bytes.
114:             * @see #skip(long)
115:             */
116:            public final void skipFast(int count) {
117:                off += count;
118:            }
119:
120:            /**
121:             * Equivalent to <code>read()<code> but does not throw
122:             * <code>IOException</code>.
123:             * @see #read()
124:             */
125:            public final int readFast() {
126:
127:                return (off < len) ? (buf[off++] & 0xff) : (-1);
128:            }
129:
130:            /**
131:             * Equivalent to <code>read(byte[])<code> but does not throw
132:             * <code>IOException</code>.
133:             * @see #read(byte[])
134:             */
135:            public final int readFast(byte[] toBuf) {
136:
137:                return readFast(toBuf, 0, toBuf.length);
138:            }
139:
140:            /**
141:             * Equivalent to <code>read(byte[],int,int)<code> but does not throw
142:             * <code>IOException</code>.
143:             * @see #read(byte[],int,int)
144:             */
145:            public final int readFast(byte[] toBuf, int offset, int length) {
146:
147:                int avail = len - off;
148:                if (avail <= 0) {
149:                    return -1;
150:                }
151:                if (length > avail) {
152:                    length = avail;
153:                }
154:                System.arraycopy(buf, off, toBuf, offset, length);
155:                off += length;
156:                return length;
157:            }
158:
159:            /**
160:             * Returns the underlying data being read.
161:             *
162:             * @return the underlying data.
163:             */
164:            public final byte[] getBufferBytes() {
165:
166:                return buf;
167:            }
168:
169:            /**
170:             * Returns the offset at which data is being read from the buffer.
171:             *
172:             * @return the offset at which data is being read.
173:             */
174:            public final int getBufferOffset() {
175:
176:                return off;
177:            }
178:
179:            /**
180:             * Returns the end of the buffer being read.
181:             *
182:             * @return the end of the buffer.
183:             */
184:            public final int getBufferLength() {
185:
186:                return len;
187:            }
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.