From 61e8e600dd1c9d6066711dfb9874e0117b87baf6 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 10 Sep 2014 14:54:40 +0200 Subject: mavenization v2 --- Dozentenmodul/src/main/java/ftp/FTPUtility.java | 86 ++++++++++++------------- 1 file changed, 42 insertions(+), 44 deletions(-) (limited to 'Dozentenmodul/src/main/java/ftp/FTPUtility.java') diff --git a/Dozentenmodul/src/main/java/ftp/FTPUtility.java b/Dozentenmodul/src/main/java/ftp/FTPUtility.java index f2c51dfc..beae3f34 100644 --- a/Dozentenmodul/src/main/java/ftp/FTPUtility.java +++ b/Dozentenmodul/src/main/java/ftp/FTPUtility.java @@ -16,7 +16,6 @@ import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.net.ftp.FTPReply; import org.apache.commons.net.ftp.FTPSClient; - /** * A utility class that provides functionality for downloading files from a FTP * server. @@ -49,7 +48,7 @@ public class FTPUtility { * Connect and login to the server. * * @throws FTPException - * @throws NoSuchAlgorithmException + * @throws NoSuchAlgorithmException */ public void connect() throws FTPException, NoSuchAlgorithmException { try { @@ -58,8 +57,7 @@ public class FTPUtility { if (!FTPReply.isPositiveCompletion(replyCode)) { throw new FTPException("FTP serve refused connection."); } - - + boolean logged = ftpClient.login(username, password); if (!logged) { // failed to login @@ -122,43 +120,45 @@ public class FTPUtility { throw new FTPException("Error downloading file: " + ex.getMessage()); } } - - - /** - * Start uploading a file to the server - * @param uploadFile the file to be uploaded - * @param destDir destination directory on the server - * where the file is stored - * @throws FTPException if client-server communication error occurred - */ - public void uploadFile(File uploadFile, String destDir) throws FTPException { - try { - boolean success = ftpClient.changeWorkingDirectory(destDir); - if (!success) { - throw new FTPException("Could not change working directory to " - + destDir + ". The directory may not exist."); - } - - success = ftpClient.setFileType(FTP.BINARY_FILE_TYPE); - if (!success) { - throw new FTPException("Could not set binary file type."); - } - - outputStream = ftpClient.storeFileStream(Image.image.getNewName()); - - //ftpClient.rename(uploadFile.getName(), ); - } catch (IOException ex) { - throw new FTPException("Error uploading file: " + ex.getMessage()); - } - } - - /** - * Write an array of bytes to the output stream. - */ - public void writeFileBytes(byte[] bytes, int offset, int length) - throws IOException { - outputStream.write(bytes, offset, length); - } + + /** + * Start uploading a file to the server + * + * @param uploadFile + * the file to be uploaded + * @param destDir + * destination directory on the server where the file is stored + * @throws FTPException + * if client-server communication error occurred + */ + public void uploadFile(File uploadFile, String destDir) throws FTPException { + try { + boolean success = ftpClient.changeWorkingDirectory(destDir); + if (!success) { + throw new FTPException("Could not change working directory to " + + destDir + ". The directory may not exist."); + } + + success = ftpClient.setFileType(FTP.BINARY_FILE_TYPE); + if (!success) { + throw new FTPException("Could not set binary file type."); + } + + outputStream = ftpClient.storeFileStream(Image.image.getNewName()); + + // ftpClient.rename(uploadFile.getName(), ); + } catch (IOException ex) { + throw new FTPException("Error uploading file: " + ex.getMessage()); + } + } + + /** + * Write an array of bytes to the output stream. + */ + public void writeFileBytes(byte[] bytes, int offset, int length) + throws IOException { + outputStream.write(bytes, offset, length); + } /** * Complete the download operation. @@ -191,11 +191,9 @@ public class FTPUtility { public InputStream getInputStream() { return inputStream; } - + public OutputStream getOutputStream() { return outputStream; } - - } \ No newline at end of file -- cgit v1.2.3-55-g7522