Source Code Cross Referenced for TFTPAckPacket.java in  » Net » Apache-commons-net-1.4.1 » org » apache » commons » net » tftp » 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 » Apache commons net 1.4.1 » org.apache.commons.net.tftp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2005 The Apache Software Foundation
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.commons.net.tftp;
017:
018:        import java.net.DatagramPacket;
019:        import java.net.InetAddress;
020:
021:        /***
022:         * A final class derived from TFTPPacket definiing the TFTP Acknowledgement
023:         * packet type.
024:         * <p>
025:         * Details regarding the TFTP protocol and the format of TFTP packets can
026:         * be found in RFC 783.  But the point of these classes is to keep you
027:         * from having to worry about the internals.  Additionally, only very
028:         * few people should have to care about any of the TFTPPacket classes
029:         * or derived classes.  Almost all users should only be concerned with the
030:         * {@link org.apache.commons.net.tftp.TFTPClient} class
031:         * {@link org.apache.commons.net.tftp.TFTPClient#receiveFile receiveFile()}
032:         * and
033:         * {@link org.apache.commons.net.tftp.TFTPClient#sendFile sendFile()}
034:         * methods.
035:         * <p>
036:         * <p>
037:         * @author Daniel F. Savarese
038:         * @see TFTPPacket
039:         * @see TFTPPacketException
040:         * @see TFTP
041:         ***/
042:
043:        public final class TFTPAckPacket extends TFTPPacket {
044:            /*** The block number being acknowledged by the packet. ***/
045:            int _blockNumber;
046:
047:            /***
048:             * Creates an acknowledgment packet to be sent to a host at a given port
049:             * acknowledging receipt of a block.
050:             * <p>
051:             * @param destination  The host to which the packet is going to be sent.
052:             * @param port  The port to which the packet is going to be sent.
053:             * @param blockNumber  The block number being acknowledged.
054:             ***/
055:            public TFTPAckPacket(InetAddress destination, int port,
056:                    int blockNumber) {
057:                super (TFTPPacket.ACKNOWLEDGEMENT, destination, port);
058:                _blockNumber = blockNumber;
059:            }
060:
061:            /***
062:             * Creates an acknowledgement packet based from a received
063:             * datagram.  Assumes the datagram is at least length 4, else an
064:             * ArrayIndexOutOfBoundsException may be thrown.
065:             * <p>
066:             * @param datagram  The datagram containing the received acknowledgement.
067:             * @throws TFTPPacketException  If the datagram isn't a valid TFTP
068:             *         acknowledgement packet.
069:             ***/
070:            TFTPAckPacket(DatagramPacket datagram) throws TFTPPacketException {
071:                super (TFTPPacket.ACKNOWLEDGEMENT, datagram.getAddress(),
072:                        datagram.getPort());
073:                byte[] data;
074:
075:                data = datagram.getData();
076:
077:                if (getType() != data[1])
078:                    throw new TFTPPacketException(
079:                            "TFTP operator code does not match type.");
080:
081:                _blockNumber = (((data[2] & 0xff) << 8) | (data[3] & 0xff));
082:            }
083:
084:            /***
085:             * This is a method only available within the package for
086:             * implementing efficient datagram transport by elminating buffering.
087:             * It takes a datagram as an argument, and a byte buffer in which
088:             * to store the raw datagram data.  Inside the method, the data
089:             * is set as the datagram's data and the datagram returned.
090:             * <p>
091:             * @param datagram  The datagram to create.
092:             * @param data The buffer to store the packet and to use in the datagram.
093:             * @return The datagram argument.
094:             ***/
095:            DatagramPacket _newDatagram(DatagramPacket datagram, byte[] data) {
096:                data[0] = 0;
097:                data[1] = (byte) _type;
098:                data[2] = (byte) ((_blockNumber & 0xffff) >> 8);
099:                data[3] = (byte) (_blockNumber & 0xff);
100:
101:                datagram.setAddress(_address);
102:                datagram.setPort(_port);
103:                datagram.setData(data);
104:                datagram.setLength(4);
105:
106:                return datagram;
107:            }
108:
109:            /***
110:             * Creates a UDP datagram containing all the TFTP
111:             * acknowledgement packet data in the proper format.
112:             * This is a method exposed to the programmer in case he
113:             * wants to implement his own TFTP client instead of using
114:             * the {@link org.apache.commons.net.tftp.TFTPClient}
115:             * class.  Under normal circumstances, you should not have a need to call this
116:             * method.
117:             * <p>
118:             * @return A UDP datagram containing the TFTP acknowledgement packet.
119:             ***/
120:            public DatagramPacket newDatagram() {
121:                byte[] data;
122:
123:                data = new byte[4];
124:                data[0] = 0;
125:                data[1] = (byte) _type;
126:                data[2] = (byte) ((_blockNumber & 0xffff) >> 8);
127:                data[3] = (byte) (_blockNumber & 0xff);
128:
129:                return new DatagramPacket(data, data.length, _address, _port);
130:            }
131:
132:            /***
133:             * Returns the block number of the acknowledgement.
134:             * <p>
135:             * @return The block number of the acknowledgement.
136:             ***/
137:            public int getBlockNumber() {
138:                return _blockNumber;
139:            }
140:
141:            /*** Sets the block number of the acknowledgement.  ***/
142:            public void setBlockNumber(int blockNumber) {
143:                _blockNumber = blockNumber;
144:            }
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.