├── NetDisk_Client ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs ├── bin │ ├── com │ │ ├── domain │ │ │ └── User.class │ │ ├── service │ │ │ ├── DownloadFileService.class │ │ │ ├── LoginService.class │ │ │ └── UploadFileService.class │ │ ├── utils │ │ │ ├── CheckEmail.class │ │ │ ├── ConfigLoader.class │ │ │ ├── FileSizeUtils.class │ │ │ └── MD5FileUtil.class │ │ └── view │ │ │ ├── FileJPanel$1.class │ │ │ ├── FileJPanel$2.class │ │ │ ├── FileJPanel$3.class │ │ │ ├── FileJPanel$4.class │ │ │ ├── FileJPanel$5.class │ │ │ ├── FileJPanel$6.class │ │ │ ├── FileJPanel.class │ │ │ ├── FileListJPanel$1.class │ │ │ ├── FileListJPanel$2.class │ │ │ ├── FileListJPanel.class │ │ │ ├── LoginJDialog$1$1.class │ │ │ ├── LoginJDialog$1.class │ │ │ ├── LoginJDialog$2.class │ │ │ ├── LoginJDialog$3.class │ │ │ ├── LoginJDialog$4.class │ │ │ ├── LoginJDialog$5.class │ │ │ ├── LoginJDialog$6.class │ │ │ ├── LoginJDialog.class │ │ │ ├── MainJFrame$1.class │ │ │ ├── MainJFrame$2.class │ │ │ ├── MainJFrame$3.class │ │ │ ├── MainJFrame$4.class │ │ │ ├── MainJFrame$5.class │ │ │ ├── MainJFrame$6.class │ │ │ ├── MainJFrame$7.class │ │ │ ├── MainJFrame.class │ │ │ ├── RePasswordDialog$1.class │ │ │ └── RePasswordDialog.class │ ├── commons-beanutils-1.8.3.jar │ ├── commons-collections-3.2.1.jar │ ├── commons-lang-2.6.jar │ ├── commons-logging-1.1.1.jar │ ├── config.properties │ ├── ezmorph-1.0.6.jar │ └── json-lib-2.4-jdk15.jar ├── image │ ├── icon_list_apk.png │ ├── icon_list_audiofile.png │ ├── icon_list_compressfile.png │ ├── icon_list_doc.png │ ├── icon_list_excel.png │ ├── icon_list_folder.png │ ├── icon_list_html.png │ ├── icon_list_image.png │ ├── icon_list_pdf.png │ ├── icon_list_ppt.png │ ├── icon_list_txtfile.png │ ├── icon_list_unknown.png │ ├── icon_list_vcard.png │ ├── icon_list_videofile.png │ └── icon_list_visio.png └── src │ ├── com │ ├── domain │ │ └── User.java │ ├── service │ │ ├── DownloadFileService.java │ │ ├── LoginService.java │ │ └── UploadFileService.java │ ├── utils │ │ ├── CheckEmail.java │ │ ├── ConfigLoader.java │ │ ├── FileSizeUtils.java │ │ └── MD5FileUtil.java │ └── view │ │ ├── FileJPanel.java │ │ ├── FileListJPanel.java │ │ ├── LoginJDialog.java │ │ ├── MainJFrame.java │ │ └── RePasswordDialog.java │ ├── commons-beanutils-1.8.3.jar │ ├── commons-collections-3.2.1.jar │ ├── commons-lang-2.6.jar │ ├── commons-logging-1.1.1.jar │ ├── config.properties │ ├── ezmorph-1.0.6.jar │ └── json-lib-2.4-jdk15.jar ├── NetDistk_Server ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs ├── bin │ ├── c3p0-0.9.1.2.jar │ ├── c3p0-config.xml │ ├── com │ │ ├── dao │ │ │ ├── DownloadDao.class │ │ │ ├── LoginDao.class │ │ │ ├── RegistDao.class │ │ │ └── UploadDao.class │ │ ├── domain │ │ │ ├── Directory.class │ │ │ ├── FileItem.class │ │ │ └── User.class │ │ ├── service │ │ │ ├── DownloadService.class │ │ │ ├── LoginService.class │ │ │ ├── RegistUserService.class │ │ │ ├── StartServer$1.class │ │ │ ├── StartServer$2.class │ │ │ ├── StartServer$3.class │ │ │ ├── StartServer$4.class │ │ │ ├── StartServer.class │ │ │ ├── UploadService.class │ │ │ └── UserOnline.class │ │ ├── test │ │ │ └── HelloTest.class │ │ └── utils │ │ │ ├── C3P0Utils.class │ │ │ ├── ConfigLoader.class │ │ │ ├── EmailUtils.class │ │ │ └── MD5FileUtil.class │ ├── commons-beanutils-1.8.3.jar │ ├── commons-collections-3.2.1.jar │ ├── commons-dbutils-1.7.jar │ ├── commons-email-1.4.jar │ ├── commons-lang-2.6.jar │ ├── commons-logging-1.1.1.jar │ ├── config.properties │ ├── ezmorph-1.0.6.jar │ ├── json-lib-2.4-jdk15.jar │ ├── mail.jar │ ├── mailapi.jar │ ├── mysql-connector-java-5.1.44-bin.jar │ └── test │ │ └── HelloTest.class └── src │ ├── c3p0-0.9.1.2.jar │ ├── c3p0-config.xml │ ├── com │ ├── dao │ │ ├── DownloadDao.java │ │ ├── LoginDao.java │ │ ├── RegistDao.java │ │ └── UploadDao.java │ ├── domain │ │ ├── Directory.java │ │ ├── FileItem.java │ │ └── User.java │ ├── service │ │ ├── DownloadService.java │ │ ├── LoginService.java │ │ ├── RegistUserService.java │ │ ├── StartServer.java │ │ ├── UploadService.java │ │ └── UserOnline.java │ ├── test │ │ └── HelloTest.java │ └── utils │ │ ├── C3P0Utils.java │ │ ├── ConfigLoader.java │ │ ├── EmailUtils.java │ │ └── MD5FileUtil.java │ ├── commons-beanutils-1.8.3.jar │ ├── commons-collections-3.2.1.jar │ ├── commons-dbutils-1.7.jar │ ├── commons-email-1.4.jar │ ├── commons-lang-2.6.jar │ ├── commons-logging-1.1.1.jar │ ├── config.properties │ ├── ezmorph-1.0.6.jar │ ├── json-lib-2.4-jdk15.jar │ ├── mail.jar │ ├── mailapi.jar │ ├── mysql-connector-java-5.1.44-bin.jar │ └── test │ └── HelloTest.java ├── README.md ├── netdisk.sql └── 演示图片 ├── 1.jpg ├── 2.jpg ├── 3.jpg ├── 4.jpg ├── 5.jpg └── 6.jpg /NetDisk_Client/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /NetDisk_Client/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | NetDisk_Client 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /NetDisk_Client/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/config.properties=UTF-8 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /NetDisk_Client/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.8 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.8 12 | -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/domain/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/domain/User.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/service/DownloadFileService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/service/DownloadFileService.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/service/LoginService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/service/LoginService.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/service/UploadFileService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/service/UploadFileService.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/utils/CheckEmail.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/utils/CheckEmail.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/utils/ConfigLoader.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/utils/ConfigLoader.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/utils/FileSizeUtils.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/utils/FileSizeUtils.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/utils/MD5FileUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/utils/MD5FileUtil.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/FileJPanel$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/FileJPanel$1.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/FileJPanel$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/FileJPanel$2.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/FileJPanel$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/FileJPanel$3.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/FileJPanel$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/FileJPanel$4.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/FileJPanel$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/FileJPanel$5.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/FileJPanel$6.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/FileJPanel$6.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/FileJPanel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/FileJPanel.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/FileListJPanel$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/FileListJPanel$1.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/FileListJPanel$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/FileListJPanel$2.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/FileListJPanel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/FileListJPanel.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/LoginJDialog$1$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/LoginJDialog$1$1.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/LoginJDialog$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/LoginJDialog$1.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/LoginJDialog$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/LoginJDialog$2.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/LoginJDialog$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/LoginJDialog$3.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/LoginJDialog$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/LoginJDialog$4.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/LoginJDialog$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/LoginJDialog$5.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/LoginJDialog$6.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/LoginJDialog$6.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/LoginJDialog.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/LoginJDialog.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/MainJFrame$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/MainJFrame$1.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/MainJFrame$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/MainJFrame$2.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/MainJFrame$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/MainJFrame$3.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/MainJFrame$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/MainJFrame$4.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/MainJFrame$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/MainJFrame$5.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/MainJFrame$6.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/MainJFrame$6.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/MainJFrame$7.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/MainJFrame$7.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/MainJFrame.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/MainJFrame.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/RePasswordDialog$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/RePasswordDialog$1.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/com/view/RePasswordDialog.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/com/view/RePasswordDialog.class -------------------------------------------------------------------------------- /NetDisk_Client/bin/commons-beanutils-1.8.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/commons-beanutils-1.8.3.jar -------------------------------------------------------------------------------- /NetDisk_Client/bin/commons-collections-3.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/commons-collections-3.2.1.jar -------------------------------------------------------------------------------- /NetDisk_Client/bin/commons-lang-2.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/commons-lang-2.6.jar -------------------------------------------------------------------------------- /NetDisk_Client/bin/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /NetDisk_Client/bin/config.properties: -------------------------------------------------------------------------------- 1 | #配置服务器IP 2 | server_ip:192.168.41.1 3 | server_regist_port:5681 4 | server_login_port:5682 5 | server_upload_port:5683 6 | server_download_port:5684 7 | -------------------------------------------------------------------------------- /NetDisk_Client/bin/ezmorph-1.0.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/ezmorph-1.0.6.jar -------------------------------------------------------------------------------- /NetDisk_Client/bin/json-lib-2.4-jdk15.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/bin/json-lib-2.4-jdk15.jar -------------------------------------------------------------------------------- /NetDisk_Client/image/icon_list_apk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/image/icon_list_apk.png -------------------------------------------------------------------------------- /NetDisk_Client/image/icon_list_audiofile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/image/icon_list_audiofile.png -------------------------------------------------------------------------------- /NetDisk_Client/image/icon_list_compressfile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/image/icon_list_compressfile.png -------------------------------------------------------------------------------- /NetDisk_Client/image/icon_list_doc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/image/icon_list_doc.png -------------------------------------------------------------------------------- /NetDisk_Client/image/icon_list_excel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/image/icon_list_excel.png -------------------------------------------------------------------------------- /NetDisk_Client/image/icon_list_folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/image/icon_list_folder.png -------------------------------------------------------------------------------- /NetDisk_Client/image/icon_list_html.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/image/icon_list_html.png -------------------------------------------------------------------------------- /NetDisk_Client/image/icon_list_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/image/icon_list_image.png -------------------------------------------------------------------------------- /NetDisk_Client/image/icon_list_pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/image/icon_list_pdf.png -------------------------------------------------------------------------------- /NetDisk_Client/image/icon_list_ppt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/image/icon_list_ppt.png -------------------------------------------------------------------------------- /NetDisk_Client/image/icon_list_txtfile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/image/icon_list_txtfile.png -------------------------------------------------------------------------------- /NetDisk_Client/image/icon_list_unknown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/image/icon_list_unknown.png -------------------------------------------------------------------------------- /NetDisk_Client/image/icon_list_vcard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/image/icon_list_vcard.png -------------------------------------------------------------------------------- /NetDisk_Client/image/icon_list_videofile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/image/icon_list_videofile.png -------------------------------------------------------------------------------- /NetDisk_Client/image/icon_list_visio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/image/icon_list_visio.png -------------------------------------------------------------------------------- /NetDisk_Client/src/com/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.domain; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | /** 8 | * 用于保存当前登录客户端的用户信息 9 | * @author 田 金 东 10 | * 11 | */ 12 | public class User { 13 | private static String email; 14 | private static Long uid; 15 | private static Long initSize; 16 | private static Long usedSize; 17 | private static String fileListStr; 18 | private static String code;//用户的串码 19 | private static LinkedList pathStack=new LinkedList<>(); 20 | 21 | 22 | 23 | public static String getEmail() { 24 | return email; 25 | } 26 | public static void setEmail(String email) { 27 | User.email = email; 28 | } 29 | public static Long getInitSize() { 30 | return initSize; 31 | } 32 | public static void setInitSize(Long initSize) { 33 | User.initSize = initSize; 34 | } 35 | public static Long getUsedSize() { 36 | return usedSize; 37 | } 38 | public static void setUsedSize(Long usedSize) { 39 | User.usedSize = usedSize; 40 | } 41 | public static Long getUid() { 42 | return uid; 43 | } 44 | public static void setUid(Long uid) { 45 | User.uid = uid; 46 | } 47 | public static String getFileListStr() { 48 | return fileListStr; 49 | } 50 | public static void setFileListStr(String fileListStr) { 51 | User.fileListStr = fileListStr; 52 | } 53 | public static LinkedList getPathStack() { 54 | return pathStack; 55 | } 56 | public static void setPathStack(LinkedList pathStack) { 57 | User.pathStack = pathStack; 58 | } 59 | public static String getCode() { 60 | return code; 61 | } 62 | public static void setCode(String code) { 63 | User.code = code; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /NetDisk_Client/src/com/service/DownloadFileService.java: -------------------------------------------------------------------------------- 1 | package com.service; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileNotFoundException; 6 | import java.io.FileOutputStream; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.io.OutputStream; 10 | import java.net.Socket; 11 | import java.text.DecimalFormat; 12 | import java.util.Vector; 13 | 14 | import javax.swing.JTable; 15 | 16 | import com.domain.User; 17 | import com.utils.ConfigLoader; 18 | import com.utils.FileSizeUtils; 19 | import com.utils.MD5FileUtil; 20 | import com.view.FileListJPanel; 21 | import com.view.MainJFrame; 22 | 23 | import net.sf.json.JSONObject; 24 | 25 | 26 | public class DownloadFileService extends Thread{ 27 | 28 | private Long uid; 29 | private String code; 30 | private Long fid; 31 | private File file; 32 | private MainJFrame mainJFrame; 33 | private Vector downloadRow; 34 | private JTable downloadTable; 35 | 36 | 37 | 38 | public DownloadFileService(Long uid, String code,Long fid, File file, 39 | MainJFrame mainJFrame, Vector downloadRow, 40 | JTable downloadTable) { 41 | super(); 42 | this.uid = uid; 43 | this.code = code; 44 | this.file = file; 45 | this.fid=fid; 46 | this.mainJFrame = mainJFrame; 47 | this.downloadRow = downloadRow; 48 | this.downloadTable = downloadTable; 49 | } 50 | 51 | 52 | 53 | public void run() { 54 | Socket socket=null; 55 | InputStream input=null; 56 | OutputStream output=null; 57 | try { 58 | downloadRow.add(file.getName()); 59 | downloadRow.add(file.getPath()); 60 | downloadRow.add(file.length()/1024/1024+"MB"); 61 | FileOutputStream fileOutput = new FileOutputStream(file); 62 | 63 | String reqStr="{\"uid\":\""+uid+"\",\"code\":\""+code+"\",\"fid\":\""+fid+"\"}"; 64 | socket=new Socket(ConfigLoader.getServerIP(),ConfigLoader.getDownloadPort()); 65 | 66 | input=socket.getInputStream(); 67 | output=socket.getOutputStream(); 68 | 69 | output.write(reqStr.getBytes()); 70 | output.flush(); 71 | 72 | 73 | byte[] buffer=new byte[1024]; 74 | int length = input.read(buffer); 75 | String jsonStr=new String(buffer,0,length); 76 | JSONObject.fromObject(jsonStr); 77 | 78 | //开始上传 79 | long s=0l;//开始时间 80 | long sta=0L;//记录每秒开始时间 81 | long end=0L;//记录每次分段下载时间 82 | long startSize=file.length();//文件开始大小 83 | long uSize=0L;//一秒类文件上传大小 84 | long oldSize=startSize;//文件的剩余大小 85 | buffer=new byte[1024*1024]; 86 | 87 | s=System.currentTimeMillis(); 88 | sta=s; 89 | while((length=input.read(buffer))>0) { 90 | fileOutput.write(buffer, 0, length); 91 | try { 92 | sleep(500); 93 | } catch (InterruptedException e) { 94 | e.printStackTrace(); 95 | } 96 | end=System.currentTimeMillis(); 97 | 98 | if(end-sta>1000) { 99 | //算出来的是以MB为单位的 100 | downloadRow.set(4, FileSizeUtils.getSpeed(uSize)); 101 | downloadRow.set(3, FileSizeUtils.getSize(oldSize)); 102 | downloadTable.updateUI(); 103 | sta=end; 104 | uSize=0l; 105 | } 106 | } 107 | downloadRow.set(3, "下载完成"); 108 | downloadRow.set(4, "——"); 109 | //刷新表格 110 | downloadTable.updateUI(); 111 | 112 | 113 | } catch (FileNotFoundException e) { 114 | // TODO Auto-generated catch block 115 | e.printStackTrace(); 116 | } catch (IOException e) { 117 | // TODO Auto-generated catch block 118 | e.printStackTrace(); 119 | }finally { 120 | if(socket!=null) { 121 | try { 122 | socket.close(); 123 | } catch (IOException e) { 124 | // TODO Auto-generated catch block 125 | e.printStackTrace(); 126 | } 127 | } 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /NetDisk_Client/src/com/service/LoginService.java: -------------------------------------------------------------------------------- 1 | package com.service; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.OutputStream; 6 | import java.net.Socket; 7 | 8 | 9 | import com.domain.User; 10 | import com.utils.ConfigLoader; 11 | 12 | import net.sf.json.JSONObject; 13 | 14 | /** 15 | * 该类是客户端业务处理的主类 16 | * @author 田 金 东 17 | * 18 | */ 19 | public class LoginService extends Thread { 20 | private static Socket socket; 21 | private static InputStream input; 22 | private static OutputStream output; 23 | 24 | 25 | public LoginService(Socket socket) { 26 | this.socket = socket; 27 | } 28 | 29 | public void run() { 30 | 31 | } 32 | 33 | public static boolean login(String username, String password) 34 | throws Exception, IOException { 35 | socket = new Socket(ConfigLoader.getServerIP(), 36 | ConfigLoader.getServerLoginPort()); 37 | input = socket.getInputStream(); 38 | output = socket.getOutputStream(); 39 | String reqStr = "{\"type\":\"login\",\"email\":\"" + username 40 | + "\",\"password\":\"" + password + "\"}"; 41 | output.write(reqStr.getBytes()); 42 | output.flush(); 43 | 44 | byte[] buffer = new byte[1024]; 45 | int len = input.read(buffer); 46 | String resStr = new String(buffer, 0, len); 47 | JSONObject resInfo = JSONObject.fromObject(resStr); 48 | if (resInfo.getString("type").trim().equals("true")) { 49 | User.setEmail(username); 50 | User.setUid(resInfo.getLong("uid")); 51 | User.setInitSize(resInfo.getLong("initSize")); 52 | User.setUsedSize(getUsedSize()); 53 | //记录用户登录的串码 54 | User.setCode(resInfo.getString("code")); 55 | new LoginService(socket).start();//登陆成功后开启线程长时间保持连接 56 | return true; 57 | } 58 | return false; 59 | } 60 | 61 | /** 62 | * 获得该用户已使用的内存大小 63 | * @return 64 | */ 65 | public static Long getUsedSize() { 66 | String reqStr = "{\"type\":\"usedSize\"}"; 67 | try { 68 | output.write(reqStr.getBytes()); 69 | output.flush(); 70 | byte[] buffer = new byte[1024]; 71 | int length = input.read(buffer); 72 | String resStr = new String(buffer, 0, length); 73 | 74 | JSONObject json = JSONObject.fromObject(resStr); 75 | if (json.getString("type").trim().equals("true")) { 76 | return json.getLong("size"); 77 | } else { 78 | throw new RuntimeException("容量获取发生错误!"); 79 | } 80 | } catch (IOException e) { 81 | // TODO Auto-generated catch block 82 | e.printStackTrace(); 83 | } 84 | return null; 85 | } 86 | 87 | /** 88 | * 获取目录下文件及文件夹列表 89 | * @return 90 | * @throws Exception 91 | */ 92 | public static String getFileListStr(Long did) throws Exception { 93 | //id=0表示获取根目录 94 | String reqStr = "{\"type\":\"list\",\"did\":\"" + did + "\"}"; 95 | try { 96 | output.write(reqStr.getBytes()); 97 | output.flush(); 98 | byte[] buffer = new byte[4096]; 99 | int length = input.read(buffer); 100 | String resStr = new String(buffer, 0, length); 101 | if (resStr.trim().equals("false")) { 102 | throw new Exception("目录获取发生错误"); 103 | } else { 104 | return resStr; 105 | } 106 | } catch (IOException e) { 107 | // TODO Auto-generated catch block 108 | e.printStackTrace(); 109 | 110 | return null; 111 | } 112 | } 113 | public static void logout() { 114 | try { 115 | output.write("{\"type\":\"logout\"}".getBytes()); 116 | output.flush(); 117 | } catch (IOException e1) { 118 | // TODO Auto-generated catch block 119 | e1.printStackTrace(); 120 | } 121 | } 122 | 123 | public static String rename(String type,String id,String newName) throws IOException { 124 | String reqStr=null; 125 | if(type.equals("dir")) { 126 | reqStr="{\"type\":\"renameDir\",\"did\":\""+id+"\",\"newName\":\""+newName+"\"}"; 127 | }else if(type.equals("file")){ 128 | reqStr="{\"type\":\"renameFile\",\"fid\":\""+id+"\",\"newName\":\""+newName+"\"}"; 129 | } 130 | output.write(reqStr.getBytes()); 131 | output.flush(); 132 | 133 | byte[] buffer=new byte[1024]; 134 | int length = input.read(buffer); 135 | String resStr=new String(buffer,0,length); 136 | return resStr; 137 | } 138 | 139 | public static String delete(String type,String id) throws IOException { 140 | String reqStr=null; 141 | if(type.equals("dir")) { 142 | reqStr="{\"type\":\"removeDir\",\"did\":\""+id+"\"}"; 143 | }else if(type.equals("file")){ 144 | reqStr="{\"type\":\"removeFile\",\"fid\":\""+id+"\"}"; 145 | } 146 | output.write(reqStr.getBytes()); 147 | output.flush(); 148 | 149 | byte[] buffer=new byte[1024]; 150 | int length = input.read(buffer); 151 | String resStr=new String(buffer,0,length); 152 | return resStr; 153 | } 154 | 155 | public static String createDir(Long id, String dirName) throws IOException { 156 | String reqStr="{\"type\":\"mkdir\",\"dname\":\""+dirName+"\",\"rdid\":\""+id+"\"}"; 157 | output.write(reqStr.getBytes()); 158 | output.flush(); 159 | byte[] buffer=new byte[1024]; 160 | int length = input.read(buffer); 161 | String resStr=new String(buffer,0,length); 162 | return resStr; 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /NetDisk_Client/src/com/service/UploadFileService.java: -------------------------------------------------------------------------------- 1 | package com.service; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileNotFoundException; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.io.OutputStream; 9 | import java.net.Socket; 10 | import java.text.DecimalFormat; 11 | import java.util.Vector; 12 | 13 | import javax.swing.JTable; 14 | 15 | import com.domain.User; 16 | import com.utils.ConfigLoader; 17 | import com.utils.FileSizeUtils; 18 | import com.utils.MD5FileUtil; 19 | import com.view.FileListJPanel; 20 | import com.view.MainJFrame; 21 | 22 | import net.sf.json.JSONObject; 23 | 24 | public class UploadFileService extends Thread { 25 | 26 | private Long uid; 27 | private String code; 28 | private File file; 29 | private Long did; 30 | private MainJFrame mainJFrame; 31 | private FileListJPanel fileListJPanel; 32 | private JTable uploadTable; 33 | 34 | //保存上该任务的在上传列表中的信息 35 | private Vector uploadRow; 36 | 37 | public UploadFileService(Long uid, String code, File file, Long did, 38 | MainJFrame mainJFrame,FileListJPanel fileListJPanel,Vector uploadRow,JTable uploadTable) { 39 | super(); 40 | this.uploadRow=uploadRow; 41 | this.uid = uid; 42 | this.code = code; 43 | this.file = file; 44 | this.did = did; 45 | this.mainJFrame = mainJFrame; 46 | this.fileListJPanel=fileListJPanel; 47 | this.uploadTable=uploadTable; 48 | } 49 | 50 | public void run() { 51 | Socket socket=null; 52 | try { 53 | uploadRow.add(file.getName()); 54 | uploadRow.add(file.getPath()); 55 | uploadRow.add(file.length()/1024/1024+"MB"); 56 | FileInputStream fileInput = new FileInputStream(file); 57 | String filemd5 = MD5FileUtil.getFileMD5String(file); 58 | //{"filesize":"","filename":"","filemd5":"","did":"","code":"","uid":""} 59 | String reqStr = "{\"filesize\":\"" + file.length() 60 | + "\",\"filename\":\"" + file.getName() 61 | + "\",\"filemd5\":\"" + filemd5 + "\",\"did\":\"" + did 62 | + "\",\"code\":\"" + code + "\",\"uid\":\"" + uid + "\"}"; 63 | socket = new Socket(ConfigLoader.getServerIP(),ConfigLoader.getUploadtPort()); 64 | InputStream input = socket.getInputStream(); 65 | OutputStream output = socket.getOutputStream(); 66 | 67 | output.write(reqStr.getBytes()); 68 | output.flush(); 69 | 70 | byte[] buffer=new byte[1024]; 71 | int length = input.read(buffer); 72 | 73 | String jsonStr=new String(buffer,0,length); 74 | 75 | JSONObject json = JSONObject.fromObject(jsonStr); 76 | String type = json.getString("type"); 77 | if(type.equals("overSize")) { 78 | //剩余容量大小不足 79 | javax.swing.JOptionPane.showMessageDialog(mainJFrame, "您的账户容量不足!"); 80 | }else if(type.equals("mc")){ 81 | uploadRow.set(4, "秒传成功!"); 82 | }else if(type.equals("pleaseUpload")) { 83 | //开始上传 84 | long s=0l;//开始时间 85 | long sta=0L;//记录每秒开始时间 86 | long end=0L;//记录每次分段上传时间 87 | long startSize=file.length();//文件开始大小 88 | long uSize=0L;//一秒类文件上传大小 89 | long oldSize=startSize;//文件的剩余大小 90 | buffer=new byte[1024*1024]; 91 | 92 | s=System.currentTimeMillis(); 93 | sta=s; 94 | while((length=fileInput.read(buffer))>0) { 95 | output.write(buffer, 0, length); 96 | uSize+=length; 97 | oldSize-=length; 98 | try { 99 | sleep(500); 100 | } catch (InterruptedException e) { 101 | e.printStackTrace(); 102 | } 103 | end=System.currentTimeMillis(); 104 | 105 | if(end-sta>1000) { 106 | //算出来的是以MB为单位的 107 | String speed=FileSizeUtils.getSpeed(uSize); 108 | uploadRow.set(4, speed); 109 | uploadRow.set(3, FileSizeUtils.getSize(oldSize)); 110 | uploadTable.updateUI(); 111 | sta=end; 112 | uSize=0l; 113 | } 114 | } 115 | uploadRow.set(3, "上传完成"); 116 | uploadRow.set(4, "——"); 117 | uploadTable.updateUI(); 118 | 119 | int len = input.read(buffer); 120 | jsonStr=new String(buffer,0,len); 121 | json = JSONObject.fromObject(jsonStr); 122 | } 123 | fileListJPanel.updateFileList(); 124 | //重新获得用户已使用大小,然后寄存到User类中 125 | User.setUsedSize(LoginService.getUsedSize()); 126 | //重新加载主页面的内存大小进度条(它是根据User类中寄存的usedSize属性更新的) 127 | mainJFrame.updateUsedSize(); 128 | 129 | } catch (FileNotFoundException e) { 130 | // TODO Auto-generated catch block 131 | e.printStackTrace(); 132 | } catch (IOException e) { 133 | // TODO Auto-generated catch block 134 | e.printStackTrace(); 135 | }finally { 136 | if(socket!=null) { 137 | try { 138 | socket.close(); 139 | } catch (IOException e) { 140 | // TODO Auto-generated catch block 141 | e.printStackTrace(); 142 | } 143 | } 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /NetDisk_Client/src/com/utils/CheckEmail.java: -------------------------------------------------------------------------------- 1 | package com.utils; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | public class CheckEmail { 7 | public static boolean checkEmail(String email) { 8 | String RULE_EMAIL = "^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$"; 9 | //正则表达式的模式 编译正则表达式 10 | Pattern p = Pattern.compile(RULE_EMAIL); 11 | //正则表达式的匹配器 12 | Matcher matcher = p.matcher(email); 13 | //进行正则匹配\ 14 | return matcher.matches(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /NetDisk_Client/src/com/utils/ConfigLoader.java: -------------------------------------------------------------------------------- 1 | package com.utils; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.util.Properties; 7 | 8 | import org.junit.Test; 9 | 10 | public class ConfigLoader { 11 | 12 | private static Properties properties=null; 13 | private static String IP; 14 | private static Integer registPort; 15 | private static Integer loginPort; 16 | private static Integer uploadtPort; 17 | private static Integer downloadPort; 18 | 19 | static { 20 | properties=new Properties(); 21 | try { 22 | properties.load(new FileInputStream(new File("src/config.properties"))); 23 | } catch (IOException e) { 24 | // TODO Auto-generated catch block 25 | e.printStackTrace(); 26 | } 27 | IP = properties.getProperty("server_ip"); 28 | registPort=Integer.valueOf(properties.getProperty("server_regist_port")); 29 | loginPort=Integer.valueOf(properties.getProperty("server_login_port")); 30 | uploadtPort=Integer.valueOf(properties.getProperty("server_upload_port")); 31 | downloadPort=Integer.valueOf(properties.getProperty("server_download_port")); 32 | } 33 | public static String getServerIP() { 34 | return IP; 35 | } 36 | public static Integer getServerRegistPort() { 37 | return registPort; 38 | } 39 | public static Integer getServerLoginPort() { 40 | return loginPort; 41 | } 42 | 43 | public static Integer getUploadtPort() { 44 | return uploadtPort; 45 | } 46 | public static Integer getDownloadPort() { 47 | return downloadPort; 48 | } 49 | 50 | @Test 51 | public void test() { 52 | System.out.println(ConfigLoader.getUploadtPort()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /NetDisk_Client/src/com/utils/FileSizeUtils.java: -------------------------------------------------------------------------------- 1 | package com.utils; 2 | 3 | import java.text.DecimalFormat; 4 | 5 | public class FileSizeUtils { 6 | 7 | private static DecimalFormat decimalFomat = new DecimalFormat(".00"); 8 | 9 | /** 10 | * 根据long的大小自动的输出传输速度(速度单位自动匹配) 11 | * @param byt 传输的字节数 12 | * @return 13 | */ 14 | public static String getSpeed(long byt) { 15 | 16 | if (byt < 1024) { 17 | return byt + "B/s"; 18 | } else if (byt < 1024 * 1024) { 19 | return byt / 1024 + "KB/s"; 20 | } else { 21 | //算出来的是以MB为单位的 22 | double tempSpeed = byt / 1024 / (1024 * 1.0); 23 | String format = decimalFomat.format(tempSpeed); 24 | return format + "MB/s"; 25 | } 26 | 27 | } 28 | 29 | public static String getSize(long byt) { 30 | 31 | if (byt < 1024) { 32 | return byt + "B"; 33 | } else if (byt < 1024 * 1024) { 34 | return byt / 1024 + "KB"; 35 | } else { 36 | //算出来的是以MB为单位的 37 | double tempSpeed = byt / 1024 / 1024; 38 | return tempSpeed + "MB"; 39 | } 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /NetDisk_Client/src/com/utils/MD5FileUtil.java: -------------------------------------------------------------------------------- 1 | package com.utils; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.nio.MappedByteBuffer; 7 | import java.nio.channels.FileChannel; 8 | import java.security.MessageDigest; 9 | import java.security.NoSuchAlgorithmException; 10 | 11 | public class MD5FileUtil { 12 | 13 | protected static char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 14 | 'f' }; 15 | protected static MessageDigest messagedigest = null; 16 | 17 | static { 18 | try { 19 | messagedigest = MessageDigest.getInstance("MD5"); 20 | } catch (NoSuchAlgorithmException e) { 21 | } 22 | } 23 | 24 | public static String getFileMD5String(File file) throws IOException { 25 | FileInputStream in = new FileInputStream(file); 26 | FileChannel ch = in.getChannel(); 27 | MappedByteBuffer byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, 0, file.length()); 28 | messagedigest.update(byteBuffer); 29 | return bufferToHex(messagedigest.digest()); 30 | } 31 | 32 | public static String getMD5String(String s) { 33 | return getMD5String(s.getBytes()); 34 | } 35 | 36 | public static String getMD5String(byte[] bytes) { 37 | messagedigest.update(bytes); 38 | return bufferToHex(messagedigest.digest()); 39 | } 40 | 41 | private static String bufferToHex(byte bytes[]) { 42 | return bufferToHex(bytes, 0, bytes.length); 43 | } 44 | 45 | private static String bufferToHex(byte bytes[], int m, int n) { 46 | StringBuffer stringbuffer = new StringBuffer(2 * n); 47 | int k = m + n; 48 | for (int l = m; l < k; l++) { 49 | appendHexPair(bytes[l], stringbuffer); 50 | } 51 | return stringbuffer.toString(); 52 | } 53 | 54 | private static void appendHexPair(byte bt, StringBuffer stringbuffer) { 55 | char c0 = hexDigits[(bt & 0xf0) >> 4]; 56 | char c1 = hexDigits[bt & 0xf]; 57 | stringbuffer.append(c0); 58 | stringbuffer.append(c1); 59 | } 60 | 61 | public static boolean checkPassword(String password, String md5PwdStr) { 62 | String s = getMD5String(password); 63 | return s.equals(md5PwdStr); 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /NetDisk_Client/src/com/view/FileJPanel.java: -------------------------------------------------------------------------------- 1 | package com.view; 2 | 3 | import javax.swing.JPanel; 4 | import javax.swing.JPopupMenu; 5 | 6 | import com.domain.User; 7 | import com.service.LoginService; 8 | 9 | import net.sf.json.JSONObject; 10 | 11 | import java.awt.Cursor; 12 | import java.awt.Dimension; 13 | import java.awt.event.ActionEvent; 14 | import java.awt.event.ActionListener; 15 | import java.awt.event.MouseEvent; 16 | import java.awt.event.MouseListener; 17 | import java.io.IOException; 18 | 19 | import javax.swing.ImageIcon; 20 | import javax.swing.JLabel; 21 | import javax.swing.JMenuItem; 22 | import javax.swing.JOptionPane; 23 | 24 | /** 25 | * 该类用于显示文件项 26 | * @author 田 金 东 27 | * 28 | */ 29 | public class FileJPanel extends JPanel { 30 | private String id; 31 | private String rid; 32 | private String type; 33 | private String fileName; 34 | private Long size; 35 | private FileListJPanel fileListJPanel; 36 | 37 | 38 | //右键菜单 39 | JPopupMenu fileMenu = new JPopupMenu(); 40 | JPopupMenu dirMenu = new JPopupMenu(); 41 | JMenuItem renameDir = new JMenuItem("重命名"); 42 | JMenuItem deleteDir = new JMenuItem("删除文件夹"); 43 | 44 | 45 | JMenuItem renameFile = new JMenuItem("重命名"); 46 | JMenuItem deleteFile = new JMenuItem("删除文件"); 47 | JMenuItem downloadFile = new JMenuItem("下载文件"); 48 | 49 | /** 50 | * Create the panel. 51 | */ 52 | public FileJPanel(String id,String rid,String type,String fileName,Long size,FileListJPanel fileListJPanel) { 53 | this.id=id; 54 | this.fileName=fileName; 55 | this.rid=rid; 56 | this.type=type; 57 | this.size=size; 58 | this.fileListJPanel=fileListJPanel; 59 | setLayout(null); 60 | setPreferredSize(new Dimension(108, 126)); 61 | JLabel imgLabel = new JLabel(""); 62 | imgLabel.setBounds(10, 10, 88, 88); 63 | add(imgLabel); 64 | 65 | JLabel lblNewLabel = new JLabel(fileName,JLabel.CENTER); 66 | lblNewLabel.setBounds(0, 98, 108, 18); 67 | add(lblNewLabel); 68 | 69 | //为右键菜单添加项 70 | dirMenu.add(renameDir); 71 | dirMenu.add(deleteDir); 72 | 73 | fileMenu.add(renameFile); 74 | fileMenu.add(downloadFile); 75 | fileMenu.add(deleteFile); 76 | 77 | renameFile.addActionListener(new ActionListener() { 78 | @Override 79 | public void actionPerformed(ActionEvent e) { 80 | String newName = JOptionPane.showInputDialog(MainJFrame.mainJFrame, "重命名", fileName); 81 | if(newName!=null&&!newName.equals("")) { 82 | try { 83 | String resStr = LoginService.rename(type, id, newName); 84 | JSONObject obj = JSONObject.fromObject(resStr); 85 | 86 | if(obj.getString("type").trim().equals("true")) { 87 | FileJPanel.this.fileName=newName; 88 | JOptionPane.showMessageDialog(MainJFrame.mainJFrame, "重命名成功!"); 89 | fileListJPanel.updateFileList(); 90 | fileListJPanel.updateUI(); 91 | }else { 92 | JOptionPane.showMessageDialog(MainJFrame.mainJFrame, obj.getString("info")); 93 | } 94 | 95 | } catch (IOException e1) { 96 | JOptionPane.showMessageDialog(MainJFrame.mainJFrame, "网络异常!"); 97 | } 98 | } 99 | } 100 | }); 101 | 102 | renameDir.addActionListener(new ActionListener() { 103 | @Override 104 | public void actionPerformed(ActionEvent e) { 105 | String newName = JOptionPane.showInputDialog(MainJFrame.mainJFrame, "重命名", fileName); 106 | if(newName!=null&&!newName.equals("")) { 107 | try { 108 | String resStr = LoginService.rename(type, id, newName); 109 | JSONObject obj = JSONObject.fromObject(resStr); 110 | 111 | if(obj.getString("type").trim().equals("true")) { 112 | JOptionPane.showMessageDialog(MainJFrame.mainJFrame, "重命名成功!"); 113 | FileJPanel.this.fileName=newName; 114 | fileListJPanel.updateFileList(); 115 | fileListJPanel.updateUI(); 116 | }else { 117 | JOptionPane.showMessageDialog(MainJFrame.mainJFrame, obj.getString("info")); 118 | } 119 | 120 | } catch (IOException e1) { 121 | JOptionPane.showMessageDialog(MainJFrame.mainJFrame, "网络异常!"); 122 | } 123 | } 124 | } 125 | }); 126 | 127 | 128 | deleteDir.addActionListener(new ActionListener() { 129 | @Override 130 | public void actionPerformed(ActionEvent e) { 131 | int click = JOptionPane.showConfirmDialog(MainJFrame.mainJFrame, "确定要删除 \""+fileName+"\" 文件吗?", "警告", JOptionPane.YES_NO_OPTION); 132 | if(click==0) { 133 | try { 134 | String resStr = LoginService.delete("dir", id); 135 | JSONObject obj = JSONObject.fromObject(resStr); 136 | if(obj.getString("type").trim().equals("true")) { 137 | fileListJPanel.updateFileList(); 138 | fileListJPanel.updateUI(); 139 | JOptionPane.showMessageDialog(MainJFrame.mainJFrame, "删除成功!"); 140 | }else { 141 | JOptionPane.showMessageDialog(MainJFrame.mainJFrame, obj.getString("info")); 142 | } 143 | } catch (IOException e1) { 144 | JOptionPane.showMessageDialog(MainJFrame.mainJFrame, "网络异常!"); 145 | } 146 | } 147 | } 148 | }); 149 | deleteFile.addActionListener(new ActionListener() { 150 | @Override 151 | public void actionPerformed(ActionEvent e) { 152 | int click = JOptionPane.showConfirmDialog(MainJFrame.mainJFrame, "确定要删除 \""+fileName+"\" 文件夹吗?", "警告", JOptionPane.YES_NO_OPTION); 153 | if(click==0) { 154 | try { 155 | String resStr = LoginService.delete("file", id); 156 | JSONObject obj = JSONObject.fromObject(resStr); 157 | if(obj.getString("type").trim().equals("true")) { 158 | JOptionPane.showMessageDialog(MainJFrame.mainJFrame, "删除成功!"); 159 | User.setUsedSize(LoginService.getUsedSize()); 160 | ((MainJFrame) MainJFrame.mainJFrame).updateUsedSize(); 161 | fileListJPanel.updateFileList(); 162 | fileListJPanel.updateUI(); 163 | }else { 164 | JOptionPane.showMessageDialog(MainJFrame.mainJFrame, obj.getString("info")); 165 | } 166 | } catch (IOException e1) { 167 | JOptionPane.showMessageDialog(MainJFrame.mainJFrame, "网络异常!"); 168 | } 169 | } 170 | } 171 | }); 172 | downloadFile.addActionListener(new ActionListener() { 173 | 174 | @Override 175 | public void actionPerformed(ActionEvent e) { 176 | JOptionPane.showConfirmDialog(MainJFrame.mainJFrame, "下载功能还未开发,实现原理与上传类似", "提示", JOptionPane.CLOSED_OPTION); 177 | } 178 | }); 179 | 180 | 181 | if(type.equals("dir")) { 182 | imgLabel.setIcon(new ImageIcon("image/icon_list_folder.png")); 183 | //为“文件夹”添加鼠标监听 184 | this.addMouseListener(new MouseListener() { 185 | 186 | @Override 187 | public void mouseReleased(MouseEvent e) {} 188 | 189 | @Override 190 | public void mousePressed(MouseEvent e) { 191 | // TODO Auto-generated method stub 192 | int temp = e.getButton(); 193 | if(temp==1) { 194 | Long did = Long.valueOf(id); 195 | User.getPathStack().push(User.getFileListStr()); 196 | //如果为左键点击 197 | fileListJPanel.updateFileList(fileName, did); 198 | try { 199 | Thread.currentThread().sleep(200); 200 | } catch (InterruptedException e1) { 201 | // TODO Auto-generated catch block 202 | e1.printStackTrace(); 203 | } 204 | }else if(temp==3){ 205 | //如果为右键点击 206 | dirMenu.show(FileJPanel.this, e.getX(), e.getY()); 207 | } 208 | } 209 | @Override 210 | public void mouseExited(MouseEvent e) { 211 | } 212 | @Override 213 | public void mouseEntered(MouseEvent e) { 214 | //鼠标移入主键时变成小手 215 | FileJPanel.this.setCursor(new Cursor(Cursor.HAND_CURSOR)); 216 | } 217 | @Override 218 | public void mouseClicked(MouseEvent e) {} 219 | }); 220 | }else if(type.equals("file")) { 221 | //为文件项添加鼠标监听 222 | this.addMouseListener(new MouseListener() { 223 | @Override 224 | public void mouseReleased(MouseEvent e) {} 225 | 226 | @Override 227 | public void mousePressed(MouseEvent e) { 228 | // TODO Auto-generated method stub 229 | fileMenu.show(FileJPanel.this, e.getX(), e.getY()); 230 | } 231 | 232 | @Override 233 | public void mouseExited(MouseEvent e) {} 234 | @Override 235 | public void mouseEntered(MouseEvent e) { 236 | //鼠标移入主键时变成小手 237 | FileJPanel.this.setCursor(new Cursor(Cursor.HAND_CURSOR)); 238 | } 239 | @Override 240 | public void mouseClicked(MouseEvent e) {} 241 | }); 242 | //如果该项为文件,则设置提示信息,提示信息显示该文件大小 243 | if(size>=0&&size<1024) { 244 | this.setToolTipText(size+"B"); 245 | }else if(size<1024*1024) { 246 | this.setToolTipText((size/1024)+"KB"); 247 | }else if(size<1024*1024*1024) { 248 | this.setToolTipText((size/1024/1024)+"MB"); 249 | } 250 | if (fileName.toLowerCase().endsWith(".jpg") || fileName.toLowerCase().endsWith(".bmp") 251 | || fileName.toLowerCase().endsWith(".jepg") || fileName.toLowerCase().endsWith(".gif") 252 | || fileName.toLowerCase().endsWith(".png")) { 253 | imgLabel.setIcon(new ImageIcon("image/icon_list_image.png")); 254 | } else if (fileName.toLowerCase().endsWith(".doc") || fileName.toLowerCase().endsWith(".docx")) { 255 | imgLabel.setIcon(new ImageIcon("image/icon_list_doc.png")); 256 | } else if (fileName.toLowerCase().endsWith(".xlsx") || fileName.toLowerCase().endsWith(".xls")) { 257 | imgLabel.setIcon(new ImageIcon("image/icon_list_excel.png")); 258 | } else if (fileName.toLowerCase().endsWith(".html") || fileName.toLowerCase().endsWith(".htm")) { 259 | imgLabel.setIcon(new ImageIcon("image/icon_list_html.png")); 260 | } else if (fileName.toLowerCase().endsWith(".pdf")) { 261 | imgLabel.setIcon(new ImageIcon("image/icon_list_pdf.png")); 262 | } else if (fileName.toLowerCase().endsWith(".vsd")) { 263 | imgLabel.setIcon(new ImageIcon("image/icon_list_visio.png")); 264 | } else if (fileName.toLowerCase().endsWith(".vcf")) { 265 | imgLabel.setIcon(new ImageIcon("image/icon_list_vcard.png")); 266 | } else if (fileName.toLowerCase().endsWith(".ppt") || fileName.toLowerCase().endsWith(".pptx")) { 267 | imgLabel.setIcon(new ImageIcon("image/icon_list_ppt.png")); 268 | } else if (fileName.toLowerCase().endsWith(".mp3") || fileName.toLowerCase().endsWith(".wma")) { 269 | imgLabel.setIcon(new ImageIcon("image/icon_list_audiofile.png")); 270 | } else if (fileName.toLowerCase().endsWith(".mp4") || fileName.toLowerCase().endsWith(".rm") 271 | || fileName.toLowerCase().endsWith(".rmvb") || fileName.toLowerCase().endsWith(".avi")) { 272 | imgLabel.setIcon(new ImageIcon("image/icon_list_videofile.png")); 273 | } else if (fileName.toLowerCase().endsWith(".rar") || fileName.toLowerCase().endsWith(".jar") 274 | || fileName.toLowerCase().endsWith(".zip") || fileName.toLowerCase().endsWith(".7z")) { 275 | imgLabel.setIcon(new ImageIcon("image/icon_list_compressfile.png")); 276 | } else if (fileName.toLowerCase().endsWith(".txt") || fileName.toLowerCase().endsWith(".log") 277 | || fileName.toLowerCase().endsWith(".ini")) { 278 | imgLabel.setIcon(new ImageIcon("image/icon_list_txtfile.png")); 279 | } else { 280 | imgLabel.setIcon(new ImageIcon("image/icon_list_unknown.png")); 281 | } 282 | } 283 | } 284 | 285 | 286 | 287 | } 288 | -------------------------------------------------------------------------------- /NetDisk_Client/src/com/view/FileListJPanel.java: -------------------------------------------------------------------------------- 1 | package com.view; 2 | 3 | import java.awt.Dimension; 4 | import java.awt.FlowLayout; 5 | import java.awt.event.ActionEvent; 6 | import java.awt.event.ActionListener; 7 | import java.awt.event.MouseEvent; 8 | import java.awt.event.MouseListener; 9 | import java.io.File; 10 | import java.util.Vector; 11 | 12 | import javax.swing.JFileChooser; 13 | import javax.swing.JMenuItem; 14 | import javax.swing.JOptionPane; 15 | import javax.swing.JPanel; 16 | import javax.swing.JPopupMenu; 17 | import javax.swing.JTable; 18 | import javax.swing.JTextField; 19 | import javax.swing.table.DefaultTableModel; 20 | 21 | import com.domain.User; 22 | import com.service.LoginService; 23 | import com.service.UploadFileService; 24 | 25 | import net.sf.json.JSONArray; 26 | import net.sf.json.JSONObject; 27 | 28 | public class FileListJPanel extends JPanel { 29 | private JTextField pathTextFiled = null; 30 | 31 | private DefaultTableModel uploadTableModel; 32 | private DefaultTableModel downloadTableModel; 33 | private JTable uploadTable; 34 | private JTable downloadTable; 35 | private String path=""; 36 | //该id是当前所在文件夹的fdid 37 | private Long id; 38 | 39 | //private String preFileListStr=null; 40 | 41 | private JPopupMenu menu = new JPopupMenu(); 42 | private JMenuItem uploadFile = new JMenuItem("上传文件"); 43 | 44 | 45 | /** 46 | * Create the panel. 47 | */ 48 | public FileListJPanel(JTextField pathTextFiled,DefaultTableModel uploadTableModel,DefaultTableModel downloadTableModel,JTable uploadTable,JTable downloadTable) { 49 | this.pathTextFiled = pathTextFiled; 50 | this.uploadTableModel=uploadTableModel; 51 | this.downloadTableModel=downloadTableModel; 52 | this.uploadTable=uploadTable; 53 | this.downloadTable=downloadTable; 54 | this.setPreferredSize(new Dimension(570, 1500)); 55 | this.setLayout(new FlowLayout(FlowLayout.LEFT)); 56 | updateFileList("", 0L); 57 | 58 | //添加上传按钮 59 | menu.add(uploadFile); 60 | 61 | this.addMouseListener(new MouseListener() { 62 | public void mouseReleased(MouseEvent e) {} 63 | public void mousePressed(MouseEvent e) { 64 | if(e.getButton()==3) { 65 | menu.show(FileListJPanel.this, e.getX(), e.getY()); 66 | } 67 | 68 | } 69 | public void mouseExited(MouseEvent e) {} 70 | public void mouseEntered(MouseEvent e) {} 71 | public void mouseClicked(MouseEvent e) {} 72 | }); 73 | 74 | uploadFile.addActionListener(new ActionListener() { 75 | @Override 76 | public void actionPerformed(ActionEvent e) { 77 | // TODO Auto-generated method stub 78 | JFileChooser chooser=new JFileChooser(); 79 | //设置文件的选择模式(只能选择文件) 80 | chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); 81 | chooser.showSaveDialog(MainJFrame.mainJFrame); 82 | 83 | File file = chooser.getSelectedFile(); 84 | if(file!=null) { 85 | Vector uploadRow = new Vector<>(); 86 | uploadRow.add(file.getName()); 87 | uploadRow.add(file.getPath()); 88 | uploadRow.add(file.length()/1024/1024+"MB"); 89 | uploadRow.add(file.length()/1024/1024+"MB"); 90 | uploadTableModel.addRow(uploadRow); 91 | new UploadFileService(User.getUid(),User.getCode() , file, id, MainJFrame.mainJFrame, FileListJPanel.this,uploadRow,uploadTable).start(); 92 | } 93 | } 94 | }); 95 | } 96 | 97 | /** 98 | * 该方法用于在进入新文件夹时,对视图进行更新 99 | * @param fileName 100 | * @param id 101 | */ 102 | public void updateFileList(String fileName, Long id) { 103 | 104 | this.id = id; 105 | if(id!=0) { 106 | //当不是根目录时需要设置路径 107 | path=path+" / "+fileName; 108 | } 109 | pathTextFiled.setText(path); 110 | String fileListStr = null; 111 | try { 112 | fileListStr = LoginService.getFileListStr(id); 113 | } catch (Exception e) { 114 | JOptionPane.showMessageDialog(MainJFrame.mainJFrame, "文件项载入错误,请重新登录!"); 115 | e.printStackTrace(); 116 | } 117 | User.setFileListStr(fileListStr); 118 | 119 | JSONObject json = JSONObject.fromObject(fileListStr); 120 | 121 | JSONArray dirs = json.getJSONArray("directories"); 122 | JSONArray files = json.getJSONArray("fileItems"); 123 | 124 | //清除当前面板中所有组件 125 | this.removeAll(); 126 | int count = dirs.size() + files.size(); 127 | 128 | this.setPreferredSize(new Dimension(570, 129 | 135 * (count / 4 + (count % 4 == 0 ? 0 : 1) + 50))); 130 | for (int i = 0; i < dirs.size(); i++) { 131 | JSONObject dir = dirs.getJSONObject(i); 132 | this.add(new FileJPanel(dir.getString("did"), dir.getString("rdid"), 133 | "dir", dir.getString("dname"), 0L, this)); 134 | } 135 | for (int i = 0; i < files.size(); i++) { 136 | JSONObject file = files.getJSONObject(i); 137 | this.add(new FileJPanel(file.getString("fid"), 138 | file.getString("did"), "file", file.getString("fname"), 139 | file.getLong("file_size"), this)); 140 | } 141 | this.updateUI(); 142 | } 143 | 144 | /** 145 | * 该方法用于在创建文件夹后更新视图,与另个一重载方法不同的是,他不需要对路径进行拼接(因为他还是当前目录) 146 | */ 147 | public void updateFileList() { 148 | String fileListStr = null; 149 | try { 150 | fileListStr = LoginService.getFileListStr(id); 151 | } catch (Exception e) { 152 | // TODO Auto-generated catch block 153 | JOptionPane.showMessageDialog(MainJFrame.mainJFrame, "文件项载入错误,请重新登录!"); 154 | e.printStackTrace(); 155 | } 156 | User.setFileListStr(fileListStr); 157 | 158 | JSONObject json = JSONObject.fromObject(fileListStr); 159 | 160 | JSONArray dirs = json.getJSONArray("directories"); 161 | JSONArray files = json.getJSONArray("fileItems"); 162 | 163 | //清除当前面板中所有组件 164 | this.removeAll(); 165 | int count = dirs.size() + files.size(); 166 | 167 | this.setPreferredSize(new Dimension(570, 168 | 135 * (count / 4 + (count % 4 == 0 ? 0 : 1) + 50))); 169 | for (int i = 0; i < dirs.size(); i++) { 170 | JSONObject dir = dirs.getJSONObject(i); 171 | this.add(new FileJPanel(dir.getString("did"), dir.getString("rdid"), 172 | "dir", dir.getString("dname"), 0L, this)); 173 | } 174 | for (int i = 0; i < files.size(); i++) { 175 | JSONObject file = files.getJSONObject(i); 176 | this.add(new FileJPanel(file.getString("fid"), 177 | file.getString("did"), "file", file.getString("fname"), 178 | file.getLong("file_size"), this)); 179 | } 180 | this.updateUI(); 181 | } 182 | 183 | 184 | 185 | public void updateFileListByJson(String json) { 186 | JSONObject jsonObj = JSONObject.fromObject(json); 187 | 188 | JSONArray dirs = jsonObj.getJSONArray("directories"); 189 | JSONArray files = jsonObj.getJSONArray("fileItems"); 190 | 191 | //刷新当前页面所在目录的did; 192 | id=jsonObj.getLong("rdid"); 193 | 194 | //清除当前面板中所有组件 195 | this.removeAll(); 196 | int count = dirs.size() + files.size(); 197 | 198 | this.setPreferredSize(new Dimension(570, 199 | 135 * (count / 4 + (count % 4 == 0 ? 0 : 1) + 50))); 200 | for (int i = 0; i < dirs.size(); i++) { 201 | JSONObject dir = dirs.getJSONObject(i); 202 | this.add(new FileJPanel(dir.getString("did"), dir.getString("rdid"), 203 | "dir", dir.getString("dname"), 0L, this)); 204 | } 205 | for (int i = 0; i < files.size(); i++) { 206 | JSONObject file = files.getJSONObject(i); 207 | this.add(new FileJPanel(file.getString("fid"), 208 | file.getString("did"), "file", file.getString("fname"), 209 | file.getLong("file_size"), this)); 210 | } 211 | this.updateUI(); 212 | } 213 | 214 | public String getPath() { 215 | return path; 216 | } 217 | 218 | public void setPath(String path) { 219 | this.path = path; 220 | } 221 | 222 | public Long getId() { 223 | return id; 224 | } 225 | 226 | public void setId(Long id) { 227 | this.id = id; 228 | } 229 | 230 | } 231 | -------------------------------------------------------------------------------- /NetDisk_Client/src/com/view/LoginJDialog.java: -------------------------------------------------------------------------------- 1 | package com.view; 2 | 3 | import java.awt.Cursor; 4 | import java.awt.EventQueue; 5 | import java.awt.event.WindowAdapter; 6 | import java.awt.event.WindowEvent; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.io.OutputStream; 10 | import java.net.Socket; 11 | 12 | import javax.swing.JButton; 13 | 14 | import javax.swing.JDialog; 15 | import javax.swing.JLabel; 16 | import javax.swing.JOptionPane; 17 | import javax.swing.JPasswordField; 18 | import javax.swing.JTextField; 19 | import java.awt.event.ActionListener; 20 | import java.awt.event.ActionEvent; 21 | import javax.swing.JPanel; 22 | import javax.swing.border.TitledBorder; 23 | 24 | import com.service.LoginService; 25 | import com.utils.CheckEmail; 26 | import com.utils.ConfigLoader; 27 | 28 | import net.sf.json.JSONObject; 29 | 30 | /** 31 | * 登录页面 32 | * @author 田 金 东 33 | * 34 | */ 35 | public class LoginJDialog extends JDialog { 36 | 37 | private JPasswordField passwordField; 38 | private JTextField usernameField; 39 | private JTextField regist_email; 40 | private JTextField regist_checkCode; 41 | private JPasswordField regist_password; 42 | private JPasswordField regist_repassword; 43 | 44 | /** 45 | * Launch the application 46 | * @param args 47 | */ 48 | public static void main(String args[]) { 49 | EventQueue.invokeLater(new Runnable() { 50 | public void run() { 51 | try { 52 | LoginJDialog dialog = new LoginJDialog(); 53 | dialog.addWindowListener(new WindowAdapter() { 54 | public void windowClosing(WindowEvent e) { 55 | System.exit(0); 56 | } 57 | }); 58 | dialog.setVisible(true); 59 | } catch (Exception e) { 60 | e.printStackTrace(); 61 | } 62 | } 63 | }); 64 | } 65 | 66 | /** 67 | * Create the dialog 68 | */ 69 | public LoginJDialog() { 70 | super(); 71 | setResizable(false); 72 | setAlwaysOnTop(true); 73 | getContentPane().setLayout(null); 74 | setTitle("登录菜鸟网盘 v1.0"); 75 | setBounds(680, 360, 416, 240); 76 | 77 | usernameField = new JTextField(""); 78 | usernameField.setBounds(105, 50, 224, 28); 79 | getContentPane().add(usernameField); 80 | 81 | passwordField = new JPasswordField(); 82 | passwordField.setBounds(105, 91, 224, 27); 83 | getContentPane().add(passwordField); 84 | 85 | final JButton button = new JButton(); 86 | button.addActionListener(new ActionListener() { 87 | public void actionPerformed(ActionEvent e) { 88 | if (LoginJDialog.this.getHeight() == 240) { 89 | LoginJDialog.this.setSize(416, 563); 90 | } else if (LoginJDialog.this.getHeight() == 563) { 91 | LoginJDialog.this.setSize(416, 240); 92 | } 93 | 94 | } 95 | }); 96 | button.setText("注册账户"); 97 | button.setBounds(225, 147, 106, 28); 98 | getContentPane().add(button); 99 | 100 | final JButton button_1 = new JButton(); 101 | button_1.addActionListener(new ActionListener() { 102 | public void actionPerformed(ActionEvent e) { 103 | String username=usernameField.getText().trim(); 104 | String password=passwordField.getText().trim(); 105 | if(username.equals("")||password.equals("")) { 106 | JOptionPane.showMessageDialog(LoginJDialog.this, "用户名或密码不能为空!"); 107 | }else { 108 | boolean isLogin=false; 109 | try { 110 | isLogin = LoginService.login(username, password); 111 | } catch (Exception e1) { 112 | e1.printStackTrace(); 113 | } 114 | if(isLogin) { 115 | LoginJDialog.this.setResizable(false); 116 | LoginJDialog.this.dispose(); 117 | MainJFrame.start(); 118 | }else { 119 | JOptionPane.showMessageDialog(LoginJDialog.this, "用户名或密码错误!"); 120 | usernameField.setText(""); 121 | passwordField.setText(""); 122 | } 123 | } 124 | } 125 | }); 126 | button_1.setText("登录"); 127 | button_1.setBounds(105, 147, 106, 28); 128 | getContentPane().add(button_1); 129 | 130 | final JLabel label = new JLabel(); 131 | label.setText("忘记密码?"); 132 | label.setBounds(254, 120, 75, 18); 133 | label.setCursor(new Cursor(Cursor.HAND_CURSOR)); 134 | getContentPane().add(label); 135 | 136 | JLabel label_1 = new JLabel("用户名:"); 137 | label_1.setBounds(47, 55, 60, 18); 138 | getContentPane().add(label_1); 139 | 140 | JLabel label_2 = new JLabel("密 码:"); 141 | label_2.setBounds(47, 95, 60, 18); 142 | getContentPane().add(label_2); 143 | 144 | JPanel loginPanel = new JPanel(); 145 | loginPanel.setBorder(new TitledBorder(null, "\u7528\u6237\u6CE8\u518C", 146 | TitledBorder.LEADING, TitledBorder.TOP, null, null)); 147 | loginPanel.setToolTipText(""); 148 | loginPanel.setBounds(14, 225, 370, 291); 149 | getContentPane().add(loginPanel); 150 | loginPanel.setLayout(null); 151 | 152 | JLabel label_3 = new JLabel("邮箱:"); 153 | label_3.setBounds(37, 46, 45, 18); 154 | loginPanel.add(label_3); 155 | 156 | regist_email = new JTextField(); 157 | regist_email.setBounds(86, 40, 221, 31); 158 | loginPanel.add(regist_email); 159 | regist_email.setColumns(10); 160 | 161 | JLabel label_4 = new JLabel("验证码:"); 162 | label_4.setBounds(22, 103, 60, 18); 163 | loginPanel.add(label_4); 164 | 165 | regist_checkCode = new JTextField(); 166 | regist_checkCode.setColumns(10); 167 | regist_checkCode.setBounds(86, 97, 99, 31); 168 | loginPanel.add(regist_checkCode); 169 | 170 | JButton button_2 = new JButton("获取验证码"); 171 | button_2.setBounds(200, 99, 107, 27); 172 | loginPanel.add(button_2); 173 | button_2.addActionListener(new ActionListener() { 174 | 175 | @Override 176 | public void actionPerformed(ActionEvent e) { 177 | InputStream input; 178 | OutputStream output; 179 | String email=regist_email.getText().trim(); 180 | try { 181 | if(email.equals("")) { 182 | JOptionPane.showMessageDialog(LoginJDialog.this, "邮箱不能为空"); 183 | }else if(!CheckEmail.checkEmail(email)){ 184 | JOptionPane.showMessageDialog(LoginJDialog.this, "请输入正确的邮箱格式"); 185 | }else { 186 | Socket socket=new Socket(ConfigLoader.getServerIP(), ConfigLoader.getServerRegistPort()); 187 | input=socket.getInputStream(); 188 | output=socket.getOutputStream(); 189 | String reqInfo="{\"type\":\"checkCode\",\"email\":\""+email+"\"}"; 190 | output.write(reqInfo.getBytes()); 191 | 192 | byte[] buffer=new byte[2048]; 193 | int len = input.read(buffer); 194 | String infoStr = new String(buffer,0,len); 195 | 196 | JSONObject info = JSONObject.fromObject(infoStr); 197 | String typeInfo = info.getString("type"); 198 | if(typeInfo.trim().equals("true")) { 199 | JOptionPane.showMessageDialog(LoginJDialog.this, "验证码发送成功!"); 200 | }else { 201 | String errorInfo = info.getString("info"); 202 | JOptionPane.showMessageDialog(LoginJDialog.this, errorInfo); 203 | } 204 | output.flush(); 205 | output.close(); 206 | input.close(); 207 | } 208 | } catch (IOException e1) { 209 | // TODO Auto-generated catch block 210 | e1.printStackTrace(); 211 | } 212 | } 213 | }); 214 | 215 | JLabel label_5 = new JLabel("密码:"); 216 | label_5.setBounds(37, 158, 45, 18); 217 | loginPanel.add(label_5); 218 | 219 | JLabel label_6 = new JLabel("确认密码:"); 220 | label_6.setBounds(10, 210, 72, 18); 221 | loginPanel.add(label_6); 222 | 223 | JButton button_3 = new JButton("注册"); 224 | button_3.addActionListener(new ActionListener() { 225 | public void actionPerformed(ActionEvent e) { 226 | String email=regist_email.getText().trim(); 227 | String checkCode=regist_checkCode.getText().trim(); 228 | String password=regist_password.getText().trim(); 229 | String repassword=regist_repassword.getText().trim(); 230 | 231 | if(email.equals("")||checkCode.equals("")||password.equals("")||repassword.equals("")){ 232 | JOptionPane.showMessageDialog(LoginJDialog.this, "输入信息不完整!"); 233 | return; 234 | } 235 | if(!repassword.equals(password)) { 236 | JOptionPane.showMessageDialog(LoginJDialog.this, "两次密码不相同,请重新输入"); 237 | regist_password.setText(""); 238 | regist_repassword.setText(""); 239 | } 240 | Socket socket=null; 241 | InputStream input=null; 242 | OutputStream output=null; 243 | try { 244 | socket = new Socket(ConfigLoader.getServerIP(),ConfigLoader.getServerRegistPort()); 245 | input=socket.getInputStream(); 246 | output=socket.getOutputStream(); 247 | //请求服务器创建用户 248 | String str="{\"type\":\"reg\",\"email\":\""+email+"\",\"password\":\""+password+"\",\"checkCode\":\""+checkCode+"\"}"; 249 | 250 | output.write(str.getBytes()); 251 | output.flush(); 252 | 253 | //----接收服务器响应 254 | byte[] buffer=new byte[1024]; 255 | int len = input.read(buffer); 256 | String infoStr=new String(buffer,0,len); 257 | JSONObject info = JSONObject.fromObject(infoStr); 258 | String typeInfo = info.getString("type"); 259 | if(typeInfo.trim().equals("true")) { 260 | JOptionPane.showMessageDialog(LoginJDialog.this, "注册成功"); 261 | LoginJDialog.this.setSize(416, 240); 262 | }else if(typeInfo.trim().equals("false")){ 263 | JOptionPane.showMessageDialog(LoginJDialog.this, info.getString("info")); 264 | } 265 | } catch (IOException e1) { 266 | // TODO Auto-generated catch block 267 | e1.printStackTrace(); 268 | } 269 | } 270 | }); 271 | button_3.setBounds(86, 256, 99, 27); 272 | loginPanel.add(button_3); 273 | 274 | JButton button_4 = new JButton("取消"); 275 | button_4.addActionListener(new ActionListener() { 276 | 277 | @Override 278 | public void actionPerformed(ActionEvent e) { 279 | LoginJDialog.this.setSize(416, 240); 280 | regist_email.setText(""); 281 | regist_password.setText(""); 282 | regist_repassword.setText(""); 283 | regist_checkCode.setText(""); 284 | } 285 | }); 286 | button_4.setBounds(208, 256, 99, 27); 287 | loginPanel.add(button_4); 288 | 289 | regist_password = new JPasswordField(); 290 | regist_password.setBounds(86, 155, 221, 31); 291 | loginPanel.add(regist_password); 292 | 293 | regist_repassword = new JPasswordField(); 294 | regist_repassword.setBounds(86, 207, 221, 31); 295 | loginPanel.add(regist_repassword); 296 | } 297 | } 298 | -------------------------------------------------------------------------------- /NetDisk_Client/src/com/view/MainJFrame.java: -------------------------------------------------------------------------------- 1 | package com.view; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.EventQueue; 5 | 6 | import javax.swing.JFrame; 7 | import javax.swing.JPanel; 8 | import javax.swing.JLabel; 9 | import javax.swing.JOptionPane; 10 | import javax.swing.JProgressBar; 11 | import javax.swing.JScrollPane; 12 | import javax.swing.JTabbedPane; 13 | import javax.swing.JButton; 14 | import java.util.Vector; 15 | import javax.swing.JTable; 16 | 17 | import com.domain.User; 18 | import com.service.LoginService; 19 | 20 | import net.sf.json.JSONObject; 21 | 22 | import java.awt.Color; 23 | import java.awt.event.ActionListener; 24 | import java.io.IOException; 25 | import java.awt.event.ActionEvent; 26 | import javax.swing.JTextField; 27 | import javax.swing.ScrollPaneConstants; 28 | import javax.swing.table.DefaultTableModel; 29 | 30 | /** 31 | * 程序运行的主界面 32 | * @author 田 金 东 33 | * 34 | */ 35 | public class MainJFrame extends JFrame { 36 | 37 | private JTable uploadTable; 38 | private JTable downloadTable; 39 | public static MainJFrame mainJFrame = null; 40 | private Vector> uploadRows=new Vector<>(); 41 | private Vector> downloadRows=new Vector<>(); 42 | private DefaultTableModel uploadTableModel=null; 43 | private DefaultTableModel downloadTableModel=null; 44 | 45 | /** 46 | * Launch the application 47 | * @param args 48 | */ 49 | public static void start() { 50 | EventQueue.invokeLater(new Runnable() { 51 | public void run() { 52 | try { 53 | MainJFrame frame = new MainJFrame(); 54 | frame.setVisible(true); 55 | } catch (Exception e) { 56 | e.printStackTrace(); 57 | } 58 | } 59 | }); 60 | } 61 | 62 | public static void main(String[] args) { 63 | EventQueue.invokeLater(new Runnable() { 64 | public void run() { 65 | try { 66 | MainJFrame frame = new MainJFrame(); 67 | frame.setVisible(true); 68 | } catch (Exception e) { 69 | e.printStackTrace(); 70 | } 71 | } 72 | }); 73 | } 74 | 75 | final JProgressBar progressBar; 76 | private JTextField pathTextFiled; 77 | 78 | 79 | public void updateUsedSize() { 80 | progressBar.setMaximum((int) (User.getInitSize() / 1024 / 1024)); 81 | progressBar.setValue((int) ((User.getInitSize() - User.getUsedSize()) 82 | / 1024 / 1024)); 83 | progressBar.setString( 84 | (User.getInitSize() - User.getUsedSize()) / 1024 / 1024 + "MB /" 85 | +" "+ User.getInitSize() / 1024 / 1024 + "MB"); 86 | } 87 | 88 | /** 89 | * Create the frame 90 | */ 91 | public MainJFrame() { 92 | super(); 93 | mainJFrame = this; 94 | setResizable(false); 95 | setTitle("菜鸟网盘 V1.0"); 96 | getContentPane().setLayout(null); 97 | setBounds(648, 230, 614, 592); 98 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 99 | 100 | final JLabel userInfo = new JLabel(); 101 | userInfo.setText("用户名:" + User.getEmail()); 102 | userInfo.setBounds(20, 10, 279, 27); 103 | getContentPane().add(userInfo); 104 | 105 | final JLabel label_1 = new JLabel(); 106 | label_1.setText("容量大小:"); 107 | label_1.setBounds(20, 50, 78, 27); 108 | getContentPane().add(label_1); 109 | 110 | progressBar = new JProgressBar(); 111 | progressBar.setForeground(new Color(46, 139, 87)); 112 | progressBar.setStringPainted(true); 113 | updateUsedSize(); 114 | progressBar.setBounds(104, 51, 482, 27); 115 | getContentPane().add(progressBar); 116 | 117 | final JTabbedPane tabbedPane = new JTabbedPane(); 118 | tabbedPane.setBounds(10, 84, 584, 460); 119 | getContentPane().add(tabbedPane); 120 | 121 | final JPanel netDiskPanel = new JPanel(); 122 | netDiskPanel.setLayout(new BorderLayout()); 123 | tabbedPane.addTab("我的网盘", null, netDiskPanel, null); 124 | 125 | JPanel panel = new JPanel(); 126 | netDiskPanel.add(panel, BorderLayout.NORTH); 127 | panel.setLayout(new BorderLayout(0, 0)); 128 | 129 | JLabel lblNewLabel = new JLabel(" 路径: "); 130 | panel.add(lblNewLabel, BorderLayout.WEST); 131 | 132 | pathTextFiled = new JTextField(); 133 | pathTextFiled.setEditable(false); 134 | panel.add(pathTextFiled, BorderLayout.CENTER); 135 | pathTextFiled.setColumns(10); 136 | 137 | /*上传面板*/ 138 | final JPanel uploadPanel = new JPanel(); 139 | uploadPanel.setLayout(new BorderLayout()); 140 | tabbedPane.addTab("上传任务", null, uploadPanel, null); 141 | 142 | final JScrollPane uploadScrollPane = new JScrollPane(); 143 | uploadPanel.add(uploadScrollPane, BorderLayout.CENTER); 144 | 145 | Vector col1 = new Vector<>(); 146 | col1.add("文件名称"); 147 | col1.add("存放路径"); 148 | col1.add("大小"); 149 | col1.add("剩余"); 150 | col1.add("速度"); 151 | uploadTable = new JTable(); 152 | uploadTableModel = new DefaultTableModel(uploadRows,col1); 153 | uploadTable.setModel(uploadTableModel); 154 | uploadScrollPane.setViewportView(uploadTable); 155 | 156 | /*下载面板*/ 157 | JScrollPane scrollPane_2 = new JScrollPane(); 158 | netDiskPanel.add(scrollPane_2, BorderLayout.CENTER); 159 | 160 | final JPanel downloadPanel = new JPanel(); 161 | downloadPanel.setLayout(new BorderLayout()); 162 | tabbedPane.addTab("下载任务", null, downloadPanel, null); 163 | 164 | final JScrollPane downloadScrollPane = new JScrollPane(); 165 | downloadPanel.add(downloadScrollPane, BorderLayout.CENTER); 166 | 167 | Vector col = new Vector<>(); 168 | col.add("文件名称"); 169 | col.add("保存路径"); 170 | col.add("大小"); 171 | col.add("剩余"); 172 | col.add("速度"); 173 | 174 | downloadTable = new JTable(); 175 | downloadTableModel = new DefaultTableModel(downloadRows,col); 176 | downloadTable.setModel(downloadTableModel); 177 | downloadScrollPane.setViewportView(downloadTable); 178 | 179 | 180 | /* 添加文件项面板*/ 181 | FileListJPanel fileListJPanel = new FileListJPanel(pathTextFiled,uploadTableModel,downloadTableModel,uploadTable,downloadTable); 182 | 183 | JPanel panel_1 = new JPanel(); 184 | panel.add(panel_1, BorderLayout.EAST); 185 | panel_1.setLayout(new BorderLayout(0, 0)); 186 | 187 | JButton btnNewButton_1 = new JButton("<<"); 188 | btnNewButton_1.addActionListener(new ActionListener() { 189 | @Override 190 | public void actionPerformed(ActionEvent e) { 191 | if (User.getPathStack().size() == 0) { 192 | JOptionPane.showMessageDialog(MainJFrame.this, 193 | "当前目录已是根目录!"); 194 | } else { 195 | String pop = User.getPathStack().pop(); 196 | User.setFileListStr(pop); 197 | 198 | String path = pathTextFiled.getText(); 199 | //去掉当前目录的字符串(即去掉最后一个 /**) 200 | String currentPath = path.substring(0, 201 | path.lastIndexOf("/")); 202 | pathTextFiled.setText(currentPath); 203 | fileListJPanel.setPath(currentPath); 204 | fileListJPanel.updateFileListByJson(pop); 205 | } 206 | } 207 | }); 208 | panel_1.add(btnNewButton_1, BorderLayout.WEST); 209 | 210 | JButton createDirButton = new JButton("新建文件夹"); 211 | createDirButton.addActionListener(new ActionListener() { 212 | public void actionPerformed(ActionEvent e) { 213 | String dirName = JOptionPane.showInputDialog( 214 | MainJFrame.mainJFrame, "文件夹名", "新建文件夹", 215 | JOptionPane.QUESTION_MESSAGE); 216 | if (dirName != null && !dirName.equals("")) { 217 | try { 218 | String resStr = LoginService 219 | .createDir(fileListJPanel.getId(), dirName); 220 | JSONObject json = JSONObject.fromObject(resStr); 221 | if (json.getString("type").equals("false")) { 222 | JOptionPane.showMessageDialog(MainJFrame.mainJFrame, 223 | json.getString("info")); 224 | } 225 | 226 | fileListJPanel.updateFileList(); 227 | } catch (IOException e1) { 228 | JOptionPane.showMessageDialog(MainJFrame.mainJFrame, 229 | "网络异常"); 230 | 231 | e1.printStackTrace(); 232 | } 233 | } 234 | } 235 | }); 236 | panel_1.add(createDirButton, BorderLayout.CENTER); 237 | 238 | JButton btnNewButton = new JButton("刷新"); 239 | btnNewButton.addActionListener(new ActionListener() { 240 | public void actionPerformed(ActionEvent e) { 241 | System.out.println(User.getFileListStr()); 242 | JSONObject json = JSONObject.fromObject(User.getFileListStr()); 243 | fileListJPanel.setId(json.getLong("rdid")); 244 | fileListJPanel.updateFileList(); 245 | JOptionPane.showMessageDialog(MainJFrame.this, "刷新成功!"); 246 | } 247 | }); 248 | panel_1.add(btnNewButton, BorderLayout.EAST); 249 | scrollPane_2.getViewport().setView(fileListJPanel); 250 | scrollPane_2.setHorizontalScrollBarPolicy( 251 | ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); 252 | 253 | 254 | 255 | final JButton button = new JButton(); 256 | button.addActionListener(new ActionListener() { 257 | 258 | public void actionPerformed(ActionEvent e) { 259 | 260 | int click = JOptionPane.showConfirmDialog(MainJFrame.this, 261 | "确定要退出吗?", "警告", JOptionPane.YES_NO_OPTION); 262 | System.out.println(click); 263 | if (click == 0) { 264 | LoginService.logout(); 265 | MainJFrame.this.dispose(); 266 | } 267 | } 268 | }); 269 | button.setText("退出网盘"); 270 | button.setBounds(480, 9, 106, 28); 271 | getContentPane().add(button); 272 | 273 | final JButton button_1_1 = new JButton(); 274 | button_1_1.addActionListener(new ActionListener() { 275 | public void actionPerformed(ActionEvent e) { 276 | RePasswordDialog.main(null); 277 | } 278 | }); 279 | button_1_1.setText("修改密码"); 280 | button_1_1.setBounds(360, 9, 106, 28); 281 | getContentPane().add(button_1_1); 282 | } 283 | } 284 | -------------------------------------------------------------------------------- /NetDisk_Client/src/com/view/RePasswordDialog.java: -------------------------------------------------------------------------------- 1 | package com.view; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.FlowLayout; 5 | 6 | import javax.swing.JButton; 7 | import javax.swing.JDialog; 8 | import javax.swing.JPanel; 9 | import javax.swing.border.EmptyBorder; 10 | 11 | import com.domain.User; 12 | import com.utils.ConfigLoader; 13 | 14 | import net.sf.json.JSONObject; 15 | 16 | import javax.swing.JPasswordField; 17 | import javax.swing.JLabel; 18 | import javax.swing.JOptionPane; 19 | 20 | import java.awt.event.ActionListener; 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | import java.io.OutputStream; 24 | import java.net.Socket; 25 | import java.awt.event.ActionEvent; 26 | 27 | /** 28 | * 密码修改界面 29 | * @author 田 金 东 30 | * 31 | */ 32 | public class RePasswordDialog extends JDialog { 33 | 34 | private final JPanel contentPanel = new JPanel(); 35 | private JPasswordField passwordField; 36 | private JPasswordField rePasswordField_1; 37 | private JPasswordField rePasswordField_2; 38 | 39 | /** 40 | * Launch the application. 41 | */ 42 | public static void main(String[] args) { 43 | try { 44 | RePasswordDialog dialog = new RePasswordDialog(); 45 | dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 46 | dialog.setVisible(true); 47 | } catch (Exception e) { 48 | e.printStackTrace(); 49 | } 50 | } 51 | 52 | /** 53 | * Create the dialog. 54 | */ 55 | public RePasswordDialog() { 56 | setTitle("修改密码"); 57 | setBounds(742, 360, 450, 300); 58 | getContentPane().setLayout(null); 59 | contentPanel.setBounds(0, 0, 432, 253); 60 | contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); 61 | getContentPane().add(contentPanel); 62 | contentPanel.setLayout(null); 63 | 64 | passwordField = new JPasswordField(); 65 | passwordField.setBounds(133, 41, 189, 32); 66 | contentPanel.add(passwordField); 67 | 68 | rePasswordField_1 = new JPasswordField(); 69 | rePasswordField_1.setBounds(133, 86, 189, 32); 70 | contentPanel.add(rePasswordField_1); 71 | 72 | rePasswordField_2 = new JPasswordField(); 73 | rePasswordField_2.setBounds(133, 131, 189, 32); 74 | contentPanel.add(rePasswordField_2); 75 | 76 | JLabel label = new JLabel("原密码:"); 77 | label.setBounds(66, 48, 60, 18); 78 | contentPanel.add(label); 79 | 80 | JLabel label_1 = new JLabel("新密码:"); 81 | label_1.setBounds(66, 93, 60, 18); 82 | contentPanel.add(label_1); 83 | 84 | JLabel label_2 = new JLabel("确认密码:"); 85 | label_2.setBounds(51, 138, 75, 18); 86 | contentPanel.add(label_2); 87 | 88 | JButton button = new JButton("确认修改"); 89 | button.addActionListener(new ActionListener() { 90 | public void actionPerformed(ActionEvent e) { 91 | 92 | String password=passwordField.getText().trim(); 93 | String rePassword=rePasswordField_1.getText().trim(); 94 | String rePassword1=rePasswordField_2.getText().trim(); 95 | if(!rePassword.equals(rePassword1)) { 96 | JOptionPane.showMessageDialog(RePasswordDialog.this, "您两次输入的密码不一致!"); 97 | return; 98 | } 99 | 100 | String reqStr="{\"type\":\"rePassword\",\"email\":\""+User.getEmail()+"\",\"password\":\""+password+"\",\"rePassword\":\""+rePassword+"\"}"; 101 | 102 | try { 103 | Socket socket = new Socket(ConfigLoader.getServerIP(),ConfigLoader.getServerLoginPort()); 104 | InputStream input = socket.getInputStream(); 105 | OutputStream output = socket.getOutputStream(); 106 | 107 | output.write(reqStr.getBytes()); 108 | output.flush(); 109 | byte[] buffer=new byte[1024]; 110 | int length = input.read(buffer); 111 | String resStr = new String(buffer,0,length); 112 | 113 | JSONObject json = JSONObject.fromObject(resStr); 114 | 115 | if(json.getString("type").trim().equals("false")) { 116 | JOptionPane.showMessageDialog(RePasswordDialog.this, "原密码输入错误"); 117 | passwordField.setText(""); 118 | }else { 119 | JOptionPane.showMessageDialog(RePasswordDialog.this, "密码更改成功!"); 120 | RePasswordDialog.this.setResizable(false); 121 | RePasswordDialog.this.dispose(); 122 | } 123 | 124 | 125 | } catch (IOException e1) { 126 | // TODO Auto-generated catch block 127 | e1.printStackTrace(); 128 | } 129 | } 130 | }); 131 | button.setBounds(167, 200, 113, 27); 132 | contentPanel.add(button); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /NetDisk_Client/src/commons-beanutils-1.8.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/src/commons-beanutils-1.8.3.jar -------------------------------------------------------------------------------- /NetDisk_Client/src/commons-collections-3.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/src/commons-collections-3.2.1.jar -------------------------------------------------------------------------------- /NetDisk_Client/src/commons-lang-2.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/src/commons-lang-2.6.jar -------------------------------------------------------------------------------- /NetDisk_Client/src/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/src/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /NetDisk_Client/src/config.properties: -------------------------------------------------------------------------------- 1 | #配置服务器IP 2 | server_ip:192.168.41.1 3 | server_regist_port:5681 4 | server_login_port:5682 5 | server_upload_port:5683 6 | server_download_port:5684 7 | -------------------------------------------------------------------------------- /NetDisk_Client/src/ezmorph-1.0.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/src/ezmorph-1.0.6.jar -------------------------------------------------------------------------------- /NetDisk_Client/src/json-lib-2.4-jdk15.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDisk_Client/src/json-lib-2.4-jdk15.jar -------------------------------------------------------------------------------- /NetDistk_Server/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /NetDistk_Server/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | NetDistk_Server 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /NetDistk_Server/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/config.properties=UTF-8 3 | -------------------------------------------------------------------------------- /NetDistk_Server/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.8 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.8 12 | -------------------------------------------------------------------------------- /NetDistk_Server/bin/c3p0-0.9.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/c3p0-0.9.1.2.jar -------------------------------------------------------------------------------- /NetDistk_Server/bin/c3p0-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.mysql.jdbc.Driver 6 | jdbc:mysql://localhost:3306/netdisk 7 | root 8 | 980613 9 | 5 10 | 20 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/dao/DownloadDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/dao/DownloadDao.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/dao/LoginDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/dao/LoginDao.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/dao/RegistDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/dao/RegistDao.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/dao/UploadDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/dao/UploadDao.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/domain/Directory.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/domain/Directory.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/domain/FileItem.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/domain/FileItem.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/domain/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/domain/User.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/service/DownloadService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/service/DownloadService.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/service/LoginService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/service/LoginService.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/service/RegistUserService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/service/RegistUserService.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/service/StartServer$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/service/StartServer$1.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/service/StartServer$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/service/StartServer$2.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/service/StartServer$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/service/StartServer$3.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/service/StartServer$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/service/StartServer$4.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/service/StartServer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/service/StartServer.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/service/UploadService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/service/UploadService.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/service/UserOnline.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/service/UserOnline.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/test/HelloTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/test/HelloTest.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/utils/C3P0Utils.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/utils/C3P0Utils.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/utils/ConfigLoader.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/utils/ConfigLoader.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/utils/EmailUtils.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/utils/EmailUtils.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/com/utils/MD5FileUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/com/utils/MD5FileUtil.class -------------------------------------------------------------------------------- /NetDistk_Server/bin/commons-beanutils-1.8.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/commons-beanutils-1.8.3.jar -------------------------------------------------------------------------------- /NetDistk_Server/bin/commons-collections-3.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/commons-collections-3.2.1.jar -------------------------------------------------------------------------------- /NetDistk_Server/bin/commons-dbutils-1.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/commons-dbutils-1.7.jar -------------------------------------------------------------------------------- /NetDistk_Server/bin/commons-email-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/commons-email-1.4.jar -------------------------------------------------------------------------------- /NetDistk_Server/bin/commons-lang-2.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/commons-lang-2.6.jar -------------------------------------------------------------------------------- /NetDistk_Server/bin/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /NetDistk_Server/bin/config.properties: -------------------------------------------------------------------------------- 1 | #配置服务器IP 2 | server_regist_port:5681 3 | server_login_port:5682 4 | server_upload_port:5683 5 | server_download_port:5684 6 | file_path:E:/NetDisk 7 | 8 | -------------------------------------------------------------------------------- /NetDistk_Server/bin/ezmorph-1.0.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/ezmorph-1.0.6.jar -------------------------------------------------------------------------------- /NetDistk_Server/bin/json-lib-2.4-jdk15.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/json-lib-2.4-jdk15.jar -------------------------------------------------------------------------------- /NetDistk_Server/bin/mail.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/mail.jar -------------------------------------------------------------------------------- /NetDistk_Server/bin/mailapi.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/mailapi.jar -------------------------------------------------------------------------------- /NetDistk_Server/bin/mysql-connector-java-5.1.44-bin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/mysql-connector-java-5.1.44-bin.jar -------------------------------------------------------------------------------- /NetDistk_Server/bin/test/HelloTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/bin/test/HelloTest.class -------------------------------------------------------------------------------- /NetDistk_Server/src/c3p0-0.9.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/src/c3p0-0.9.1.2.jar -------------------------------------------------------------------------------- /NetDistk_Server/src/c3p0-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.mysql.jdbc.Driver 6 | jdbc:mysql://localhost:3306/netdisk 7 | root 8 | 980613 9 | 5 10 | 20 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/dao/DownloadDao.java: -------------------------------------------------------------------------------- 1 | package com.dao; 2 | 3 | public class DownloadDao { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/dao/LoginDao.java: -------------------------------------------------------------------------------- 1 | package com.dao; 2 | 3 | import static org.hamcrest.CoreMatchers.nullValue; 4 | 5 | import java.sql.Connection; 6 | import java.sql.PreparedStatement; 7 | import java.sql.ResultSet; 8 | import java.sql.SQLException; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | import org.junit.Test; 13 | 14 | import com.domain.Directory; 15 | import com.domain.FileItem; 16 | import com.domain.User; 17 | import com.utils.C3P0Utils; 18 | 19 | /** 20 | * 该类用于登录操作中的数据库操作 21 | * @author 田 金 东 22 | * 23 | */ 24 | public class LoginDao { 25 | 26 | public User login(String username, String password) throws SQLException { 27 | Connection connection = C3P0Utils.getConnection(); 28 | String sql = "select uid,user_email,user_size from user where user_email=? and user_password=?"; 29 | PreparedStatement prepareStatement = connection.prepareStatement(sql); 30 | prepareStatement.setString(1, username); 31 | prepareStatement.setString(2, password); 32 | ResultSet result = prepareStatement.executeQuery(); 33 | if (result.next()) { 34 | User user = new User(); 35 | user.setUid(result.getLong("uid")); 36 | user.setEmail(result.getString("user_email")); 37 | user.setInitSize(result.getLong("user_size")); 38 | return user; 39 | } 40 | connection.close(); 41 | return null; 42 | } 43 | 44 | public Long getUsedSize(Long uid) throws SQLException { 45 | Connection connection = C3P0Utils.getConnection(); 46 | String sql = "select sum(file_size) from user_file_items where uid=?"; 47 | PreparedStatement prepareStatement = connection.prepareStatement(sql); 48 | prepareStatement.setLong(1, uid); 49 | ResultSet query = prepareStatement.executeQuery(); 50 | Long size = null; 51 | if (query.next()) { 52 | size = query.getLong(1); 53 | } 54 | connection.close(); 55 | return size; 56 | } 57 | 58 | public boolean rePassword(String username, String password, 59 | String rePassword) throws SQLException { 60 | Connection connection = C3P0Utils.getConnection(); 61 | String sql = "update user set user_password=? where user_email=? and user_password=?"; 62 | PreparedStatement prepareStatement = connection.prepareStatement(sql); 63 | prepareStatement.setString(1, rePassword); 64 | prepareStatement.setString(2, username); 65 | prepareStatement.setString(3, password); 66 | 67 | int row = prepareStatement.executeUpdate(); 68 | if (row == 0) { 69 | return false; 70 | } else if (row == 1) { 71 | return true; 72 | } 73 | connection.close(); 74 | return false; 75 | } 76 | 77 | public List getDirectories(Long uid, Long rid) 78 | throws SQLException { 79 | Connection connection = C3P0Utils.getConnection(); 80 | String sql = "select * from user_file_drictory where rdid=? and uid=?"; 81 | PreparedStatement prepareStatement = connection.prepareStatement(sql); 82 | prepareStatement.setLong(1, rid); 83 | prepareStatement.setLong(2, uid); 84 | ResultSet result = prepareStatement.executeQuery(); 85 | ArrayList list = new ArrayList<>(); 86 | while (result.next()) { 87 | list.add(new Directory(result.getLong("did"), 88 | result.getString("dname"), result.getLong("rdid"), 89 | result.getLong("uid"))); 90 | } 91 | connection.close(); 92 | return list; 93 | } 94 | 95 | public List getFileItems(Long uid, Long did) throws SQLException { 96 | Connection connection = C3P0Utils.getConnection(); 97 | String sql = "select * from user_file_items where did=? and uid=?"; 98 | PreparedStatement prepareStatement = connection.prepareStatement(sql); 99 | prepareStatement.setLong(1, did); 100 | prepareStatement.setLong(2, uid); 101 | ResultSet result = prepareStatement.executeQuery(); 102 | ArrayList list = new ArrayList<>(); 103 | while (result.next()) { 104 | FileItem item = new FileItem(); 105 | item.setDid(result.getLong("did")); 106 | item.setFid(result.getLong("fid")); 107 | item.setFile_md5(result.getString("file_md5")); 108 | item.setFile_size(result.getLong("file_size")); 109 | item.setFname(result.getString("fname")); 110 | item.setUid(result.getLong("uid")); 111 | list.add(item); 112 | } 113 | return list; 114 | } 115 | 116 | public int mkDir(Directory dir) throws SQLException { 117 | 118 | Connection connection = C3P0Utils.getConnection(); 119 | //由于did设置了主键自增,所以不用指定did 120 | String sql = "insert into user_file_drictory(dname,rdid,uid) values(?,?,?)"; 121 | PreparedStatement prepare = connection.prepareStatement(sql); 122 | prepare.setString(1, dir.getDname()); 123 | prepare.setLong(2, dir.getRdid()); 124 | prepare.setLong(3, dir.getUid()); 125 | 126 | return prepare.executeUpdate(); 127 | } 128 | 129 | /** 130 | * 131 | * @param uid 132 | * @param rid 133 | * @param dname 134 | * @return true 代表当前目录下没有同名文件,可以使用该文件名 135 | * false 代表当前目录下有同名文件,不能使用该文件名 136 | * @throws SQLException 137 | */ 138 | public boolean isExistName(Directory dir) throws SQLException { 139 | Connection connection = C3P0Utils.getConnection(); 140 | //由于did设置了主键自增,所以不用指定did 141 | String sql = "select * from user_file_drictory where dname=? and rdid=? and uid=?"; 142 | PreparedStatement prepare = connection.prepareStatement(sql); 143 | prepare.setString(1, dir.getDname()); 144 | prepare.setLong(2, dir.getRdid()); 145 | prepare.setLong(3, dir.getUid()); 146 | ResultSet executeQuery = prepare.executeQuery(); 147 | if (executeQuery.next()) { 148 | return false; 149 | } else { 150 | return true; 151 | } 152 | } 153 | 154 | public void deleteDir(Long uid, Long did) throws SQLException { 155 | Connection connection = C3P0Utils.getConnection(); 156 | //由于did设置了主键自增,所以不用指定did 157 | String sql = "delete from user_file_drictory where did=? and uid=?"; 158 | PreparedStatement prepare = connection.prepareStatement(sql); 159 | prepare.setLong(1, did); 160 | prepare.setLong(2, uid); 161 | prepare.executeUpdate(); 162 | connection.close(); 163 | } 164 | 165 | public void deleteFileItem(long uid, long fid) throws SQLException { 166 | Connection connection = C3P0Utils.getConnection(); 167 | //由于did设置了主键自增,所以不用指定did 168 | String sql = "delete from user_file_items where fid=? and uid=?"; 169 | PreparedStatement prepare = connection.prepareStatement(sql); 170 | prepare.setLong(1, fid); 171 | prepare.setLong(2, uid); 172 | prepare.executeUpdate(); 173 | connection.close(); 174 | } 175 | 176 | /** 177 | * 判断当前文件夹的名称在当前父文件夹下是否重名 178 | * @param did 179 | * @return true 该文件名可以使用 180 | * false 该文件夹名重名 181 | * @throws SQLException 182 | */ 183 | public boolean dirNameIsExist(Long uid,Long did, String dname) throws SQLException { 184 | Connection connection = C3P0Utils.getConnection(); 185 | 186 | //就要判断文件夹是否重名也要判断文件是否重名 187 | String sql = "select * from user_file_drictory where rdid=(select rdid from user_file_drictory where did=?) and dname=? and uid=?"; 188 | PreparedStatement prepare = connection.prepareStatement(sql); 189 | prepare.setLong(1, did); 190 | prepare.setString(2, dname); 191 | prepare.setLong(3, uid); 192 | ResultSet result = prepare.executeQuery(); 193 | if (result.next()) { 194 | return false; 195 | } 196 | prepare = connection.prepareStatement( 197 | "select * from user_file_items where fname=? and did=(select rdid from user_file_drictory where did=?) and uid=?"); 198 | prepare.setString(1, dname); 199 | prepare.setLong(2, did); 200 | prepare.setLong(3, uid); 201 | ResultSet result2 = prepare.executeQuery(); 202 | if (result2.next()) { 203 | return false; 204 | } 205 | return true; 206 | } 207 | /** 208 | * 判断当前文件所在文件夹下有没指定名称的文件或文件夹 209 | * @param fid 210 | * @param fname 211 | * @return 212 | * @throws SQLException 213 | */ 214 | public boolean fileNameIsExist(Long uid,Long fid, String fname) throws SQLException { 215 | Connection connection = C3P0Utils.getConnection(); 216 | //先判断文件是否重名 217 | String sql = "select * from user_file_items where did=(select did from user_file_items where fid=?) and fname=? and uid=?"; 218 | PreparedStatement prepare = connection.prepareStatement(sql); 219 | prepare.setLong(1, fid); 220 | prepare.setString(2, fname); 221 | prepare.setLong(3, uid); 222 | ResultSet result = prepare.executeQuery(); 223 | if (result.next()) { 224 | return false; 225 | } 226 | prepare = connection.prepareStatement( 227 | "select * from user_file_drictory where dname=? and rdid=(select did from user_file_items where fid=?) and uid=?"); 228 | prepare.setString(1, fname); 229 | prepare.setLong(2, fid); 230 | prepare.setLong(3, uid); 231 | ResultSet result2 = prepare.executeQuery(); 232 | if (result2.next()) { 233 | return false; 234 | } 235 | return true; 236 | } 237 | 238 | /** 239 | * 修改文件夹名称 240 | * @param did 241 | * @param newName 242 | * @throws SQLException 243 | */ 244 | public void reNameDir(Long did,String newName) throws SQLException { 245 | Connection connection = C3P0Utils.getConnection(); 246 | //先判断文件是否重名 247 | String sql = "update user_file_drictory set dname=? where did=?"; 248 | PreparedStatement prepare = connection.prepareStatement(sql); 249 | prepare.setString(1, newName); 250 | prepare.setLong(2, did); 251 | 252 | prepare.executeUpdate(); 253 | } 254 | 255 | /** 256 | * 修改文件名称 257 | * @param fid 258 | * @param newName 259 | * @throws SQLException 260 | */ 261 | public void reNameFile(Long fid,String newName) throws SQLException { 262 | Connection connection = C3P0Utils.getConnection(); 263 | //先判断文件是否重名 264 | String sql = "update user_file_items set fname=? where fid=?"; 265 | PreparedStatement prepare = connection.prepareStatement(sql); 266 | prepare.setString(1, newName); 267 | prepare.setLong(2, fid); 268 | prepare.executeUpdate(); 269 | } 270 | public Long getInitSize(Long uid) throws SQLException { 271 | Connection connection = C3P0Utils.getConnection(); 272 | //先判断文件是否重名 273 | String sql = "select user_size from user where uid=?"; 274 | PreparedStatement prepare = connection.prepareStatement(sql); 275 | prepare.setLong(1, uid); 276 | ResultSet result = prepare.executeQuery(); 277 | if(result.next()) { 278 | return result.getLong(1); 279 | } 280 | return null; 281 | } 282 | 283 | @Test 284 | public void test() throws SQLException { 285 | // reNameFile(2L,"haha.doc"); 286 | //System.out.println(isExistName(new Directory(0L, "新建文件夹1", 0L, 1L))); 287 | //deleteDir(1L, 14L); 288 | //System.out.println(isDirExist(1L,1L,"哈哈")); 289 | //System.out.println(isFileExist(1L,1L,"哈哈")); 290 | 291 | } 292 | 293 | 294 | 295 | } 296 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/dao/RegistDao.java: -------------------------------------------------------------------------------- 1 | package com.dao; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.sql.SQLException; 7 | 8 | import org.junit.Test; 9 | 10 | import com.utils.C3P0Utils; 11 | 12 | /** 13 | * 该类用于注册业务时数据库的操作 14 | * @author 田 金 东 15 | * 16 | */ 17 | public class RegistDao { 18 | 19 | /** 20 | * 创建用户 21 | * @param email 22 | * @param password 23 | * @throws SQLException 24 | */ 25 | public void createUser(String email, String password) throws SQLException { 26 | String sql = "insert into user(user_email,user_password,user_size) values(?,?,?)"; 27 | Connection connection = C3P0Utils.getConnection(); 28 | PreparedStatement prepareStatement = connection.prepareStatement(sql); 29 | prepareStatement.setString(1, email); 30 | prepareStatement.setString(2, password); 31 | prepareStatement.setString(3, new Long(5000*1024*1024).toString()); 32 | prepareStatement.executeUpdate(); 33 | connection.close(); 34 | prepareStatement.close(); 35 | } 36 | 37 | /** 38 | * 判断该email在数据库中是否存在,如果存在返回false(该邮箱已经注册,不能使用),返回true(该邮箱可以使用) 39 | * @param infoEmail 40 | * @return 41 | */ 42 | public boolean checkEmail(String infoEmail) { 43 | String sql = "select uid from user where user_email=?"; 44 | Connection connection = C3P0Utils.getConnection(); 45 | try { 46 | PreparedStatement prepareStatement = connection.prepareStatement(sql); 47 | prepareStatement.setString(1, infoEmail); 48 | ResultSet executeQuery = prepareStatement.executeQuery(); 49 | if(executeQuery.next()) { 50 | return false; 51 | } 52 | return true; 53 | } catch (SQLException e) { 54 | e.printStackTrace(); 55 | return false; 56 | } 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/dao/UploadDao.java: -------------------------------------------------------------------------------- 1 | package com.dao; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.sql.SQLException; 7 | 8 | import org.junit.Test; 9 | 10 | import com.utils.C3P0Utils; 11 | 12 | /** 13 | * 上传操作的持久层 14 | * @author 田 金 东 15 | * 16 | */ 17 | public class UploadDao { 18 | 19 | public boolean isExistFile(String filemd5) throws SQLException { 20 | Connection con=C3P0Utils.getConnection(); 21 | PreparedStatement prepare = con.prepareStatement("select count(file_md5) from sys_file_items where file_md5=?"); 22 | prepare.setString(1, filemd5); 23 | ResultSet result = prepare.executeQuery(); 24 | if(result.next()) { 25 | long num = result.getLong(1); 26 | if(num>0) { 27 | return true; 28 | } 29 | } 30 | return false; 31 | } 32 | 33 | /** 34 | * 在数据库中注册用户文件信息 35 | * @param fileName 文件名 36 | * @param uid 用户ID 37 | * @param did 所在文件夹ID 38 | * @param fileSize 文件大小 39 | * @param filemd5 文件的MD5码 40 | * @throws SQLException 41 | */ 42 | public void regUserFile(String fileName,Long uid,Long did,Long fileSize,String filemd5) throws SQLException { 43 | Connection con=C3P0Utils.getConnection(); 44 | PreparedStatement prepare = con.prepareStatement("insert into user_file_items(fname,upload_time,uid,did,file_size,file_md5) values (?,SYSDATE(),?,?,?,?)"); 45 | prepare.setString(1, fileName); 46 | prepare.setLong(2, uid); 47 | prepare.setLong(3, did); 48 | prepare.setLong(4, fileSize); 49 | prepare.setString(5, filemd5); 50 | prepare.executeUpdate(); 51 | } 52 | 53 | /** 54 | * 用于在数据库中注册用户首次上传文件的用户信息。 55 | * @param filemd5 文件的MD5码(主键) 56 | * @param fileSize 文件大小 57 | * @param filePath 文件在本地操作系统中存放路径 58 | * @param firstUid 第一次上传该文件的用户ID 59 | * @throws SQLException 60 | */ 61 | public void regSystemFile(String filemd5,Long fileSize,String filePath,Long firstUid) throws SQLException { 62 | Connection con=C3P0Utils.getConnection(); 63 | PreparedStatement prepare = con.prepareStatement("insert into sys_file_items(file_md5,file_size,file_path,upload_time,uid_first) values (?,?,?,SYSDATE(),?)"); 64 | prepare.setString(1, filemd5); 65 | prepare.setLong(2, fileSize); 66 | prepare.setString(3, filePath); 67 | prepare.setLong(4, firstUid); 68 | prepare.executeUpdate(); 69 | } 70 | @Test 71 | public void test() { 72 | try { 73 | regUserFile("你好.xls",1L,0L,1231231L,"dsadasdsadsa"); 74 | } catch (SQLException e) { 75 | // TODO Auto-generated catch block 76 | e.printStackTrace(); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/domain/Directory.java: -------------------------------------------------------------------------------- 1 | package com.domain; 2 | 3 | public class Directory { 4 | private Long did; 5 | private String dname; 6 | private Long rdid; 7 | private Long uid; 8 | 9 | 10 | public Long getDid() { 11 | return did; 12 | } 13 | public void setDid(Long did) { 14 | this.did = did; 15 | } 16 | public String getDname() { 17 | return dname; 18 | } 19 | public void setDname(String dname) { 20 | this.dname = dname; 21 | } 22 | public Long getRdid() { 23 | return rdid; 24 | } 25 | public void setRdid(Long rdid) { 26 | this.rdid = rdid; 27 | } 28 | public Long getUid() { 29 | return uid; 30 | } 31 | public void setUid(Long uid) { 32 | this.uid = uid; 33 | } 34 | public Directory(Long did, String dname, Long rdid, Long uid) { 35 | super(); 36 | this.did = did; 37 | this.dname = dname; 38 | this.rdid = rdid; 39 | this.uid = uid; 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/domain/FileItem.java: -------------------------------------------------------------------------------- 1 | package com.domain; 2 | 3 | public class FileItem { 4 | private Long fid; 5 | private String fname; 6 | private Long did; 7 | private String file_md5; 8 | private Long file_size; 9 | private Long uid; 10 | 11 | 12 | public Long getFid() { 13 | return fid; 14 | } 15 | public void setFid(Long fid) { 16 | this.fid = fid; 17 | } 18 | public String getFname() { 19 | return fname; 20 | } 21 | public void setFname(String fname) { 22 | this.fname = fname; 23 | } 24 | public Long getDid() { 25 | return did; 26 | } 27 | public void setDid(Long did) { 28 | this.did = did; 29 | } 30 | public String getFile_md5() { 31 | return file_md5; 32 | } 33 | public void setFile_md5(String file_md5) { 34 | this.file_md5 = file_md5; 35 | } 36 | public Long getFile_size() { 37 | return file_size; 38 | } 39 | public void setFile_size(Long file_size) { 40 | this.file_size = file_size; 41 | } 42 | public Long getUid() { 43 | return uid; 44 | } 45 | public void setUid(Long uid) { 46 | this.uid = uid; 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.domain; 2 | 3 | /** 4 | * 封装用户信息 5 | * @author 田 金 东 6 | * 7 | */ 8 | public class User { 9 | private Long uid; 10 | private String email; 11 | private Long initSize; 12 | public String getEmail() { 13 | return email; 14 | } 15 | public void setEmail(String email) { 16 | this.email = email; 17 | } 18 | public Long getInitSize() { 19 | return initSize; 20 | } 21 | public void setInitSize(Long initSize) { 22 | this.initSize = initSize; 23 | } 24 | public Long getUid() { 25 | return uid; 26 | } 27 | public void setUid(Long uid) { 28 | this.uid = uid; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/service/DownloadService.java: -------------------------------------------------------------------------------- 1 | package com.service; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.OutputStream; 6 | import java.net.ServerSocket; 7 | import java.net.Socket; 8 | 9 | import com.utils.ConfigLoader; 10 | 11 | import net.sf.json.JSONObject; 12 | 13 | public class DownloadService extends Thread{ 14 | 15 | private Socket socket; 16 | 17 | public DownloadService(Socket socket) { 18 | super(); 19 | this.socket = socket; 20 | } 21 | 22 | public void run() { 23 | //{"uid":xxx,"code":"xxx","fid":"xxx"} 24 | InputStream input=null; 25 | OutputStream output=null; 26 | 27 | try { 28 | input=socket.getInputStream(); 29 | output=socket.getOutputStream(); 30 | byte[] buffer=new byte[1024]; 31 | int length = input.read(buffer); 32 | String jsonStr=new String(buffer,0,length); 33 | JSONObject json = JSONObject.fromObject(jsonStr); 34 | 35 | Long uid=json.getLong("uid"); 36 | Long fid = json.getLong("fid"); 37 | String code=json.getString("code"); 38 | 39 | 40 | 41 | } catch (IOException e) { 42 | // TODO Auto-generated catch block 43 | e.printStackTrace(); 44 | } 45 | } 46 | 47 | public static void openDownloadService() throws Exception { 48 | ServerSocket serverSocket = new ServerSocket(ConfigLoader.getDownloadPort()); 49 | while(true) { 50 | Socket socket = serverSocket.accept(); 51 | new DownloadService(socket).start(); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/service/LoginService.java: -------------------------------------------------------------------------------- 1 | package com.service; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.OutputStream; 6 | import java.net.ServerSocket; 7 | import java.net.Socket; 8 | import java.sql.SQLException; 9 | import java.util.HashMap; 10 | import java.util.List; 11 | 12 | import com.dao.LoginDao; 13 | import com.domain.Directory; 14 | import com.domain.FileItem; 15 | import com.domain.User; 16 | import com.utils.ConfigLoader; 17 | import com.utils.MD5FileUtil; 18 | 19 | import net.sf.json.JSONObject; 20 | 21 | public class LoginService extends Thread { 22 | private Socket socket; 23 | private LoginDao dao; 24 | 25 | public LoginService(Socket socket) { 26 | this.socket = socket; 27 | dao = new LoginDao(); 28 | } 29 | 30 | public void run() { 31 | InputStream input=null; 32 | OutputStream output=null; 33 | try { 34 | input = socket.getInputStream(); 35 | output = socket.getOutputStream(); 36 | String reqStr = null; 37 | JSONObject reqInfo = null; 38 | User user = null; 39 | while (true) { 40 | byte[] buffer = new byte[2048]; 41 | int length = input.read(buffer); 42 | reqStr = new String(buffer, 0, length); 43 | reqInfo = JSONObject.fromObject(reqStr); 44 | String typeInfo = reqInfo.getString("type").trim(); 45 | if (reqInfo.getString("type").trim().equals("login")) {//登录 46 | String username = reqInfo.getString("email"); 47 | String password = reqInfo.getString("password"); 48 | user = dao.login(username, password); 49 | String resStr = null; 50 | if (user != null) { 51 | String code= MD5FileUtil.getMD5String(System.currentTimeMillis() + "" + user.getUid()); 52 | //在UserOnline中注册串码。 53 | UserOnline.regUserOnline(code, user.getUid()); 54 | resStr = "{\"type\":\"true\",\"uid\":\"" + user.getUid() 55 | + "\",\"initSize\":\"" + user.getInitSize() 56 | + "\",\"code\":"+code+" }"; 57 | output.write(resStr.getBytes()); 58 | output.flush(); 59 | } else { 60 | resStr = "{\"type\":\"false\"}"; 61 | output.write(resStr.getBytes()); 62 | output.flush(); 63 | //如果登陆失败,则终止该线程运行,不让程序进入后面的死循环接收请求 64 | return; 65 | } 66 | } else if (typeInfo.equals("usedSize")) {//获得用户已经使用的内存大小 67 | Long usedSize; 68 | try { 69 | usedSize = dao.getUsedSize(user.getUid()); 70 | String resStr = "{\"type\":\"true\",\"size\":" 71 | + usedSize + "}"; 72 | output.write(resStr.getBytes()); 73 | } catch (Exception e) { 74 | output.write("{\"type\":\"false\"}".getBytes()); 75 | e.printStackTrace(); 76 | } 77 | 78 | output.flush(); 79 | } else if (typeInfo.equals("list")) {//获取目录 80 | //获取did(获取当前所在目录) 81 | long did = reqInfo.getLong("did"); 82 | 83 | //获得did目录下所有文件夹 84 | List directories; 85 | //获得did目录下所有文件 86 | List fileItems; 87 | try { 88 | directories = dao.getDirectories(user.getUid(), did); 89 | fileItems = dao.getFileItems(user.getUid(), did); 90 | HashMap hashMap = new HashMap<>(); 91 | hashMap.put("rdid", did); 92 | hashMap.put("directories", directories); 93 | hashMap.put("fileItems", fileItems); 94 | 95 | JSONObject resObj = JSONObject.fromObject(hashMap); 96 | output.write(resObj.toString().getBytes()); 97 | output.flush(); 98 | 99 | } catch (Exception e) { 100 | //如果发生异常则回一个错误提示 101 | output.write("false".getBytes()); 102 | output.flush(); 103 | e.printStackTrace(); 104 | } 105 | 106 | } else if (typeInfo.equals("mkdir")) {//创建文件夹 107 | //获取当前所在目录的父目录 108 | long rdid = reqInfo.getLong("rdid"); 109 | //获取文件夹名称 110 | String dname = reqInfo.getString("dname"); 111 | Directory dir = new Directory(0L, dname, rdid, user.getUid()); 112 | 113 | //判断在当前目录下是否有同名文件夹 114 | if (dao.isExistName(dir)) { 115 | //将新建的文件夹的父目录设置为传入的rdid 116 | int row = dao.mkDir(dir); 117 | 118 | if (row > 0) { 119 | output.write("{\"type\":\"true\"}".getBytes()); 120 | } else { 121 | output.write( 122 | "{\"type\":\"false\",\"info\":\"创建失败!\"}" 123 | .getBytes()); 124 | } 125 | } else { 126 | //有重名文件 127 | output.write("{\"type\":\"false\",\"info\":\"文件夹已存在!\"}" 128 | .getBytes()); 129 | } 130 | } else if (typeInfo.equals("removeDir")) {//删除文件夹 131 | //获得需要删除的文件夹的did 132 | long did = reqInfo.getLong("did"); 133 | try { 134 | dao.deleteDir(user.getUid(), did); 135 | output.write("{\"type\":\"true\"}".getBytes()); 136 | output.flush(); 137 | } catch (SQLException e) { 138 | output.write("{\"type\":\"false\",\"info\":\"删除失败\"}" 139 | .getBytes()); 140 | output.flush(); 141 | e.printStackTrace(); 142 | } 143 | 144 | } else if (typeInfo.equals("removeFile")) {//删除文件 145 | //获得需要删除的文件的fid 146 | long fid = reqInfo.getLong("fid"); 147 | try { 148 | dao.deleteFileItem(user.getUid(), fid); 149 | output.write("{\"type\":\"true\"}".getBytes()); 150 | output.flush(); 151 | } catch (SQLException e) { 152 | output.write("{\"type\":\"false\",\"info\":\"删除失败\"}" 153 | .getBytes()); 154 | output.flush(); 155 | e.printStackTrace(); 156 | } 157 | } else if (typeInfo.equals("renameDir")) {//重命名文件夹 158 | //获得目标文件夹的did 159 | Long did = reqInfo.getLong("did"); 160 | //获得文件夹的名称 161 | String newName = reqInfo.getString("newName"); 162 | 163 | if (dao.dirNameIsExist(user.getUid(), did, newName)) { 164 | dao.reNameDir(did, newName); 165 | 166 | output.write("{\"type\":\"true\"}".getBytes()); 167 | output.flush(); 168 | } else { 169 | output.write( 170 | "{\"type\":\"false\",\"info\":\"该文件名已存在!\"}" 171 | .getBytes()); 172 | output.flush(); 173 | } 174 | 175 | } else if (typeInfo.equals("renameFile")) {//重命名文件 176 | //获得目标文件的fid 177 | Long fid = reqInfo.getLong("fid"); 178 | //获得文件的名称 179 | String newName = reqInfo.getString("newName"); 180 | 181 | if (dao.fileNameIsExist(user.getUid(), fid, newName)) { 182 | dao.reNameFile(fid, newName); 183 | output.write("{\"type\":\"true\"}".getBytes()); 184 | output.flush(); 185 | } else { 186 | output.write( 187 | "{\"type\":\"false\",\"info\":\"该文件名已存在!\"}" 188 | .getBytes()); 189 | output.flush(); 190 | } 191 | } else if (typeInfo.equals("rePassword")) {//修改密码 192 | String email = reqInfo.getString("email"); 193 | String password = reqInfo.getString("password"); 194 | String rePassword = reqInfo.getString("rePassword"); 195 | 196 | boolean isUpdate = dao.rePassword(email, password, 197 | rePassword); 198 | String resStr = null; 199 | if (isUpdate) { 200 | resStr = "{\"type\":\"true\"}"; 201 | } else { 202 | resStr = "{\"type\":\"false\"}"; 203 | } 204 | output.write(resStr.getBytes()); 205 | output.flush(); 206 | } else if (typeInfo.equals("logout")) {//退出登录 207 | break; 208 | } 209 | 210 | } 211 | } catch (IOException | SQLException e) { 212 | try { 213 | output.write("{\"type\":\"error\",\"info\":\"套接字异常,请关闭客户端重试!\"}".getBytes()); 214 | output.flush(); 215 | } catch (IOException e1) { 216 | // TODO Auto-generated catch block 217 | e1.printStackTrace(); 218 | } 219 | 220 | e.printStackTrace(); 221 | }finally { 222 | try { 223 | socket.close(); 224 | } catch (IOException e1) { 225 | // TODO Auto-generated catch block 226 | e1.printStackTrace(); 227 | } 228 | } 229 | } 230 | 231 | public static void openLoginServer() throws IOException { 232 | ServerSocket serverSocket = new ServerSocket( 233 | ConfigLoader.getLoginPort()); 234 | while (true) { 235 | Socket socket = serverSocket.accept(); 236 | new LoginService(socket).start(); 237 | } 238 | 239 | } 240 | 241 | } 242 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/service/RegistUserService.java: -------------------------------------------------------------------------------- 1 | package com.service; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.OutputStream; 6 | import java.net.ServerSocket; 7 | import java.net.Socket; 8 | import java.sql.SQLException; 9 | import java.util.Collections; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | import java.util.Random; 13 | 14 | import com.dao.RegistDao; 15 | import com.utils.ConfigLoader; 16 | import com.utils.EmailUtils; 17 | 18 | import net.sf.json.JSONObject; 19 | 20 | /** 21 | * 22 | * @author 田 金 东 23 | * 24 | */ 25 | public class RegistUserService extends Thread{ 26 | 27 | private Socket socket; 28 | private RegistDao dao; 29 | private Integer checkCode; 30 | private Map mapping=null; 31 | 32 | public RegistUserService(Socket socket,Map mapping) { 33 | this.mapping=mapping; 34 | this.socket = socket; 35 | this.dao=new RegistDao(); 36 | } 37 | 38 | @Override 39 | public void run() { 40 | InputStream input; 41 | OutputStream output; 42 | try { 43 | input=socket.getInputStream(); 44 | output=socket.getOutputStream(); 45 | byte[] buffer=new byte[2048]; 46 | int len = input.read(buffer); 47 | String infoStr=new String(buffer,0,len); 48 | JSONObject obj = JSONObject.fromObject(infoStr); 49 | String infoType=obj.getString("type"); 50 | //如果为注册请求 51 | if(infoType.trim().equals("reg")) { 52 | String email=obj.getString("email"); 53 | String checkCode = obj.getString("checkCode"); 54 | String password=obj.getString("password"); 55 | 56 | if(email!=null&&checkCode!=null&&password!=null) { 57 | if(checkCode.trim().equals(mapping.get(email))) { 58 | try { 59 | dao.createUser(email, password); 60 | output.write("{\"type\":\"true\"}".getBytes()); 61 | } catch (SQLException e) { 62 | 63 | //数据库操作失败,发送响应(系统异常,注册失败) 64 | output.write("{\"type\":\"false\",\"info\":\"系统异常,注册失败\"}".getBytes()); 65 | output.flush(); 66 | e.printStackTrace(); 67 | } 68 | }else { 69 | //当请求验证码和缓存中不一致时,发送响应(验证码有误,请重新获得验证码) 70 | output.write("{\"type\":\"false\",\"info\":\"验证码有误,请重新获得验证码\"}".getBytes()); 71 | output.flush(); 72 | } 73 | mapping.remove(email); 74 | }else { 75 | //当获取的email,checkCode,password为空时,发送响应(请求失败,请重试) 76 | output.write("{\"type\":\"false\",\"info\":\"请求失败,请重新获得验证码注册\"}".getBytes()); 77 | output.flush(); 78 | } 79 | //获取验证码请求 80 | }else if(infoType.trim().equals("checkCode")) { 81 | String infoEmail = obj.getString("email"); 82 | Random random=new Random(); 83 | Integer checkCode = random.nextInt(100000); 84 | 85 | if(dao.checkEmail(infoEmail)) { 86 | EmailUtils.sendEmail(infoEmail, checkCode.toString()); 87 | //将验证码加入缓存,为了注册请求时验证该验证码 88 | mapping.put(infoEmail, checkCode.toString()); 89 | output.write("\"type\":\"true\"".getBytes()); 90 | output.flush(); 91 | }else { 92 | output.write("{\"type\":\"false\",\"info\":\"该邮箱已经注册!\"}".getBytes()); 93 | } 94 | } 95 | 96 | 97 | } catch (IOException e) { 98 | // TODO Auto-generated catch block 99 | e.printStackTrace(); 100 | } 101 | } 102 | 103 | public static void openRegistService() throws IOException { 104 | ServerSocket serverSocket = new ServerSocket(ConfigLoader.getRegistPort()); 105 | Map mapping=Collections.synchronizedMap(new HashMap()); 106 | while(true) { 107 | Socket accept = serverSocket.accept(); 108 | new RegistUserService(accept,mapping).start(); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/service/StartServer.java: -------------------------------------------------------------------------------- 1 | package com.service; 2 | 3 | import java.io.IOException; 4 | 5 | public class StartServer { 6 | public static void main(String[] args) { 7 | new Thread() { 8 | @Override 9 | public void run() { 10 | try { 11 | LoginService.openLoginServer(); 12 | } catch (IOException e) { 13 | // TODO Auto-generated catch block 14 | e.printStackTrace(); 15 | } 16 | } 17 | 18 | }.start(); 19 | new Thread() { 20 | @Override 21 | public void run() { 22 | try { 23 | RegistUserService.openRegistService(); 24 | } catch (IOException e) { 25 | // TODO Auto-generated catch block 26 | e.printStackTrace(); 27 | } 28 | } 29 | }.start(); 30 | new Thread() { 31 | @Override 32 | public void run() { 33 | try { 34 | DownloadService.openDownloadService(); 35 | } catch (Exception e) { 36 | // TODO Auto-generated catch block 37 | e.printStackTrace(); 38 | } 39 | } 40 | }.start(); 41 | new Thread() { 42 | @Override 43 | public void run() { 44 | try { 45 | UploadService.openUploadService(); 46 | } catch (Exception e) { 47 | // TODO Auto-generated catch block 48 | e.printStackTrace(); 49 | } 50 | } 51 | 52 | }.start(); 53 | System.out.println("服务器启动成功"); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/service/UploadService.java: -------------------------------------------------------------------------------- 1 | package com.service; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.io.OutputStream; 8 | import java.net.ServerSocket; 9 | import java.net.Socket; 10 | import java.sql.SQLException; 11 | 12 | import com.dao.LoginDao; 13 | import com.dao.UploadDao; 14 | import com.utils.ConfigLoader; 15 | 16 | import net.sf.json.JSONObject; 17 | 18 | public class UploadService extends Thread{ 19 | 20 | private Socket socket=null; 21 | public UploadService(Socket socket) { 22 | this.socket=socket; 23 | } 24 | 25 | public void run() { 26 | //{"filesize":"","filename":"","filemd5":"","did":"","code":"","uid":""} 27 | InputStream input=null; 28 | OutputStream output=null; 29 | LoginDao loginDao=new LoginDao(); 30 | UploadDao uploadDao=new UploadDao(); 31 | try { 32 | input=socket.getInputStream(); 33 | output=socket.getOutputStream(); 34 | byte[] buffer=new byte[2048]; 35 | int length=input.read(buffer); 36 | String jsonStr=new String(buffer,0,length); 37 | JSONObject json = JSONObject.fromObject(jsonStr); 38 | 39 | Long fileSize =json.getLong("filesize"); 40 | String code = json.getString("code"); 41 | Long did=json.getLong("did"); 42 | String filemd5=json.getString("filemd5"); 43 | String filename=json.getString("filename"); 44 | Long uid=json.getLong("uid"); 45 | 46 | //如果该用户没有登录,则关闭该线程 47 | if(!UserOnline.isUserOnline(code, uid)) { 48 | return; 49 | } 50 | 51 | Long usedSize=loginDao.getUsedSize(uid); 52 | Long initSize=loginDao.getInitSize(uid); 53 | 54 | if(usedSize+fileSize<=initSize) { 55 | //向数据库插入用户的文件数据 56 | uploadDao.regUserFile(filename, uid, did, fileSize, filemd5); 57 | if(uploadDao.isExistFile(filemd5)) { 58 | //服务器中已经存在该文件,相应客户端“秒传” 59 | output.write("{\"type\":\"mc\"}".getBytes()); 60 | output.flush(); 61 | }else { 62 | output.write("{\"type\":\"pleaseUpload\"}".getBytes()); 63 | output.flush(); 64 | File filePath=new File(ConfigLoader.getFilePath(),filemd5); 65 | FileOutputStream fileOutput=new FileOutputStream(filePath); 66 | 67 | buffer=new byte[1024*1024]; 68 | long size=0l; 69 | while((length = input.read(buffer))>0) { 70 | fileOutput.write(buffer, 0, length); 71 | size+=length; 72 | if(size>=fileSize) { 73 | break; 74 | } 75 | } 76 | fileOutput.close(); 77 | //将新上传的文件信息 注册数据库 78 | uploadDao.regSystemFile(filemd5, fileSize, filePath.getPath(), uid); 79 | output.write("{\"type\":\"success\"}".getBytes()); 80 | output.flush(); 81 | } 82 | 83 | }else { 84 | output.write("{\"type\":\"overSize\"}".getBytes()); 85 | } 86 | 87 | } catch (IOException e) { 88 | // TODO Auto-generated catch block 89 | e.printStackTrace(); 90 | } catch (SQLException e) { 91 | // TODO Auto-generated catch block 92 | e.printStackTrace(); 93 | }finally { 94 | try { 95 | input.close(); 96 | } catch (IOException e) { 97 | // TODO Auto-generated catch block 98 | e.printStackTrace(); 99 | } 100 | try { 101 | output.close(); 102 | } catch (IOException e) { 103 | // TODO Auto-generated catch block 104 | e.printStackTrace(); 105 | } 106 | try { 107 | socket.close(); 108 | } catch (IOException e) { 109 | // TODO Auto-generated catch block 110 | e.printStackTrace(); 111 | } 112 | } 113 | 114 | } 115 | 116 | public static void openUploadService() throws Exception{ 117 | ServerSocket serverSocket = new ServerSocket(ConfigLoader.getUploadtPort()); 118 | while(true) { 119 | Socket socket = serverSocket.accept(); 120 | new UploadService(socket).start(); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/service/UserOnline.java: -------------------------------------------------------------------------------- 1 | package com.service; 2 | 3 | import java.util.HashMap; 4 | 5 | public class UserOnline { 6 | private static HashMap map=new HashMap<>(); 7 | 8 | /** 9 | * 10 | * @param code 客户端登录时,服务器生成的串码,在登录时注册 11 | * @param uid 该串码对应用户的uid 12 | */ 13 | public static void regUserOnline(String code,Long uid) { 14 | synchronized (map) { 15 | map.put(code, uid); 16 | } 17 | } 18 | 19 | public static boolean isUserOnline(String code,Long uid) { 20 | Long id = map.get(code); 21 | if(id!=null&&id==uid) { 22 | return true; 23 | } 24 | return false; 25 | } 26 | 27 | public static Long getOnlineUid(String code) { 28 | 29 | return map.get(code); 30 | } 31 | 32 | public static void logout(String code) { 33 | map.remove(code); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/test/HelloTest.java: -------------------------------------------------------------------------------- 1 | package com.test; 2 | 3 | import java.util.Random; 4 | 5 | import org.junit.Test; 6 | 7 | public class HelloTest { 8 | @Test 9 | public void test() { 10 | Random random = new Random(); 11 | int string = random.nextInt(100000); 12 | System.out.println(string); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/utils/C3P0Utils.java: -------------------------------------------------------------------------------- 1 | package com.utils; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | 6 | import javax.sql.DataSource; 7 | 8 | import com.mchange.v2.c3p0.ComboPooledDataSource; 9 | 10 | public class C3P0Utils { 11 | private static DataSource dataSource; 12 | static { 13 | //在new这个对象时,底层会自动找到c3po-config.xml的配置文件 14 | dataSource=new ComboPooledDataSource(); 15 | } 16 | public static DataSource getDataSource() { 17 | return dataSource; 18 | } 19 | public static Connection getConnection() { 20 | try { 21 | return dataSource.getConnection(); 22 | } catch (SQLException e) { 23 | throw new RuntimeException(e); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /NetDistk_Server/src/com/utils/ConfigLoader.java: -------------------------------------------------------------------------------- 1 | package com.utils; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.util.Properties; 7 | 8 | import org.junit.Test; 9 | 10 | public class ConfigLoader { 11 | private static Properties properties=null; 12 | private static Integer registPort; 13 | private static Integer loginPort; 14 | private static Integer uploadtPort; 15 | private static Integer downloadPort; 16 | private static String filePath; 17 | static { 18 | properties=new Properties(); 19 | try { 20 | properties.load(new FileInputStream(new File("src/config.properties"))); 21 | } catch (IOException e) { 22 | // TODO Auto-generated catch block 23 | e.printStackTrace(); 24 | } 25 | registPort = Integer.valueOf(properties.getProperty("server_regist_port")); 26 | loginPort = Integer.valueOf(properties.getProperty("server_login_port")); 27 | uploadtPort=Integer.valueOf(properties.getProperty("server_upload_port")); 28 | downloadPort=Integer.valueOf(properties.getProperty("server_download_port")); 29 | filePath=properties.getProperty("file_path"); 30 | } 31 | public static Integer getRegistPort() { 32 | return registPort; 33 | } 34 | 35 | public static Integer getLoginPort() { 36 | return loginPort; 37 | } 38 | 39 | 40 | public static Integer getUploadtPort() { 41 | return uploadtPort; 42 | } 43 | 44 | public static Integer getDownloadPort() { 45 | return downloadPort; 46 | } 47 | public static String getFilePath() { 48 | return filePath; 49 | } 50 | 51 | @Test 52 | public void test() { 53 | System.out.println(ConfigLoader.getUploadtPort()); 54 | System.out.println(ConfigLoader.getRegistPort()); 55 | System.out.println(ConfigLoader.getLoginPort()); 56 | System.out.println(ConfigLoader.getFilePath()); 57 | 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/utils/EmailUtils.java: -------------------------------------------------------------------------------- 1 | package com.utils; 2 | import org.apache.commons.mail.HtmlEmail; 3 | 4 | public class EmailUtils { 5 | 6 | public static void sendEmail(String emailaddress, String code) { 7 | 8 | try { 9 | HtmlEmail email = new HtmlEmail(); 10 | email.setHostName("smtp.126.com"); 11 | email.setCharset("UTF-8"); 12 | email.addTo(emailaddress);// 收件地址 13 | 14 | email.setFrom("tianjindong98@126.com", "菜鸟网盘注册验证码"); 15 | 16 | //第一个参数填邮箱、第二个参数填密码 17 | email.setAuthentication("xxxxx@126.com", "123456"); 18 | 19 | email.setSubject("菜鸟网盘注册验证码"); 20 | email.setMsg("验证码是:" + code+"\n\n请勿将验证码透露给第三方!"); 21 | email.send(); 22 | } catch (Exception e) { 23 | e.printStackTrace(); 24 | 25 | } 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /NetDistk_Server/src/com/utils/MD5FileUtil.java: -------------------------------------------------------------------------------- 1 | package com.utils; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.nio.MappedByteBuffer; 7 | import java.nio.channels.FileChannel; 8 | import java.security.MessageDigest; 9 | import java.security.NoSuchAlgorithmException; 10 | 11 | public class MD5FileUtil { 12 | 13 | protected static char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 14 | 'f' }; 15 | protected static MessageDigest messagedigest = null; 16 | 17 | static { 18 | try { 19 | messagedigest = MessageDigest.getInstance("MD5"); 20 | } catch (NoSuchAlgorithmException e) { 21 | } 22 | } 23 | 24 | public static String getFileMD5String(File file) throws IOException { 25 | FileInputStream in = new FileInputStream(file); 26 | FileChannel ch = in.getChannel(); 27 | MappedByteBuffer byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, 0, file.length()); 28 | messagedigest.update(byteBuffer); 29 | return bufferToHex(messagedigest.digest()); 30 | } 31 | 32 | public static String getMD5String(String s) { 33 | return getMD5String(s.getBytes()); 34 | } 35 | 36 | public static String getMD5String(byte[] bytes) { 37 | messagedigest.update(bytes); 38 | return bufferToHex(messagedigest.digest()); 39 | } 40 | 41 | private static String bufferToHex(byte bytes[]) { 42 | return bufferToHex(bytes, 0, bytes.length); 43 | } 44 | 45 | private static String bufferToHex(byte bytes[], int m, int n) { 46 | StringBuffer stringbuffer = new StringBuffer(2 * n); 47 | int k = m + n; 48 | for (int l = m; l < k; l++) { 49 | appendHexPair(bytes[l], stringbuffer); 50 | } 51 | return stringbuffer.toString(); 52 | } 53 | 54 | private static void appendHexPair(byte bt, StringBuffer stringbuffer) { 55 | char c0 = hexDigits[(bt & 0xf0) >> 4]; 56 | char c1 = hexDigits[bt & 0xf]; 57 | stringbuffer.append(c0); 58 | stringbuffer.append(c1); 59 | } 60 | 61 | public static boolean checkPassword(String password, String md5PwdStr) { 62 | String s = getMD5String(password); 63 | return s.equals(md5PwdStr); 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /NetDistk_Server/src/commons-beanutils-1.8.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/src/commons-beanutils-1.8.3.jar -------------------------------------------------------------------------------- /NetDistk_Server/src/commons-collections-3.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/src/commons-collections-3.2.1.jar -------------------------------------------------------------------------------- /NetDistk_Server/src/commons-dbutils-1.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/src/commons-dbutils-1.7.jar -------------------------------------------------------------------------------- /NetDistk_Server/src/commons-email-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/src/commons-email-1.4.jar -------------------------------------------------------------------------------- /NetDistk_Server/src/commons-lang-2.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/src/commons-lang-2.6.jar -------------------------------------------------------------------------------- /NetDistk_Server/src/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/src/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /NetDistk_Server/src/config.properties: -------------------------------------------------------------------------------- 1 | #配置服务器IP 2 | server_regist_port:5681 3 | server_login_port:5682 4 | server_upload_port:5683 5 | server_download_port:5684 6 | file_path:E:/NetDisk 7 | 8 | -------------------------------------------------------------------------------- /NetDistk_Server/src/ezmorph-1.0.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/src/ezmorph-1.0.6.jar -------------------------------------------------------------------------------- /NetDistk_Server/src/json-lib-2.4-jdk15.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/src/json-lib-2.4-jdk15.jar -------------------------------------------------------------------------------- /NetDistk_Server/src/mail.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/src/mail.jar -------------------------------------------------------------------------------- /NetDistk_Server/src/mailapi.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/src/mailapi.jar -------------------------------------------------------------------------------- /NetDistk_Server/src/mysql-connector-java-5.1.44-bin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/NetDistk_Server/src/mysql-connector-java-5.1.44-bin.jar -------------------------------------------------------------------------------- /NetDistk_Server/src/test/HelloTest.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import java.sql.Connection; 4 | 5 | import javax.mail.MessagingException; 6 | 7 | import org.junit.Test; 8 | 9 | import com.utils.EmailUtils; 10 | 11 | 12 | public class HelloTest { 13 | @Test 14 | public void test() { 15 | //Connection connection = C3P0Utils.getConnection(); 16 | try { 17 | EmailUtils.sendEmail("1804972747@qq.com", "41525465"); 18 | System.out.println("dassdas"); 19 | } catch (Exception e) { 20 | // TODO Auto-generated catch block 21 | e.printStackTrace(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NetDisk 2 | 这是一个Java SE网盘项目 3 | 网盘特点: 4 | 1. 实现了网盘的秒传功能,若当前用户上传的文件已经被其他用户上传过了,那么就不会重新上传,实现秒传的效果。 5 | 2. 网盘实现了多级目录、目录切换、目录回退、新建文件夹、重命名、删除、上传、下载(待开发)等基本的文件操作。 6 | 7 | 8 | ![](./演示图片/1.jpg) 9 | 10 | ![](./演示图片/2.jpg) 11 | 12 | ![](./演示图片/3.jpg) 13 | 14 | ![](./演示图片/4.jpg) 15 | 16 | ![](./演示图片/5.jpg) 17 | 18 | ![](./演示图片/6.jpg) -------------------------------------------------------------------------------- /netdisk.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : TJDMySQL 5 | Source Server Version : 50638 6 | Source Host : localhost:3306 7 | Source Database : netdisk 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50638 11 | File Encoding : 65001 12 | 13 | Date: 2018-10-13 08:45:25 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for sys_file_items 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `sys_file_items`; 22 | CREATE TABLE `sys_file_items` ( 23 | `file_md5` varchar(255) NOT NULL, 24 | `file_size` decimal(15,0) NOT NULL, 25 | `file_path` varchar(255) NOT NULL, 26 | `upload_time` datetime DEFAULT NULL, 27 | `uid_first` varchar(255) DEFAULT NULL, 28 | PRIMARY KEY (`file_md5`) 29 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 30 | 31 | -- ---------------------------- 32 | -- Table structure for user 33 | -- ---------------------------- 34 | DROP TABLE IF EXISTS `user`; 35 | CREATE TABLE `user` ( 36 | `uid` bigint(100) NOT NULL AUTO_INCREMENT, 37 | `user_email` varchar(255) NOT NULL, 38 | `user_password` varchar(255) NOT NULL, 39 | `user_size` bigint(15) NOT NULL, 40 | PRIMARY KEY (`uid`) 41 | ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; 42 | 43 | -- ---------------------------- 44 | -- Table structure for user_file_drictory 45 | -- ---------------------------- 46 | DROP TABLE IF EXISTS `user_file_drictory`; 47 | CREATE TABLE `user_file_drictory` ( 48 | `did` bigint(100) NOT NULL AUTO_INCREMENT, 49 | `dname` varchar(255) NOT NULL, 50 | `rdid` bigint(100) NOT NULL, 51 | `uid` bigint(255) NOT NULL, 52 | PRIMARY KEY (`did`), 53 | KEY `user_file_directory_uid` (`uid`), 54 | KEY `user_file_directory_rdid` (`rdid`), 55 | CONSTRAINT `user_file_directory_rdid` FOREIGN KEY (`rdid`) REFERENCES `user_file_drictory` (`did`) ON DELETE CASCADE, 56 | CONSTRAINT `user_file_directory_uid` FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) 57 | ) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8; 58 | 59 | -- ---------------------------- 60 | -- Table structure for user_file_items 61 | -- ---------------------------- 62 | DROP TABLE IF EXISTS `user_file_items`; 63 | CREATE TABLE `user_file_items` ( 64 | `fid` bigint(255) NOT NULL AUTO_INCREMENT, 65 | `fname` varchar(255) NOT NULL, 66 | `upload_time` datetime DEFAULT NULL, 67 | `did` bigint(100) NOT NULL, 68 | `uid` bigint(100) NOT NULL, 69 | `file_size` decimal(15,0) NOT NULL, 70 | `file_md5` varchar(255) NOT NULL, 71 | PRIMARY KEY (`fid`), 72 | KEY `user_file_items_md5` (`file_md5`), 73 | KEY `user_file_items_foreign` (`did`), 74 | CONSTRAINT `user_file_items_foreign` FOREIGN KEY (`did`) REFERENCES `user_file_drictory` (`did`) ON DELETE CASCADE 75 | ) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=utf8; 76 | -------------------------------------------------------------------------------- /演示图片/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/演示图片/1.jpg -------------------------------------------------------------------------------- /演示图片/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/演示图片/2.jpg -------------------------------------------------------------------------------- /演示图片/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/演示图片/3.jpg -------------------------------------------------------------------------------- /演示图片/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/演示图片/4.jpg -------------------------------------------------------------------------------- /演示图片/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/演示图片/5.jpg -------------------------------------------------------------------------------- /演示图片/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigcoder84/NetDisk/dc28766a2b82cb68a7bfcb71117330a6e1e00625/演示图片/6.jpg --------------------------------------------------------------------------------