    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017
    018package org.apache.commons.net.tftp;
    019
    020import java.net.DatagramPacket;
    021import java.net.InetAddress;
    022
    023/**
    024 * A class derived from TFTPRequestPacket defining a TFTP read request packet type.
    025 * <p>
    026 * 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
    027 * 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
    028 * should only be concerned with the {@link org.apache.commons.net.tftp.TFTPClient} class {@link org.apache.commons.net.tftp.TFTPClient#receiveFile
    029 * receiveFile()} and {@link org.apache.commons.net.tftp.TFTPClient#sendFile sendFile()} methods.
    030 *
    031 *
    032 * @see TFTPPacket
    033 * @see TFTPRequestPacket
    034 * @see TFTPPacketException
    035 * @see TFTP
    036 */
    037
    038public final class TFTPReadRequestPacket extends TFTPRequestPacket {
    039
    040    /**
    041     * 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
    042     * datagram is at least length 4, else an ArrayIndexOutOfBoundsException may be thrown.
    043     *
    044     * @param datagram The datagram containing the received request.
    045     * @throws TFTPPacketException If the datagram isn't a valid TFTP request packet.
    046     */
    047    TFTPReadRequestPacket(final DatagramPacket datagram) throws TFTPPacketException {
    048        super(TFTPPacket.READ_REQUEST, datagram);
    049    }
    050
    051    /**
    052     * Creates a read request packet to be sent to a host at a given port with a file name and transfer mode request.
    053     *
    054     * @param destination The host to which the packet is going to be sent.
    055     * @param port        The port to which the packet is going to be sent.
    056     * @param fileName    The requested file name.
    057     * @param mode        The requested transfer mode. This should be on of the TFTP class MODE constants (e.g., TFTP.NETASCII_MODE).
    058     */
    059    public TFTPReadRequestPacket(final InetAddress destination, final int port, final String fileName, final int mode) {
    060        super(destination, port, TFTPPacket.READ_REQUEST, fileName, mode);
    061    }
    062
    063    /**
    064     * For debugging
    065     *
    066     * @since 3.6
    067     */
    068    @Override
    069    public String toString() {
    070        return super.toString() + " RRQ " + getFilename() + " " + TFTP.getModeName(getMode());
    071    }
    072}