Source Code Cross Referenced for BEROutputStream.java in  » Net » snmp4j » org » snmp4j » asn1 » 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 » Net » snmp4j » org.snmp4j.asn1 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*_############################################################################
002:          _## 
003:          _##  SNMP4J - BEROutputStream.java  
004:          _## 
005:          _##  Copyright (C) 2003-2008  Frank Fock and Jochen Katz (SNMP4J.org)
006:          _##  
007:          _##  Licensed under the Apache License, Version 2.0 (the "License");
008:          _##  you may not use this file except in compliance with the License.
009:          _##  You may obtain a copy of the License at
010:          _##  
011:          _##      http://www.apache.org/licenses/LICENSE-2.0
012:          _##  
013:          _##  Unless required by applicable law or agreed to in writing, software
014:          _##  distributed under the License is distributed on an "AS IS" BASIS,
015:          _##  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016:          _##  See the License for the specific language governing permissions and
017:          _##  limitations under the License.
018:          _##  
019:          _##########################################################################*/
020:
021:        package org.snmp4j.asn1;
022:
023:        import java.io.*;
024:        import java.nio.ByteBuffer;
025:
026:        /**
027:         * The <code>BEROutputStream</code> class wraps a <code>ByteBuffer</code>
028:         * to support BER encoding. The backing buffer can be accessed directly to
029:         * optimize performance and memory usage.
030:         *
031:         * @author Frank Fock
032:         * @version 1.0
033:         */
034:        public class BEROutputStream extends OutputStream {
035:
036:            private ByteBuffer buffer;
037:            private int offset = 0;
038:
039:            /**
040:             * Creates a BER output stream without a backing buffer set. In order to
041:             * be able to write anything to the stream,
042:             * {@link #setBuffer(ByteBuffer buffer)} has to be
043:             * called before. Otherwise a <code>NullPointerException</code> will be
044:             * thrown when calling one of the <code>write</code> operations.
045:             */
046:            public BEROutputStream() {
047:                this .buffer = null;
048:            }
049:
050:            /**
051:             * Create a <code>BEROutputStream</code> that uses the supplied buffer
052:             * as backing buffer.
053:             * @param buffer
054:             *    a <code>ByteBuffer</code> whose limit and capacity must be greater or
055:             *    equal that the length of the encoded BER stream.
056:             */
057:            public BEROutputStream(ByteBuffer buffer) {
058:                this .buffer = buffer;
059:                this .offset = buffer.position();
060:            }
061:
062:            public void write(int b) throws java.io.IOException {
063:                buffer.put((byte) b);
064:            }
065:
066:            public void write(byte[] b) throws IOException {
067:                buffer.put(b);
068:            }
069:
070:            public void write(byte[] b, int off, int len) throws IOException {
071:                buffer.put(b, off, len);
072:            }
073:
074:            public void close() throws IOException {
075:            }
076:
077:            public void flush() throws IOException {
078:            }
079:
080:            /**
081:             * Rewinds backing buffer and returns it. In contrast to the backing buffer's
082:             * rewind method, this method sets the position of the buffer to the first
083:             * byte of this output stream rather than to the first byte of the underlying
084:             * byte array!
085:             * @return
086:             *    the ByteBuffer backing this output stream with its current position
087:             *    set to the begin of the output stream.
088:             */
089:            public ByteBuffer rewind() {
090:                return (ByteBuffer) buffer.position(offset);
091:            }
092:
093:            /**
094:             * Gets the backing buffer.
095:             * @return
096:             *    the <code>ByteBuffer</code> backing this output stream.
097:             */
098:            public ByteBuffer getBuffer() {
099:                return buffer;
100:            }
101:
102:            /**
103:             * Sets the backing buffer to the supplied one and sets the offset used by
104:             * {@link #rewind()} to the buffers current position.
105:             * @param buffer
106:             *    a <code>ByteBuffer</code> whose limit and capacity must be greater or
107:             *    equal that the length of the encoded BER stream.
108:             */
109:            public void setBuffer(ByteBuffer buffer) {
110:                this .buffer = buffer;
111:                this .offset = buffer.position();
112:            }
113:
114:            /**
115:             * Sets the backing buffer and sets the current position of the stream to
116:             * the buffers limit (end).
117:             * @param buffer
118:             *    a <code>ByteBuffer</code> whose limit and capacity must be greater or
119:             *    equal that the length of the encoded BER stream.
120:             */
121:            public void setFilledBuffer(ByteBuffer buffer) {
122:                this.buffer = buffer;
123:                this.offset = buffer.position();
124:                buffer.position(buffer.limit());
125:            }
126:
127:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.