This is an extremely simple java server using only java.net.* package to run a local file explorer system which is similar to what most package manager sites use such as http://central.maven.org/
- JDK1.8
- Gradle 3.5+
Run the app using
gradle run
- Via generated jar
- Run
gradle clean build jar
- cd to build/libs/
- run
java -jar fileServer-1.0-SNAPSHOT.jar "{optional: path to directory}"
- i.e.
java -jar fileServer-1.0-SNAPSHOT.jar
-> will use current directory - i.e.
java -jar fileServer-1.0-SNAPSHOT.jar "c:/"
-> will explore the C drive
- i.e.
- Via gradle
gradle run -Pargs="{path to directory}"
- i.e.
gradle run -Pargs="c:/"
- i.e.
You can Change SOCKET_PORT inside FileServerApp
Default is set to 3222
You will notice I used interfaces for everything even for something as simple as FileDownloader. This mainly a practice that I always do to hide the implementation and also testing purposes. You can always go and change the implementation without worrying about the side effects.
HttpFileServer#doRun(): Runs a simple HTTP server using HTTP1.1 spec. When a request is received it will validated it and then checks if it's a;
- Directory?
- Use DisplayService.java implementation to draw HTML table of the requested directory
- File?
- Use FileDownloaderService.java implementation to download the file
- Invalid request
- Return an error page
- Sorting
- Socket Number as a program argument (Currently it's hardcoded)
- Not hiding the program's jar from the explorer!
- Threading
- Use log4j or any logging library
Visit my personal website: sinanaumarah.com