Source Code Cross Referenced for ByteOutputBuffer.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » jj2000 » j2k » entropy » encoder » 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 » 6.0 JDK Modules » Java Advanced Imaging » jj2000.j2k.entropy.encoder 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: ByteOutputBuffer.java,v $
003:         * $Revision: 1.1 $
004:         * $Date: 2005/02/11 05:02:07 $
005:         * $State: Exp $
006:         *
007:         * Class:                   ByteOutputBuffer
008:         *
009:         * Description:             Provides buffering for byte based output, similar
010:         *                          to the standard class ByteArrayOutputStream
011:         *
012:         *                          the old jj2000.j2k.io.ByteArrayOutput class by
013:         *                          Diego SANTA CRUZ, Apr-26-1999
014:         *
015:         *
016:         * COPYRIGHT:
017:         *
018:         * This software module was originally developed by Raphaël Grosbois and
019:         * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel
020:         * Askelöf (Ericsson Radio Systems AB); and Bertrand Berthelot, David
021:         * Bouchard, Félix Henry, Gerard Mozelle and Patrice Onno (Canon Research
022:         * Centre France S.A) in the course of development of the JPEG2000
023:         * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This
024:         * software module is an implementation of a part of the JPEG 2000
025:         * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio
026:         * Systems AB and Canon Research Centre France S.A (collectively JJ2000
027:         * Partners) agree not to assert against ISO/IEC and users of the JPEG
028:         * 2000 Standard (Users) any of their rights under the copyright, not
029:         * including other intellectual property rights, for this software module
030:         * with respect to the usage by ISO/IEC and Users of this software module
031:         * or modifications thereof for use in hardware or software products
032:         * claiming conformance to the JPEG 2000 Standard. Those intending to use
033:         * this software module in hardware or software products are advised that
034:         * their use may infringe existing patents. The original developers of
035:         * this software module, JJ2000 Partners and ISO/IEC assume no liability
036:         * for use of this software module or modifications thereof. No license
037:         * or right to this software module is granted for non JPEG 2000 Standard
038:         * conforming products. JJ2000 Partners have full right to use this
039:         * software module for his/her own purpose, assign or donate this
040:         * software module to any third party and to inhibit third parties from
041:         * using this software module for non JPEG 2000 Standard conforming
042:         * products. This copyright notice must be included in all copies or
043:         * derivative works of this software module.
044:         *
045:         * Copyright (c) 1999/2000 JJ2000 Partners.
046:         *
047:         *
048:         *
049:         */
050:
051:        package jj2000.j2k.entropy.encoder;
052:
053:        import java.io.*;
054:
055:        /**
056:         * This class provides a buffering output stream similar to
057:         * ByteArrayOutputStream, with some additional methods.
058:         *
059:         * <P>Once an array has been written to an output stream or to a byte
060:         * array, the object can be reused as a new stream if the reset()
061:         * method is called.
062:         *
063:         * <P>Unlike the ByteArrayOutputStream class, this class is not thread safe.
064:         *
065:         * @see #reset
066:         * */
067:        public class ByteOutputBuffer {
068:
069:            /** The buffer where the data is stored */
070:            byte buf[];
071:
072:            /** The number of valid bytes in the buffer */
073:            int count;
074:
075:            /** The buffer increase size */
076:            public final static int BUF_INC = 512;
077:
078:            /** The default initial buffer size */
079:            public final static int BUF_DEF_LEN = 256;
080:
081:            /**
082:             * Creates a new byte array output stream. The buffer capacity is
083:             * initially BUF_DEF_LEN bytes, though its size increases if necessary.
084:             *
085:             *
086:             * */
087:            public ByteOutputBuffer() {
088:                buf = new byte[BUF_DEF_LEN];
089:            }
090:
091:            /**
092:             * Creates a new byte array output stream, with a buffer capacity
093:             * of the specified size, in bytes.
094:             *
095:             * @param size the initial size.
096:             *
097:             *
098:             * */
099:            public ByteOutputBuffer(int size) {
100:                buf = new byte[size];
101:            }
102:
103:            /**
104:             * Writes the specified byte to this byte array output stream. The
105:             * functionality provided by this implementation is the same as for the
106:             * one in the superclass, however this method is not synchronized and
107:             * therefore not safe thread, but faster.
108:             *
109:             * @param b The byte to write
110:             *
111:             *
112:             * */
113:            public final void write(int b) {
114:                if (count == buf.length) { // Resize buffer
115:                    byte tmpbuf[] = buf;
116:                    buf = new byte[buf.length + BUF_INC];
117:                    System.arraycopy(tmpbuf, 0, buf, 0, count);
118:                }
119:                buf[count++] = (byte) b;
120:            }
121:
122:            /**
123:             * Copies the specified part of the stream to the 'outbuf' byte
124:             * array.
125:             *
126:             * @param off The index of the first element in the stream to
127:             * copy.
128:             *
129:             * @param len The number of elements of the array to copy
130:             *
131:             * @param outbuf The destination array
132:             *
133:             * @param outoff The index of the first element in 'outbuf' where
134:             * to write the data.
135:             *
136:             *
137:             * */
138:            public void toByteArray(int off, int len, byte outbuf[], int outoff) {
139:                // Copy the data
140:                System.arraycopy(buf, off, outbuf, outoff, len);
141:            }
142:
143:            /**
144:             * Returns the number of valid bytes in the output buffer (count class
145:             * variable).
146:             *
147:             * @return The number of bytes written to the buffer
148:             *
149:             * */
150:            public int size() {
151:                return count;
152:            }
153:
154:            /**
155:             * Discards all the buffered data, by resetting the counter of written
156:             * bytes to 0.
157:             *
158:             * */
159:            public void reset() {
160:                count = 0;
161:            }
162:
163:            /**
164:             * Returns the byte buffered at the given position in the buffer. The
165:             * position in the buffer is the index of the 'write()' method call after
166:             * the last call to 'reset()'.
167:             *
168:             * @param pos The position of the byte to return
169:             *
170:             * @return The value (betweeb 0-255) of the byte at position 'pos'.
171:             *
172:             * */
173:            public int getByte(int pos) {
174:                if (pos >= count) {
175:                    throw new IllegalArgumentException();
176:                }
177:                return buf[pos] & 0xFF;
178:            }
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.