-
Notifications
You must be signed in to change notification settings - Fork 0
Hw4.FTO_GUI #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ilkivoo
wants to merge
2
commits into
master
Choose a base branch
from
hw4
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Hw4.FTO_GUI #7
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| language: java | ||
| jdk: | ||
| - oraclejdk8 | ||
| os: | ||
| - linux | ||
| script: | ||
| - chmod +x buildscript.sh && ./buildscript.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>04</groupId> | ||
| <artifactId>FTP_GUI</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <configuration> | ||
| <source>1.8</source> | ||
| <target>1.8</target> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>4.12</version> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
|
|
||
| </project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package ru.spbau.mit.alyokhina; | ||
|
|
||
| import javafx.application.Application; | ||
| import javafx.geometry.Pos; | ||
| import javafx.scene.Scene; | ||
| import javafx.scene.layout.GridPane; | ||
| import javafx.stage.Stage; | ||
| import ru.spbau.mit.alyokhina.ui.*; | ||
|
|
||
| public class Main extends Application { | ||
|
|
||
| @Override | ||
| public void start(Stage primaryStage) throws Exception { | ||
| primaryStage.setTitle("Крестики - Нолики"); | ||
| GridPane gridPane = new GridPane(); | ||
| gridPane.setAlignment(Pos.CENTER); | ||
| CreateNewElements.createMainActivity(gridPane); | ||
| primaryStage.setScene(new Scene(gridPane, 600, 400)); | ||
| primaryStage.show(); | ||
|
|
||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| launch(args); | ||
| } | ||
| } | ||
99 changes: 99 additions & 0 deletions
99
04.FTP_GUI/src/main/java/ru/spbau/mit/alyokhina/client/Client.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package ru.spbau.mit.alyokhina.client; | ||
|
|
||
| import javafx.util.Pair; | ||
| import ru.spbau.mit.alyokhina.server.Server; | ||
|
|
||
|
|
||
| import java.io.*; | ||
| import java.net.Socket; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Client, which allows you to execute the requests list and get | ||
| */ | ||
| public class Client { | ||
| /** | ||
| * OutputStream from Socket | ||
| */ | ||
| private DataOutputStream dataOutputStream; | ||
| /** | ||
| * InputStream from Socket | ||
| */ | ||
| private DataInputStream dataInputStream; | ||
|
|
||
| /** | ||
| * Constructor | ||
| * | ||
| * @throws IOException if Socket or Stream can't be created | ||
| */ | ||
| public Client(String host, int port) throws IOException { | ||
| Socket clientSocket = new Socket(host, port); | ||
| dataInputStream = new DataInputStream(clientSocket.getInputStream()); | ||
| dataOutputStream = new DataOutputStream(clientSocket.getOutputStream()); | ||
|
|
||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Listing files in the directory on the server | ||
| * | ||
| * @param path directory path | ||
| * @return list of Pair. Fist value - name of file. Second value - type of file ( if file is directory - true, else false) | ||
| * Count files in directory = length of list | ||
| * @throws IOException if we can't read/write in InputStream/OutputStream | ||
| */ | ||
| public List<Pair<String, Boolean>> list(String path) throws IOException { | ||
| List<Pair<String, Boolean>> listFiles = new ArrayList<>(); | ||
| dataOutputStream.writeInt(Server.LIST_REQUEST); | ||
| dataOutputStream.writeUTF(path); | ||
| dataOutputStream.flush(); | ||
| int count = dataInputStream.readInt(); | ||
| for (int i = 0; i < count; i++) { | ||
| String fileName = dataInputStream.readUTF(); | ||
| Boolean isDirectory = dataInputStream.readBoolean(); | ||
| listFiles.add(new Pair<>(fileName, isDirectory)); | ||
| } | ||
| return listFiles; | ||
| } | ||
|
|
||
| /** | ||
| * Сopy the file from the server to the file | ||
| * | ||
| * @param path path of the file from server | ||
| * @param nameFileForSave the name of the file into which the content will be copied | ||
| * @return file into which the content will be copied | ||
| * @throws IOException if we can't read/write in InputStream/OutputStream | ||
| */ | ||
| public File get(String path, String nameFileForSave) throws IOException { | ||
| dataOutputStream.writeInt(Server.GET_REQUEST); | ||
| dataOutputStream.writeUTF(path); | ||
| dataOutputStream.flush(); | ||
| File fileForSave = new File(nameFileForSave); | ||
| int count = dataInputStream.readInt(); | ||
| if (count != 0) { | ||
| byte[] bytes = new byte[count]; | ||
| int countReadBytes = dataInputStream.read(bytes); | ||
| if (countReadBytes != count) { | ||
| throw new IOException("Impossible to read all data"); | ||
| } | ||
| DataOutputStream dataOutputStreamForSave = new DataOutputStream(new FileOutputStream(fileForSave)); | ||
| dataOutputStreamForSave.write(bytes); | ||
| } | ||
| return fileForSave; | ||
| } | ||
|
|
||
| /** | ||
| * check file in server for existence | ||
| * | ||
| * @param path path of the file, that we want to check | ||
| * @return true - is exists, false - else | ||
| * @throws IOException if we can't write in dataOutputStream | ||
| */ | ||
| public boolean isExists(String path) throws IOException { | ||
| dataOutputStream.writeInt(Server.IS_EXISTS_REQUEST); | ||
| dataOutputStream.writeUTF(path); | ||
| dataOutputStream.flush(); | ||
| return dataInputStream.readBoolean(); | ||
| } | ||
| } |
131 changes: 131 additions & 0 deletions
131
04.FTP_GUI/src/main/java/ru/spbau/mit/alyokhina/server/Server.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| package ru.spbau.mit.alyokhina.server; | ||
|
|
||
| import java.io.*; | ||
| import java.net.ServerSocket; | ||
| import java.net.Socket; | ||
|
|
||
| /** | ||
| * A server that processes two list requests and receives | ||
| */ | ||
| public class Server { | ||
| /** | ||
| * Value for request list | ||
| */ | ||
| public static int LIST_REQUEST = 1; | ||
| /** | ||
| * Value for request get | ||
| */ | ||
| public static int GET_REQUEST = 2; | ||
| /** | ||
| * Value for request is exist file | ||
| */ | ||
| public static int IS_EXISTS_REQUEST = 3; | ||
| /** | ||
| * Socket for connection with this server | ||
| */ | ||
| private ServerSocket serverSocket; | ||
|
|
||
| /** | ||
| * Constructor | ||
| * | ||
| * @param port port of connection | ||
| * @throws IOException if Socket can't be created | ||
| */ | ||
| public Server(int port) throws IOException { | ||
| serverSocket = new ServerSocket(port); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Start of the server | ||
| */ | ||
| public void start() { | ||
| while (true) { | ||
| try { | ||
| final Socket socket = serverSocket.accept(); | ||
| Thread thread = new Thread(() -> { | ||
| try (DataInputStream dataInputStream = new DataInputStream(socket.getInputStream()); | ||
| DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream())) { | ||
| while (!Thread.interrupted()) { | ||
| int requestType = dataInputStream.readInt(); | ||
| String path = dataInputStream.readUTF(); | ||
| if (requestType == LIST_REQUEST) { | ||
| list(path, dataOutputStream); | ||
| } else if (requestType == GET_REQUEST) { | ||
| get(path, dataOutputStream); | ||
| } else if (requestType == IS_EXISTS_REQUEST) { | ||
| isExist(path, dataOutputStream); | ||
| } | ||
| } | ||
| } catch (IOException e) { | ||
| System.out.println(e.getMessage()); | ||
| } | ||
| }); | ||
| thread.start(); | ||
| } catch (IOException ignored) { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Write count files, names of files and their types from input directory to dataOutputStream | ||
| * | ||
| * @param path directory path | ||
| * @param dataOutputStream stream for write result | ||
| * @throws IOException if it is impossible to write in dataOutputStream | ||
| */ | ||
| private void list(String path, DataOutputStream dataOutputStream) throws IOException { | ||
| File directory = new File(path); | ||
| File[] files = directory.listFiles(); | ||
| dataOutputStream.writeInt(files == null ? 0 : files.length); | ||
| if (files != null) { | ||
| for (File file : files) { | ||
| dataOutputStream.writeUTF(file.getName()); | ||
| dataOutputStream.writeBoolean(file.isDirectory()); | ||
| } | ||
| } | ||
| dataOutputStream.flush(); | ||
| } | ||
|
|
||
| /** | ||
| * Write file contents in dataOutputStream | ||
| * | ||
| * @param path name of file | ||
| * @param dataOutputStream OutputStream for write result | ||
| * @throws IOException if it is impossible to write in dataOutputStream | ||
| */ | ||
| private void get(String path, DataOutputStream dataOutputStream) throws IOException { | ||
| File file = new File(path); | ||
| int length = (int) file.length(); | ||
| if (length != 0) { | ||
| DataInputStream dataInputStreamForRequest = new DataInputStream(new FileInputStream(file)); | ||
| byte[] bytes = new byte[length]; | ||
|
|
||
| if (dataInputStreamForRequest.read(bytes) == length) { | ||
| dataOutputStream.writeInt(length); | ||
| dataOutputStream.write(bytes); | ||
| } else { | ||
| throw new IOException("Impossible to read all data"); | ||
| } | ||
| dataInputStreamForRequest.close(); | ||
| } else { | ||
| dataOutputStream.writeInt(length); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * check file for existence | ||
| * | ||
| * @param path path of the file, that we want to check | ||
| * @throws IOException if we can't write in dataOutputStream or create | ||
| */ | ||
| private void isExist(String path, DataOutputStream dataOutputStream) throws IOException { | ||
| File file = new File(path); | ||
| dataOutputStream.writeBoolean(file.exists()); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)