Package ds.pjftp.representation.impl

Source Code of ds.pjftp.representation.impl.AsciiRepresentation

/*
* pjftp FTP server.
* Copyright (C) 2012 Dmitriy Simbiriatin <dmitriy.simbiriatin@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

package ds.pjftp.representation.impl;

import ds.pjftp.utils.NotNull;

import ds.pjftp.utils.AsciiInputStream;
import ds.pjftp.utils.AsciiOutputStream;
import ds.pjftp.representation.Representation;

import java.net.Socket;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
* Implements {@link Representation} class.
* This class is an implementation of ASCII FTP representation.
* This representation mostly used for transferring text files.
*/
public class AsciiRepresentation extends Representation {

    /**
     * Constructs AsciiRepresentation object.
     */
    public AsciiRepresentation() {
        // Not used here.
    }

    /**
     * Returns an input stream of current representation.
     * All the new line characters will be converted from local
     * format to '\r\n'.
     * @param client ftp client.
     * @return an input stream of current representation.
     * @throws IOException if failed to get input stream.
     */
    @Override
    public InputStream getInputStream(@NotNull final Socket client) throws IOException {
        return new AsciiInputStream(client.getInputStream());
    }

    /**
     * Returns an output stream of current representation.
     * All the new line characters will be converted from '\r\n'
     * to local format.
     * @param client ftp client.
     * @return an output stream of current representation.
     * @throws IOException if failed to get output stream.
     */
    @Override
    public OutputStream getOutputStream(@NotNull final Socket client) throws IOException {
        return new AsciiOutputStream(client.getOutputStream());
    }

    /**
     * Returns name of representation.
     * @return name of representation.
     */
    @Override
    public String toString() {
        return "ASCII";
    }
}
TOP

Related Classes of ds.pjftp.representation.impl.AsciiRepresentation

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.