1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.commons.net.tftp; 19 20 import java.net.DatagramPacket; 21 import java.net.InetAddress; 22 23 /** 24 * A class derived from TFTPRequestPacket defining a TFTP read request packet type. 25 * <p> 26 * Details regarding the TFTP protocol and the format of TFTP packets can be found in RFC 783. But the point of these classes is to keep you from having to 27 * worry about the internals. Additionally, only very few people should have to care about any of the TFTPPacket classes or derived classes. Almost all users 28 * should only be concerned with the {@link org.apache.commons.net.tftp.TFTPClient} class {@link org.apache.commons.net.tftp.TFTPClient#receiveFile 29 * receiveFile()} and {@link org.apache.commons.net.tftp.TFTPClient#sendFile sendFile()} methods. 30 * 31 * 32 * @see TFTPPacket 33 * @see TFTPRequestPacket 34 * @see TFTPPacketException 35 * @see TFTP 36 */ 37 38 public final class TFTPReadRequestPacket extends TFTPRequestPacket { 39 40 /** 41 * Creates a read request packet of based on a received datagram and assumes the datagram has already been identified as a read request. Assumes the 42 * datagram is at least length 4, else an ArrayIndexOutOfBoundsException may be thrown. 43 * 44 * @param datagram The datagram containing the received request. 45 * @throws TFTPPacketException If the datagram isn't a valid TFTP request packet. 46 */ 47 TFTPReadRequestPacket(final DatagramPacket datagram) throws TFTPPacketException { 48 super(TFTPPacket.READ_REQUEST, datagram); 49 } 50 51 /** 52 * Creates a read request packet to be sent to a host at a given port with a file name and transfer mode request. 53 * 54 * @param destination The host to which the packet is going to be sent. 55 * @param port The port to which the packet is going to be sent. 56 * @param fileName The requested file name. 57 * @param mode The requested transfer mode. This should be on of the TFTP class MODE constants (e.g., TFTP.NETASCII_MODE). 58 */ 59 public TFTPReadRequestPacket(final InetAddress destination, final int port, final String fileName, final int mode) { 60 super(destination, port, TFTPPacket.READ_REQUEST, fileName, mode); 61 } 62 63 /** 64 * For debugging 65 * 66 * @since 3.6 67 */ 68 @Override 69 public String toString() { 70 return super.toString() + " RRQ " + getFilename() + " " + TFTP.getModeName(getMode()); 71 } 72 }