This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-net.git
The following commit(s) were added to refs/heads/master by this push: new cb9b828f Move experiment around cb9b828f is described below commit cb9b828f24a98eb7c97cfb1f90f9d65da370668b Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sat Feb 24 13:22:56 2024 -0500 Move experiment around Javadoc --- src/main/java/org/apache/commons/net/ftp/FTP.java | 25 ++++++----- .../java/org/apache/commons/net/ftp/FTPClient.java | 3 +- .../org/apache/commons/net/ftp/GZIPSocket.java | 48 ++++++++++++++++++++++ 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/apache/commons/net/ftp/FTP.java b/src/main/java/org/apache/commons/net/ftp/FTP.java index f4a7ff13..62cc3d7a 100644 --- a/src/main/java/org/apache/commons/net/ftp/FTP.java +++ b/src/main/java/org/apache/commons/net/ftp/FTP.java @@ -154,14 +154,16 @@ public class FTP extends SocketClient { /** * A constant used to indicate a file is to be transferred as FTP (un)compressing data in the "deflate" compression format. All constants ending in * <code>TRANSFER_MODE</code> are used to indicate file transfer modes. + * + * See the Internet Draft <a ref="https://datatracker.ietf.org/doc/html/draft-preston-ftpext-deflate-03">Deflate transmission mode for FTP</a> */ public static final int DEFLATE_TRANSFER_MODE = 13; - /** - * A constant used to indicate a file is to be transferred as FTP (un)compressing data in the GZIP compression format. All constants ending in - * <code>TRANSFER_MODE</code> are used to indicate file transfer modes. - */ - public static final int GZIP_TRANSFER_MODE = 14; +// /** +// * A constant used to indicate a file is to be transferred as FTP (un)compressing data in the GZIP compression format. All constants ending in +// * <code>TRANSFER_MODE</code> are used to indicate file transfer modes. +// */ +// public static final int GZIP_TRANSFER_MODE = 14; // We have to ensure that the protocol communication is in ASCII, // but we use ISO-8859-1 just in case 8-bit characters cross @@ -175,7 +177,7 @@ public class FTP extends SocketClient { /** Length of the FTP reply code (3 alphanumerics) */ public static final int REPLY_CODE_LEN = 3; - private static final String modes = "AEILNTCFRPSBCZ"; + private static final String MODES = "AEILNTCFRPSBCZ"; protected int _replyCode; protected ArrayList<String> _replyLines; protected boolean _newReplyString; @@ -904,7 +906,8 @@ public class FTP extends SocketClient { * @throws IOException If an I/O error occurs while either sending the command or receiving the server reply. */ public int mode(final int mode) throws IOException { - return sendCommand(FTPCmd.MODE, modes.substring(mode, mode + 1)); + + return sendCommand(FTPCmd.MODE, MODES.substring(mode, mode + 1)); } /** @@ -1405,7 +1408,7 @@ public class FTP extends SocketClient { * @throws IOException If an I/O error occurs while either sending the command or receiving the server reply. */ public int stru(final int structure) throws IOException { - return sendCommand(FTPCmd.STRU, modes.substring(structure, structure + 1)); + return sendCommand(FTPCmd.STRU, MODES.substring(structure, structure + 1)); } /** @@ -1432,7 +1435,7 @@ public class FTP extends SocketClient { * @throws IOException If an I/O error occurs while either sending the command or receiving the server reply. */ public int type(final int fileType) throws IOException { - return sendCommand(FTPCmd.TYPE, modes.substring(fileType, fileType + 1)); + return sendCommand(FTPCmd.TYPE, MODES.substring(fileType, fileType + 1)); } /** @@ -1449,12 +1452,12 @@ public class FTP extends SocketClient { public int type(final int fileType, final int formatOrByteSize) throws IOException { final StringBuilder arg = new StringBuilder(); - arg.append(modes.charAt(fileType)); + arg.append(MODES.charAt(fileType)); arg.append(' '); if (fileType == LOCAL_FILE_TYPE) { arg.append(formatOrByteSize); } else { - arg.append(modes.charAt(formatOrByteSize)); + arg.append(MODES.charAt(formatOrByteSize)); } return sendCommand(FTPCmd.TYPE, arg.toString()); diff --git a/src/main/java/org/apache/commons/net/ftp/FTPClient.java b/src/main/java/org/apache/commons/net/ftp/FTPClient.java index 69e19c1e..eb89b89d 100644 --- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java +++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java @@ -3423,7 +3423,8 @@ public class FTPClient extends FTP implements Configurable { switch (fileTransferMode) { case DEFLATE_TRANSFER_MODE: return new DeflateSocket(plainSocket); - case GZIP_TRANSFER_MODE: + // Experiment, not in an RFC? + // case GZIP_TRANSFER_MODE: //return new GZIPSocket(plainSocket); default: return plainSocket; diff --git a/src/test/java/org/apache/commons/net/ftp/GZIPSocket.java b/src/test/java/org/apache/commons/net/ftp/GZIPSocket.java new file mode 100644 index 00000000..48dadbda --- /dev/null +++ b/src/test/java/org/apache/commons/net/ftp/GZIPSocket.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.net.ftp; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; + +/** + * Experiment, not in an RFC? + * + * Wrapper class for FTP data channel sockets when compressing data in the GZIP compression format. All methods except of {@link #getInputStream()} and + * {@link #getOutputStream()} are calling the delegate methods directly. + */ +final class GZIPSocket extends DelegateSocket { + + GZIPSocket(final Socket delegate) { + super(delegate); + } + + @Override + public InputStream getInputStream() throws IOException { + return new GZIPInputStream(delegate.getInputStream()); + } + + @Override + public OutputStream getOutputStream() throws IOException { + return new GZIPOutputStream(delegate.getOutputStream()); + } +}