<commit_before>package cpsc471.ftp.data;

import java.io.*;
import java.net.Socket;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

/**
 * Used to transfer files and large messages.
 * The actual file transfer portion of the FTP connection.
 */
public abstract class DataChannel {

    // thanks to https://www.ibm.com/developerworks/library/j-zerocopy/
    // for the introduction to SocketChannels, FileChannels, and the
    // transferTo method

    protected SocketChannel socketChannel;

    /**
     * Set the socket channel to use for communications
     * @param socketChannel socketChannel to set
     * @throws IOException if unable to read from socket
     */
    public void setSocketChannel(SocketChannel socketChannel)
            throws IOException {

        this.socketChannel = socketChannel;
        // block allows for more data to transfer more easily, though it's less scalable
        socketChannel.configureBlocking(true);
    }

    /**
     * Download a file
     * @param file file to download
     */
    public void download(File file) throws IOException {

        // todo implement
    };

    /**
     * Upload a file
     * @param file file to upload
     */
    public void upload(File file) throws IOException {

        FileChannel fileChannel = new FileInputStream(file).getChannel();

        // send the file
        long bytesSent = 0, fileLength = file.length();
        while(bytesSent < fileLength) {
            bytesSent += fileChannel.transferTo(
                    bytesSent, // byte offset from which to send
                    fileLength - bytesSent, // number of bytes to send
                    socketChannel // channel to which to send bytes
            );
        }
    }

    /**
     * Upload a large string
     * @param s string to upload
     * @throws IOException thrown if connection issue
     */
    public void upload(String s) throws IOException {

        // todo implement
    };<commit_msg>Added size param to download function<commit_after>package cpsc471.ftp.data;

import java.io.*;
import java.net.Socket;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

/**
 * Used to transfer files and large messages.
 * The actual file transfer portion of the FTP connection.
 */
public abstract class DataChannel {

    // thanks to https://www.ibm.com/developerworks/library/j-zerocopy/
    // for the introduction to SocketChannels, FileChannels, and the
    // transferTo method

    protected SocketChannel socketChannel;

    /**
     * Set the socket channel to use for communications
     * @param socketChannel socketChannel to set
     * @throws IOException if unable to read from socket
     */
    public void setSocketChannel(SocketChannel socketChannel)
            throws IOException {

        this.socketChannel = socketChannel;
        // block allows for more data to transfer more easily, though it's less scalable
        socketChannel.configureBlocking(true);
    }

    /**
     * Download a file
     * @param file file in which to store download
     * @param size size of file to download
     */
    public void download(File file, long size) throws IOException {

        FileChannel fileChannel = new FileOutputStream(file).getChannel();

        fileChannel.transferFrom(
                socketChannel, // channel from which to retrieve bytes
                0,
                size
        );
    }

    /**
     * Upload a file
     * @param file file to upload
     */
    public void upload(File file) throws IOException {

        FileChannel fileChannel = new FileInputStream(file).getChannel();

        // send the file
        long bytesSent = 0, fileLength = file.length();
        while(bytesSent < fileLength) {
            bytesSent += fileChannel.transferTo(
                    bytesSent, // byte offset from which to send
                    fileLength - bytesSent, // number of bytes to send
                    socketChannel // channel to which to send bytes
            );
        }
    }

    /**
     * Upload a large string
     * @param s string to upload
     * @throws IOException thrown if connection issue
     */
    public void upload(String s) throws IOException {

        // todo implement
    };
{'fraction_non_alphanumeric': 0.07591684185937865, 'fraction_numerical': 0.002102312543798178, 'mean_word_length': 2.212303075768942, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3227312', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1025, 'n_words': 387}