Optimisation légère du code + correction orthographe
This commit is contained in:
parent
33a3db930e
commit
88fe097c01
@ -10,13 +10,13 @@ import lightcontainer.protocol.ProtocolWriter;
|
|||||||
public class Task {
|
public class Task {
|
||||||
// Variables
|
// Variables
|
||||||
private TaskStatus status;
|
private TaskStatus status;
|
||||||
private ProtocolWriter.ProtocolResult command;
|
private final ProtocolWriter.ProtocolResult command;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Défini le context courrant dans laquelle la tâche opère
|
* Défini le context courant dans laquelle la tâche opère
|
||||||
*/
|
*/
|
||||||
private Context context;
|
private final Context context;
|
||||||
|
|
||||||
public Task(Context context, TaskStatus status, ProtocolWriter.ProtocolResult command) {
|
public Task(Context context, TaskStatus status, ProtocolWriter.ProtocolResult command) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@ -26,17 +26,18 @@ public class Task {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de créer une instance de la class {@link Task}
|
* Permet de créer une instance de la class {@link Task}
|
||||||
|
*
|
||||||
* @param context Context à utiliser pour cette tâche
|
* @param context Context à utiliser pour cette tâche
|
||||||
* @param command Commande à exécuter
|
* @param command Commande à exécuter
|
||||||
* @return L'instance de la tâche créée
|
* @return L'instance de la tâche créée
|
||||||
*/
|
*/
|
||||||
public static Task newInstance(Context context, ProtocolWriter.ProtocolResult command) {
|
public static Task newInstance(Context context, ProtocolWriter.ProtocolResult command) {
|
||||||
Task task = new Task(context, TaskStatus.PENDING, command);
|
return new Task(context, TaskStatus.PENDING, command);
|
||||||
return task;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de savoir si la réponse est destinée au client
|
* Permet de savoir si la réponse est destinée au client
|
||||||
|
*
|
||||||
* @param storeDomain Nom du store back end fournissant la réponse.
|
* @param storeDomain Nom du store back end fournissant la réponse.
|
||||||
* @return TRUE si le client doit recevoir cette réponse.
|
* @return TRUE si le client doit recevoir cette réponse.
|
||||||
*/
|
*/
|
||||||
@ -46,6 +47,7 @@ public class Task {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de récupérer le login du client associé à la tâche
|
* Permet de récupérer le login du client associé à la tâche
|
||||||
|
*
|
||||||
* @return Login du client
|
* @return Login du client
|
||||||
*/
|
*/
|
||||||
public String getClient() {
|
public String getClient() {
|
||||||
@ -54,6 +56,7 @@ public class Task {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de récupérer la commande à executer
|
* Permet de récupérer la commande à executer
|
||||||
|
*
|
||||||
* @return Commande à exécuter
|
* @return Commande à exécuter
|
||||||
*/
|
*/
|
||||||
public ProtocolWriter.ProtocolResult getCommand() {
|
public ProtocolWriter.ProtocolResult getCommand() {
|
||||||
@ -62,6 +65,7 @@ public class Task {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de définir le StorBackEnd à utiliser pour cette tâche
|
* Permet de définir le StorBackEnd à utiliser pour cette tâche
|
||||||
|
*
|
||||||
* @param storeDomain Le StorBackEnd à utiliser
|
* @param storeDomain Le StorBackEnd à utiliser
|
||||||
*/
|
*/
|
||||||
public void setDomain(String storeDomain) {
|
public void setDomain(String storeDomain) {
|
||||||
|
@ -29,12 +29,12 @@ import java.nio.charset.StandardCharsets;
|
|||||||
*/
|
*/
|
||||||
public class ClientHandler implements Runnable, AutoCloseable {
|
public class ClientHandler implements Runnable, AutoCloseable {
|
||||||
// Variables
|
// Variables
|
||||||
private ClientHandlerFFE fileFrontEnd;
|
private final ClientHandlerFFE fileFrontEnd;
|
||||||
private final Socket client;
|
private final Socket client;
|
||||||
private ProtocolRepository protocolRep;
|
private final ProtocolRepository protocolRep;
|
||||||
private Context context;
|
private final Context context;
|
||||||
private boolean client_run;
|
private boolean client_run;
|
||||||
private UnicastCHR repository;
|
private final UnicastCHR repository;
|
||||||
|
|
||||||
|
|
||||||
private BufferedReader reader;
|
private BufferedReader reader;
|
||||||
|
@ -107,7 +107,7 @@ public class Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet d'ajouter des données pour la requête courrante
|
* Permet d'ajouter des données pour la requête courante
|
||||||
*
|
*
|
||||||
* @param key La clé permettant de retrouver la valeur
|
* @param key La clé permettant de retrouver la valeur
|
||||||
* @param value La valeur associée à la clé
|
* @param value La valeur associée à la clé
|
||||||
@ -117,7 +117,7 @@ public class Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet d'ajouter des données pour la requête courrante
|
* Permet d'ajouter des données pour la requête courante
|
||||||
*
|
*
|
||||||
* @param key La clé permettant de retrouver la valeur
|
* @param key La clé permettant de retrouver la valeur
|
||||||
* @param value La valeur associée à la clé
|
* @param value La valeur associée à la clé
|
||||||
@ -127,7 +127,7 @@ public class Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de récupérer des données pour la requête courrante
|
* Permet de récupérer des données pour la requête courante
|
||||||
*
|
*
|
||||||
* @param key La clé permettant de retrouver la valeur
|
* @param key La clé permettant de retrouver la valeur
|
||||||
* @return La valeur associée à la clé ou null
|
* @return La valeur associée à la clé ou null
|
||||||
@ -137,7 +137,7 @@ public class Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de récupérer des données pour la requête courrante
|
* Permet de récupérer des données pour la requête courante
|
||||||
*
|
*
|
||||||
* @param key La clé permettant de retrouver la valeur
|
* @param key La clé permettant de retrouver la valeur
|
||||||
* @return La valeur associée à la clé
|
* @return La valeur associée à la clé
|
||||||
|
@ -5,12 +5,13 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class RequestBundle {
|
public class RequestBundle {
|
||||||
|
|
||||||
private Map<String, String> stringData = new HashMap<>();
|
private final Map<String, String> stringData = new HashMap<>();
|
||||||
|
|
||||||
private Map<String, Integer> intData = new HashMap<>();
|
private final Map<String, Integer> intData = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet d'ajouter des String
|
* Permet d'ajouter des String
|
||||||
|
*
|
||||||
* @param key La clé permettant de retrouver la valeur
|
* @param key La clé permettant de retrouver la valeur
|
||||||
* @param value La valeur associée à la clé
|
* @param value La valeur associée à la clé
|
||||||
*/
|
*/
|
||||||
@ -20,6 +21,7 @@ public class RequestBundle {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet d'ajouter des int
|
* Permet d'ajouter des int
|
||||||
|
*
|
||||||
* @param key La clé permettant de retrouver la valeur
|
* @param key La clé permettant de retrouver la valeur
|
||||||
* @param value La valeur associée à la clé
|
* @param value La valeur associée à la clé
|
||||||
*/
|
*/
|
||||||
@ -29,6 +31,7 @@ public class RequestBundle {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de récupérer des données string
|
* Permet de récupérer des données string
|
||||||
|
*
|
||||||
* @param key La clé permettant de retrouver la valeur
|
* @param key La clé permettant de retrouver la valeur
|
||||||
* @return La valeur associée à la clé ou null
|
* @return La valeur associée à la clé ou null
|
||||||
*/
|
*/
|
||||||
@ -38,6 +41,7 @@ public class RequestBundle {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de récupérer des données int
|
* Permet de récupérer des données int
|
||||||
|
*
|
||||||
* @param key La clé permettant de retrouver la valeur
|
* @param key La clé permettant de retrouver la valeur
|
||||||
* @return La valeur associée à la clé
|
* @return La valeur associée à la clé
|
||||||
*/
|
*/
|
||||||
|
@ -8,23 +8,21 @@ import lightcontainer.protocol.ProtocolWriter;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StoreProcessor
|
* StoreProcessor
|
||||||
*
|
* <p>
|
||||||
* <!> MULTICAST CLIENT <!>
|
* <!> MULTICAST CLIENT <!>
|
||||||
* Class communicating with the storebackend and
|
* Class communicating with the storebackend and
|
||||||
* processing the tasks in the FileFrontEnd
|
* processing the tasks in the FileFrontEnd
|
||||||
*
|
*
|
||||||
|
* @author Jérémi NIHART <j.nihart@student.helmo.be>
|
||||||
* @version 1.1
|
* @version 1.1
|
||||||
* @since 1.0
|
|
||||||
*
|
|
||||||
* @see Runnable
|
* @see Runnable
|
||||||
* @see AutoCloseable
|
* @see AutoCloseable
|
||||||
* @author Jérémi NIHART <j.nihart@student.helmo.be>
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public class StoreProcessor extends Thread implements AutoCloseable {
|
public class StoreProcessor extends Thread implements AutoCloseable {
|
||||||
// Variables
|
// Variables
|
||||||
@ -37,7 +35,7 @@ public class StoreProcessor extends Thread implements AutoCloseable {
|
|||||||
private Context context;
|
private Context context;
|
||||||
private PrintWriter writer;
|
private PrintWriter writer;
|
||||||
private ProtocolWriter.ProtocolResult protocolResult;
|
private ProtocolWriter.ProtocolResult protocolResult;
|
||||||
private ProtocolRepository protocolRep;
|
private final ProtocolRepository protocolRep;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
public StoreProcessor(Socket socket, String domain, StoreProcessorFFE ffe, ProtocolRepository protocolRep) {
|
public StoreProcessor(Socket socket, String domain, StoreProcessorFFE ffe, ProtocolRepository protocolRep) {
|
||||||
@ -95,7 +93,7 @@ public class StoreProcessor extends Thread implements AutoCloseable {
|
|||||||
} catch (IOException writeException) { // Si SBE fermé
|
} catch (IOException writeException) { // Si SBE fermé
|
||||||
System.out.println("STOPPER");
|
System.out.println("STOPPER");
|
||||||
// Envoie au client que la requête n'a pu être traitée
|
// Envoie au client que la requête n'a pu être traitée
|
||||||
alertAvalaible(null);
|
alertAvailable(null);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,14 +108,14 @@ public class StoreProcessor extends Thread implements AutoCloseable {
|
|||||||
this.store.getInputStream()
|
this.store.getInputStream()
|
||||||
);
|
);
|
||||||
|
|
||||||
alertAvalaible(responseResult.getResultCommand());
|
alertAvailable(responseResult.getResultCommand());
|
||||||
} else {
|
} else {
|
||||||
System.out.println("StoreBackEnd result: Commande null");
|
System.out.println("StoreBackEnd result: Commande null");
|
||||||
alertAvalaible(null);
|
alertAvailable(null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("StoreBackEnd: Commande null");
|
System.out.println("StoreBackEnd: Commande null");
|
||||||
alertAvalaible(null);
|
alertAvailable(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
@ -139,6 +137,7 @@ public class StoreProcessor extends Thread implements AutoCloseable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de demander au StoreBackEnd d'effectuer une commande
|
* Permet de demander au StoreBackEnd d'effectuer une commande
|
||||||
|
*
|
||||||
* @param protocolResult La commande à effectuer
|
* @param protocolResult La commande à effectuer
|
||||||
*/
|
*/
|
||||||
public void executeCommand(Context context, ProtocolWriter.ProtocolResult protocolResult) {
|
public void executeCommand(Context context, ProtocolWriter.ProtocolResult protocolResult) {
|
||||||
@ -152,7 +151,7 @@ public class StoreProcessor extends Thread implements AutoCloseable {
|
|||||||
/**
|
/**
|
||||||
* Permet de déclarer le StoreBackEnd disponible
|
* Permet de déclarer le StoreBackEnd disponible
|
||||||
*/
|
*/
|
||||||
private void alertAvalaible(ProtocolWriter.ProtocolResult responseCommand) {
|
private void alertAvailable(ProtocolWriter.ProtocolResult responseCommand) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
this.protocolResult = null;
|
this.protocolResult = null;
|
||||||
if (responseCommand == null) {
|
if (responseCommand == null) {
|
||||||
@ -169,7 +168,9 @@ public class StoreProcessor extends Thread implements AutoCloseable {
|
|||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
try {
|
try {
|
||||||
this.wait();
|
this.wait();
|
||||||
} catch (InterruptedException e) { e.printStackTrace(); }
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package lightcontainer.enumerations;
|
|||||||
import lightcontainer.domains.Task;
|
import lightcontainer.domains.Task;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* enumeration to define the type of a {@link Task}.
|
* enumeration to define the type of {@link Task}.
|
||||||
*/
|
*/
|
||||||
public enum TaskType {
|
public enum TaskType {
|
||||||
SEND,
|
SEND,
|
||||||
|
@ -13,6 +13,7 @@ public interface ClientHandlerFFE {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Demande le traitement d'une commande
|
* Demande le traitement d'une commande
|
||||||
|
*
|
||||||
* @param context Context de la requête
|
* @param context Context de la requête
|
||||||
* @param command Commande à traiter
|
* @param command Commande à traiter
|
||||||
*/
|
*/
|
||||||
|
@ -11,12 +11,14 @@ import lightcontainer.repository.StoreProcessorRepository;
|
|||||||
public interface MulticastSPR {
|
public interface MulticastSPR {
|
||||||
/**
|
/**
|
||||||
* Setter, allow to define the ServerListener of a repository.
|
* Setter, allow to define the ServerListener of a repository.
|
||||||
|
*
|
||||||
* @param server ServerListener to set as default.
|
* @param server ServerListener to set as default.
|
||||||
*/
|
*/
|
||||||
void setServerListener(MulticastServerListener server);
|
void setServerListener(MulticastServerListener server);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a StorePorcessor.
|
* Add a StorePorcessor.
|
||||||
|
*
|
||||||
* @param store Store processor to add.
|
* @param store Store processor to add.
|
||||||
*/
|
*/
|
||||||
boolean addStore(StoreProcessor store);
|
boolean addStore(StoreProcessor store);
|
||||||
@ -36,6 +38,7 @@ public interface MulticastSPR {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de déconnecter un SBE
|
* Permet de déconnecter un SBE
|
||||||
|
*
|
||||||
* @param domain Le domaine du SBE à déconnecter
|
* @param domain Le domaine du SBE à déconnecter
|
||||||
*/
|
*/
|
||||||
void closeStore(String domain);
|
void closeStore(String domain);
|
||||||
|
@ -10,13 +10,15 @@ import lightcontainer.repository.FileFrontEnd;
|
|||||||
public interface StoreProcessorFFE {
|
public interface StoreProcessorFFE {
|
||||||
/**
|
/**
|
||||||
* Allows a {@link StoreProcessor} to notify the FFE that it's available.
|
* Allows a {@link StoreProcessor} to notify the FFE that it's available.
|
||||||
|
*
|
||||||
* @param store The store processor that is now available.
|
* @param store The store processor that is now available.
|
||||||
* @param responseCommand
|
* @param response
|
||||||
*/
|
*/
|
||||||
void onStoreAvailable(StoreProcessor store, ProtocolWriter.ProtocolResult response);
|
void onStoreAvailable(StoreProcessor store, ProtocolWriter.ProtocolResult response);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de déconnecter un SBE
|
* Permet de déconnecter un SBE
|
||||||
|
*
|
||||||
* @param domain Le domaine du SBE à déconnecter
|
* @param domain Le domaine du SBE à déconnecter
|
||||||
*/
|
*/
|
||||||
void onStoreDisconnect(String domain);
|
void onStoreDisconnect(String domain);
|
||||||
|
@ -12,18 +12,21 @@ import lightcontainer.repository.ClientHandlerRepository;
|
|||||||
public interface UnicastCHR {
|
public interface UnicastCHR {
|
||||||
/**
|
/**
|
||||||
* Setter, allow to define the ServerListener of a repository.
|
* Setter, allow to define the ServerListener of a repository.
|
||||||
|
*
|
||||||
* @param server ServerListener to set as default.
|
* @param server ServerListener to set as default.
|
||||||
*/
|
*/
|
||||||
void setServerListener(UnicastServerListener server);
|
void setServerListener(UnicastServerListener server);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a ClientHandler.
|
* Add a ClientHandler.
|
||||||
|
*
|
||||||
* @param client Client Handler to add.
|
* @param client Client Handler to add.
|
||||||
*/
|
*/
|
||||||
void addClient(ClientHandler client);
|
void addClient(ClientHandler client);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de demander la déconnection d'un client
|
* Permet de demander la déconnection d'un client
|
||||||
|
*
|
||||||
* @param client Le client à déconnecter
|
* @param client Le client à déconnecter
|
||||||
*/
|
*/
|
||||||
void disconnect(ClientHandler client);
|
void disconnect(ClientHandler client);
|
||||||
|
@ -95,7 +95,8 @@ public abstract class ProtocolReader {
|
|||||||
*
|
*
|
||||||
* @param reader Buffer rempli du fichier
|
* @param reader Buffer rempli du fichier
|
||||||
*/
|
*/
|
||||||
public void read(InputStream reader) { }
|
public void read(InputStream reader) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de récupérer le context courant
|
* Permet de récupérer le context courant
|
||||||
|
@ -23,6 +23,7 @@ public abstract class ProtocolWriter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de récupérer le nom de la commande.
|
* Permet de récupérer le nom de la commande.
|
||||||
|
*
|
||||||
* @return Nom de la commande.
|
* @return Nom de la commande.
|
||||||
*/
|
*/
|
||||||
public final String getCmdName() {
|
public final String getCmdName() {
|
||||||
@ -50,12 +51,15 @@ public abstract class ProtocolWriter {
|
|||||||
/**
|
/**
|
||||||
* Permet d'écrire un fichier sur le réseau. Cad envoyer le contenu d'un fichier sur le réseau.
|
* Permet d'écrire un fichier sur le réseau. Cad envoyer le contenu d'un fichier sur le réseau.
|
||||||
* Redéfinissez cette méthode pour l'utiliser.
|
* Redéfinissez cette méthode pour l'utiliser.
|
||||||
|
*
|
||||||
* @param writer Buffer à remplir qui sera envoyer via le réseau
|
* @param writer Buffer à remplir qui sera envoyer via le réseau
|
||||||
*/
|
*/
|
||||||
public void write(OutputStream writer) throws IOException {}
|
public void write(OutputStream writer) throws IOException {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accesseur au contexte courant sur lequel opère la commande
|
* Accesseur au contexte courant sur lequel opère la commande
|
||||||
|
*
|
||||||
* @return Context
|
* @return Context
|
||||||
*/
|
*/
|
||||||
public Context getContext() {
|
public Context getContext() {
|
||||||
@ -66,6 +70,7 @@ public abstract class ProtocolWriter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de contruire une commande selon une règle établie.
|
* Permet de contruire une commande selon une règle établie.
|
||||||
|
*
|
||||||
* @param data Les données à ajouter dans la commande; L'ordre défini leur position dans la commande
|
* @param data Les données à ajouter dans la commande; L'ordre défini leur position dans la commande
|
||||||
* @return La commande construites
|
* @return La commande construites
|
||||||
*/
|
*/
|
||||||
@ -74,7 +79,7 @@ public abstract class ProtocolWriter {
|
|||||||
StringBuilder builder = new StringBuilder(this.cmdName);
|
StringBuilder builder = new StringBuilder(this.cmdName);
|
||||||
|
|
||||||
for (String param : data)
|
for (String param : data)
|
||||||
builder.append(" " + param);
|
builder.append(" ").append(param);
|
||||||
|
|
||||||
String command = builder + "\r\n";
|
String command = builder + "\r\n";
|
||||||
Matcher ruleMatcher = this.rulePattern.matcher(command); // Vérifie que tout match (cf. Matcher). Si match alors on retourne la commande build, sinon on retourne NULL
|
Matcher ruleMatcher = this.rulePattern.matcher(command); // Vérifie que tout match (cf. Matcher). Si match alors on retourne la commande build, sinon on retourne NULL
|
||||||
|
@ -69,6 +69,7 @@ public class RemoveFileRule extends ProtocolReader {
|
|||||||
/**
|
/**
|
||||||
* TODO : But futur est de pouvoir en avoir plusieurs
|
* TODO : But futur est de pouvoir en avoir plusieurs
|
||||||
* Cette méthode permet de choisir le domaine voulu.
|
* Cette méthode permet de choisir le domaine voulu.
|
||||||
|
*
|
||||||
* @param storageIterator Les domaines
|
* @param storageIterator Les domaines
|
||||||
* @return Le domain choisi
|
* @return Le domain choisi
|
||||||
*/
|
*/
|
||||||
|
@ -20,8 +20,8 @@ public class RetrieveOkRule extends ProtocolReader {
|
|||||||
private static final int HASHED_FILE_CONTENT = 2; // Index hashed file content
|
private static final int HASHED_FILE_CONTENT = 2; // Index hashed file content
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
private ProtocolRepository protocolRep;
|
private final ProtocolRepository protocolRep;
|
||||||
private String storagePath;
|
private final String storagePath;
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
public RetrieveOkRule(ProtocolRepository protocolRep, String storagePath) {
|
public RetrieveOkRule(ProtocolRepository protocolRep, String storagePath) {
|
||||||
@ -32,8 +32,8 @@ public class RetrieveOkRule extends ProtocolReader {
|
|||||||
|
|
||||||
public class Result extends ProtocolResult {
|
public class Result extends ProtocolResult {
|
||||||
// Variables
|
// Variables
|
||||||
private String filename;
|
private final String filename;
|
||||||
private int filesize;
|
private final int filesize;
|
||||||
private String hashedFileContent;
|
private String hashedFileContent;
|
||||||
|
|
||||||
public Result(Context context, String filename, int filesize, String hashedFileContent) {
|
public Result(Context context, String filename, int filesize, String hashedFileContent) {
|
||||||
@ -52,7 +52,6 @@ public class RetrieveOkRule extends ProtocolReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bitch has bettern than my money
|
|
||||||
* @param reader Buffer rempli du fichier
|
* @param reader Buffer rempli du fichier
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,8 +26,8 @@ public class SavefileRule extends ProtocolReader {
|
|||||||
private static final int FILE_NAME = 0; // Index file name.
|
private static final int FILE_NAME = 0; // Index file name.
|
||||||
private static final int FILE_SIZE = 1; // Index file size.
|
private static final int FILE_SIZE = 1; // Index file size.
|
||||||
|
|
||||||
private ProtocolRepository protocolRep;
|
private final ProtocolRepository protocolRep;
|
||||||
private String storagePath;
|
private final String storagePath;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
public SavefileRule(ProtocolRepository protocolRep, String storagePath) {
|
public SavefileRule(ProtocolRepository protocolRep, String storagePath) {
|
||||||
@ -39,7 +39,7 @@ public class SavefileRule extends ProtocolReader {
|
|||||||
public class Result extends ProtocolResult {
|
public class Result extends ProtocolResult {
|
||||||
// Variables
|
// Variables
|
||||||
private String filename;
|
private String filename;
|
||||||
private int size;
|
private final int size;
|
||||||
|
|
||||||
// Construct
|
// Construct
|
||||||
public Result(Context context, String filename, int size) {
|
public Result(Context context, String filename, int size) {
|
||||||
|
@ -14,7 +14,7 @@ public class SendErrorRule extends ProtocolReader {
|
|||||||
|
|
||||||
private static final String NAME = "SEND_ERROR";
|
private static final String NAME = "SEND_ERROR";
|
||||||
|
|
||||||
private ProtocolRepository protocolRep;
|
private final ProtocolRepository protocolRep;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
public SendErrorRule(ProtocolRepository protocolRep) {
|
public SendErrorRule(ProtocolRepository protocolRep) {
|
||||||
|
@ -18,7 +18,7 @@ public class SigninRule extends ProtocolReader {
|
|||||||
private static final int LOGIN = 0; // Index du domain dans le tableau de données
|
private static final int LOGIN = 0; // Index du domain dans le tableau de données
|
||||||
private static final int PASSWORD = 1; // Index du port dans le tableau de données
|
private static final int PASSWORD = 1; // Index du port dans le tableau de données
|
||||||
|
|
||||||
private ProtocolRepository protocolRep;
|
private final ProtocolRepository protocolRep;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
public SigninRule(ProtocolRepository protocolRep) {
|
public SigninRule(ProtocolRepository protocolRep) {
|
||||||
|
@ -16,7 +16,7 @@ public class SignupRule extends ProtocolReader {
|
|||||||
private static final int LOGIN = 0;
|
private static final int LOGIN = 0;
|
||||||
private static final int PASSWORD = 1;
|
private static final int PASSWORD = 1;
|
||||||
|
|
||||||
private ProtocolRepository protocolRep;
|
private final ProtocolRepository protocolRep;
|
||||||
|
|
||||||
public SignupRule(ProtocolRepository protocolRep) {
|
public SignupRule(ProtocolRepository protocolRep) {
|
||||||
super(NAME, PATTERN);
|
super(NAME, PATTERN);
|
||||||
|
@ -18,7 +18,7 @@ public class GetFileOkRule extends ProtocolWriter {
|
|||||||
private static final int FILE_SIZE = 1; // Index file size
|
private static final int FILE_SIZE = 1; // Index file size
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
private String storagePath;
|
private final String storagePath;
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
public GetFileOkRule(String storagePath) {
|
public GetFileOkRule(String storagePath) {
|
||||||
@ -28,8 +28,8 @@ public class GetFileOkRule extends ProtocolWriter {
|
|||||||
|
|
||||||
public class Result extends ProtocolWriter.ProtocolResult {
|
public class Result extends ProtocolWriter.ProtocolResult {
|
||||||
// Variables
|
// Variables
|
||||||
private String filename;
|
private final String filename;
|
||||||
private int filesize;
|
private final int filesize;
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
public Result(Context context, String filename, int filesize) {
|
public Result(Context context, String filename, int filesize) {
|
||||||
@ -40,6 +40,7 @@ public class GetFileOkRule extends ProtocolWriter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Oh yeahh baby by tonton EndMove ;-)
|
* Oh yeahh baby by tonton EndMove ;-)
|
||||||
|
*
|
||||||
* @param writer Buffer à remplir qui sera envoyer via le réseau
|
* @param writer Buffer à remplir qui sera envoyer via le réseau
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -58,7 +59,8 @@ public class GetFileOkRule extends ProtocolWriter {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Files.deleteIfExists(Path.of(String.format("%s/%s", storagePath, getContext().getDataString("hashedFileName"))));
|
Files.deleteIfExists(Path.of(String.format("%s/%s", storagePath, getContext().getDataString("hashedFileName"))));
|
||||||
} catch (IOException ignore) { }
|
} catch (IOException ignore) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,8 @@ public class SaveFileOkRule extends ProtocolWriter {
|
|||||||
String hashedFileName = context.getHashedFileName(context.getDataString("fileName"));
|
String hashedFileName = context.getHashedFileName(context.getDataString("fileName"));
|
||||||
try {
|
try {
|
||||||
Files.deleteIfExists(Path.of(String.format("%s/%s", storagePath, hashedFileName)));
|
Files.deleteIfExists(Path.of(String.format("%s/%s", storagePath, hashedFileName)));
|
||||||
} catch (IOException ignore) {}
|
} catch (IOException ignore) {
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class SendfileRule extends ProtocolWriter {
|
|||||||
private static final int FILE_SIZE = 1; // Index file size.
|
private static final int FILE_SIZE = 1; // Index file size.
|
||||||
private static final int HASHED_FILE_CONTENT = 2; // Index file content hashed.
|
private static final int HASHED_FILE_CONTENT = 2; // Index file content hashed.
|
||||||
|
|
||||||
private String storagePath;
|
private final String storagePath;
|
||||||
|
|
||||||
public SendfileRule(String storagePath) {
|
public SendfileRule(String storagePath) {
|
||||||
super(NAME, PATTERN);
|
super(NAME, PATTERN);
|
||||||
|
@ -8,18 +8,18 @@ import lightcontainer.protocol.ProtocolWriter;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
// TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;)
|
// TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClientHandlerRepository
|
* ClientHandlerRepository
|
||||||
*
|
* <p>
|
||||||
* Repository storing ClientHandler class.
|
* Repository storing ClientHandler class.
|
||||||
* Contains some utility functions.
|
* Contains some utility functions.
|
||||||
*
|
*
|
||||||
|
* @author Jérémi NIHART <j.nihart@student.helmo.be>
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @since 1.0
|
|
||||||
*
|
|
||||||
* @see ClientHandler
|
* @see ClientHandler
|
||||||
* @see AutoCloseable
|
* @see AutoCloseable
|
||||||
* @author Jérémi NIHART <j.nihart@student.helmo.be>
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public class ClientHandlerRepository implements AutoCloseable, UnicastCHR {
|
public class ClientHandlerRepository implements AutoCloseable, UnicastCHR {
|
||||||
// Variable
|
// Variable
|
||||||
@ -34,8 +34,8 @@ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR {
|
|||||||
/**
|
/**
|
||||||
* Setter, allow to define the ServerListener of a repository.
|
* Setter, allow to define the ServerListener of a repository.
|
||||||
* & Start the server.
|
* & Start the server.
|
||||||
* @param server ServerListener to set as default.
|
|
||||||
*
|
*
|
||||||
|
* @param server ServerListener to set as default.
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -46,8 +46,8 @@ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a ClientHandler.
|
* Add a ClientHandler.
|
||||||
* @param client Client Handler to add.
|
|
||||||
*
|
*
|
||||||
|
* @param client Client Handler to add.
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,8 +16,8 @@ import java.util.concurrent.ConcurrentLinkedDeque;
|
|||||||
public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
|
public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
|
||||||
// Variables
|
// Variables
|
||||||
private Deque<Task> tasks = new ConcurrentLinkedDeque<>();
|
private Deque<Task> tasks = new ConcurrentLinkedDeque<>();
|
||||||
private ClientHandlerRepository clientRepository; // TODO -> pourquoi pas une interface ? end
|
private final ClientHandlerRepository clientRepository; // TODO -> pourquoi pas une interface ? end
|
||||||
private StoreProcessorRepository storeRepository; // TODO -> pourquoi pas une interface ? end
|
private final StoreProcessorRepository storeRepository; // TODO -> pourquoi pas une interface ? end
|
||||||
private ProtocolRepository protocolRepository;
|
private ProtocolRepository protocolRepository;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
|
@ -9,17 +9,17 @@ import java.util.HashSet;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
// TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;)
|
// TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StoreProcessorRepository
|
* StoreProcessorRepository
|
||||||
*
|
* <p>
|
||||||
* Repository storing StorePorcessor class.
|
* Repository storing StorePorcessor class.
|
||||||
* Contains some utility functions.
|
* Contains some utility functions.
|
||||||
*
|
*
|
||||||
* @version 1.0
|
|
||||||
* @since 1.0
|
|
||||||
*
|
|
||||||
* @see StoreProcessor
|
|
||||||
* @author Jérémi NIHART <j.nihart@student.helmo.be>
|
* @author Jérémi NIHART <j.nihart@student.helmo.be>
|
||||||
|
* @version 1.0
|
||||||
|
* @see StoreProcessor
|
||||||
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public class StoreProcessorRepository implements AutoCloseable, MulticastSPR {
|
public class StoreProcessorRepository implements AutoCloseable, MulticastSPR {
|
||||||
// Variables
|
// Variables
|
||||||
@ -34,8 +34,8 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR {
|
|||||||
/**
|
/**
|
||||||
* Setter, allow to define the ServerListener of a repository.
|
* Setter, allow to define the ServerListener of a repository.
|
||||||
* & start the server.
|
* & start the server.
|
||||||
* @param server ServerListener to set as default.
|
|
||||||
*
|
*
|
||||||
|
* @param server ServerListener to set as default.
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -46,8 +46,8 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a StorePorcessor.
|
* Add a StorePorcessor.
|
||||||
* @param store Store processor to add.
|
|
||||||
*
|
*
|
||||||
|
* @param store Store processor to add.
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -90,6 +90,7 @@ public class AppConfig {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Méthode permettant de récupérer le chemin de sauvegarde des fichiers
|
* Méthode permettant de récupérer le chemin de sauvegarde des fichiers
|
||||||
|
*
|
||||||
* @return Chemin de sauvegarde
|
* @return Chemin de sauvegarde
|
||||||
*/
|
*/
|
||||||
public String getStoragePath() {
|
public String getStoragePath() {
|
||||||
|
@ -11,10 +11,9 @@ import java.util.Base64;
|
|||||||
/**
|
/**
|
||||||
* AES GCM 256 Encryption Class [DO NOT EDIT]
|
* AES GCM 256 Encryption Class [DO NOT EDIT]
|
||||||
*
|
*
|
||||||
* @since 1.0
|
|
||||||
* @version 1.0
|
|
||||||
*
|
|
||||||
* @author Jérémi Nihart <contact@endmove.eu>
|
* @author Jérémi Nihart <contact@endmove.eu>
|
||||||
|
* @version 1.0
|
||||||
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public class AES_GCM {
|
public class AES_GCM {
|
||||||
// Constants
|
// Constants
|
||||||
@ -23,8 +22,7 @@ public class AES_GCM {
|
|||||||
public static final int GCM_TAG_LENGTH = 16;
|
public static final int GCM_TAG_LENGTH = 16;
|
||||||
|
|
||||||
// Main method for testing
|
// Main method for testing
|
||||||
public static void main(String[] args) throws Exception
|
public static void main(String[] args) throws Exception {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* FILE ENCRYPTION DEMO
|
* FILE ENCRYPTION DEMO
|
||||||
*/
|
*/
|
||||||
@ -92,7 +90,6 @@ public class AES_GCM {
|
|||||||
*
|
*
|
||||||
* @param base64String A base64 encoded string.
|
* @param base64String A base64 encoded string.
|
||||||
* @return Plain string.
|
* @return Plain string.
|
||||||
*
|
|
||||||
* @see AES_GCM#decodeBase64Vector(String)
|
* @see AES_GCM#decodeBase64Vector(String)
|
||||||
*/
|
*/
|
||||||
private static String decodeBase64String(String base64String) {
|
private static String decodeBase64String(String base64String) {
|
||||||
@ -101,6 +98,7 @@ public class AES_GCM {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Encoder to encode vector to base64 string.
|
* Encoder to encode vector to base64 string.
|
||||||
|
*
|
||||||
* @param rawVector A raw vector.
|
* @param rawVector A raw vector.
|
||||||
* @return A base64 encoded vector.
|
* @return A base64 encoded vector.
|
||||||
*/
|
*/
|
||||||
@ -111,9 +109,9 @@ public class AES_GCM {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Encoder to encode string to base64 string.
|
* Encoder to encode string to base64 string.
|
||||||
|
*
|
||||||
* @param rawString A raw string.
|
* @param rawString A raw string.
|
||||||
* @return A base64 encoded string.
|
* @return A base64 encoded string.
|
||||||
*
|
|
||||||
* @see AES_GCM#encodeBase64(byte[]))
|
* @see AES_GCM#encodeBase64(byte[]))
|
||||||
*/
|
*/
|
||||||
private static String encodeBase64(String rawString) {
|
private static String encodeBase64(String rawString) {
|
||||||
@ -127,9 +125,7 @@ public class AES_GCM {
|
|||||||
* following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE)
|
* following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE)
|
||||||
* @param key Base64 encoded secret key.
|
* @param key Base64 encoded secret key.
|
||||||
* @param IV Base64 encoded vector.
|
* @param IV Base64 encoded vector.
|
||||||
*
|
|
||||||
* @return A Cryptography cypher.
|
* @return A Cryptography cypher.
|
||||||
*
|
|
||||||
* @throws AesGcmException Throw an exception in case of an error occur while setting up the the cypher.
|
* @throws AesGcmException Throw an exception in case of an error occur while setting up the the cypher.
|
||||||
*/
|
*/
|
||||||
private static Cipher createCipher(int op_mode, String key, String IV) throws AesGcmException {
|
private static Cipher createCipher(int op_mode, String key, String IV) throws AesGcmException {
|
||||||
@ -152,7 +148,6 @@ public class AES_GCM {
|
|||||||
* Generate a secret key base64 encoded.
|
* Generate a secret key base64 encoded.
|
||||||
*
|
*
|
||||||
* @return New Secret key b64 encoded.
|
* @return New Secret key b64 encoded.
|
||||||
*
|
|
||||||
* @throws AesGcmException Exception if an error occur.
|
* @throws AesGcmException Exception if an error occur.
|
||||||
*/
|
*/
|
||||||
public static String generateSecretKey() throws AesGcmException {
|
public static String generateSecretKey() throws AesGcmException {
|
||||||
@ -184,9 +179,7 @@ public class AES_GCM {
|
|||||||
* @param plainText Plain text to encrypt.
|
* @param plainText Plain text to encrypt.
|
||||||
* @param key Base64 encoded secret key.
|
* @param key Base64 encoded secret key.
|
||||||
* @param IV Base64 encoded vector.
|
* @param IV Base64 encoded vector.
|
||||||
*
|
|
||||||
* @return The encrypted plain text Base64 encoded.
|
* @return The encrypted plain text Base64 encoded.
|
||||||
*
|
|
||||||
* @throws AesGcmException Exception if an error occur.
|
* @throws AesGcmException Exception if an error occur.
|
||||||
*/
|
*/
|
||||||
public static String encrypt(String plainText, String key, String IV) throws AesGcmException {
|
public static String encrypt(String plainText, String key, String IV) throws AesGcmException {
|
||||||
@ -209,7 +202,6 @@ public class AES_GCM {
|
|||||||
* @param fileSize Stream/file size (! unencrypted size !).
|
* @param fileSize Stream/file size (! unencrypted size !).
|
||||||
* @param key Base64 encoded secret key.
|
* @param key Base64 encoded secret key.
|
||||||
* @param IV Base64 encoded vector.
|
* @param IV Base64 encoded vector.
|
||||||
*
|
|
||||||
* @throws AesGcmException Exception if an error occur.
|
* @throws AesGcmException Exception if an error occur.
|
||||||
*/
|
*/
|
||||||
public static void encryptStream(InputStream in, OutputStream out, long fileSize, String key, String IV) throws AesGcmException {
|
public static void encryptStream(InputStream in, OutputStream out, long fileSize, String key, String IV) throws AesGcmException {
|
||||||
@ -240,9 +232,7 @@ public class AES_GCM {
|
|||||||
* @param cryptText The encrypted text.
|
* @param cryptText The encrypted text.
|
||||||
* @param key Base64 encoded secret key.
|
* @param key Base64 encoded secret key.
|
||||||
* @param IV Base64 encoded vector.
|
* @param IV Base64 encoded vector.
|
||||||
*
|
|
||||||
* @return The decrypted plain text.
|
* @return The decrypted plain text.
|
||||||
*
|
|
||||||
* @throws AesGcmException Exception if an error occur.
|
* @throws AesGcmException Exception if an error occur.
|
||||||
*/
|
*/
|
||||||
public static String decrypt(String cryptText, String key, String IV) throws AesGcmException {
|
public static String decrypt(String cryptText, String key, String IV) throws AesGcmException {
|
||||||
@ -265,7 +255,6 @@ public class AES_GCM {
|
|||||||
* @param fileSize Stream/file size (! encrypted size !).
|
* @param fileSize Stream/file size (! encrypted size !).
|
||||||
* @param key Base64 encoded secret key.
|
* @param key Base64 encoded secret key.
|
||||||
* @param IV Base64 encoded vector.
|
* @param IV Base64 encoded vector.
|
||||||
*
|
|
||||||
* @throws AesGcmException Exception if an error occur.
|
* @throws AesGcmException Exception if an error occur.
|
||||||
*/
|
*/
|
||||||
public static void decryptStream(InputStream in, OutputStream out, long fileSize, String key, String IV) throws AesGcmException {
|
public static void decryptStream(InputStream in, OutputStream out, long fileSize, String key, String IV) throws AesGcmException {
|
||||||
|
@ -3,9 +3,11 @@ package lightcontainer.utils;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
public class FileReceiver {
|
public class FileReceiver {
|
||||||
private String path;
|
private final String path;
|
||||||
|
|
||||||
public FileReceiver(String path) { this.path = path; }
|
public FileReceiver(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
public int receiveFile(InputStream input, String fileName, int fileSize, String key, String iv) {
|
public int receiveFile(InputStream input, String fileName, int fileSize, String key, String iv) {
|
||||||
try {
|
try {
|
||||||
@ -42,7 +44,12 @@ public class FileReceiver {
|
|||||||
return true;
|
return true;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
if(bosFile != null) { try { bosFile.close(); } catch(Exception e) {} }
|
if (bosFile != null) {
|
||||||
|
try {
|
||||||
|
bosFile.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,9 @@ public class FileSender {
|
|||||||
private static final int DEFAULT_BUFFER = 8000;
|
private static final int DEFAULT_BUFFER = 8000;
|
||||||
private final String path;
|
private final String path;
|
||||||
|
|
||||||
public FileSender(String path) { this.path = path; }
|
public FileSender(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean sendFile(String filename, OutputStream out, int fileSize, String aesKey, String iv) throws IOException {
|
public boolean sendFile(String filename, OutputStream out, int fileSize, String aesKey, String iv) throws IOException {
|
||||||
BufferedInputStream bisFile;
|
BufferedInputStream bisFile;
|
||||||
@ -35,7 +37,8 @@ public class FileSender {
|
|||||||
bisFile = new BufferedInputStream(new FileInputStream(file));
|
bisFile = new BufferedInputStream(new FileInputStream(file));
|
||||||
long currentOffset = 0;
|
long currentOffset = 0;
|
||||||
while ((currentOffset < fileSize) && (bytesReaded = bisFile.read(buffer)) > 0) {
|
while ((currentOffset < fileSize) && (bytesReaded = bisFile.read(buffer)) > 0) {
|
||||||
out.write(buffer, 0, bytesReaded); out.flush();
|
out.write(buffer, 0, bytesReaded);
|
||||||
|
out.flush();
|
||||||
currentOffset += bytesReaded;
|
currentOffset += bytesReaded;
|
||||||
}
|
}
|
||||||
bisFile.close();
|
bisFile.close();
|
||||||
|
@ -13,10 +13,9 @@ import java.util.Base64;
|
|||||||
/**
|
/**
|
||||||
* SHA 256 Hashing and borrowing Class [DO NOT EDIT]
|
* SHA 256 Hashing and borrowing Class [DO NOT EDIT]
|
||||||
*
|
*
|
||||||
* @since 1.0
|
|
||||||
* @version 1.0
|
|
||||||
*
|
|
||||||
* @author Jérémi Nihart <contact@endmove.eu>
|
* @author Jérémi Nihart <contact@endmove.eu>
|
||||||
|
* @version 1.0
|
||||||
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public class SHA {
|
public class SHA {
|
||||||
// Constants
|
// Constants
|
||||||
@ -44,9 +43,7 @@ public class SHA {
|
|||||||
*
|
*
|
||||||
* @param in InputStream to the input, flux to hash.
|
* @param in InputStream to the input, flux to hash.
|
||||||
* @param fileSize Stream/file size.
|
* @param fileSize Stream/file size.
|
||||||
*
|
|
||||||
* @return Borrowing of the full current flux.
|
* @return Borrowing of the full current flux.
|
||||||
*
|
|
||||||
* @throws ShaException if an error occur.
|
* @throws ShaException if an error occur.
|
||||||
*/
|
*/
|
||||||
public static String hashStream(InputStream in, long fileSize) throws ShaException {
|
public static String hashStream(InputStream in, long fileSize) throws ShaException {
|
||||||
@ -79,9 +76,7 @@ public class SHA {
|
|||||||
*
|
*
|
||||||
* @param rootPath Root path of the file.
|
* @param rootPath Root path of the file.
|
||||||
* @param fileName File Name.
|
* @param fileName File Name.
|
||||||
*
|
|
||||||
* @return Borrowing of the file.
|
* @return Borrowing of the file.
|
||||||
*
|
|
||||||
* @throws ShaException if an error occur.
|
* @throws ShaException if an error occur.
|
||||||
*/
|
*/
|
||||||
public static String hashFile(String rootPath, String fileName) throws ShaException {
|
public static String hashFile(String rootPath, String fileName) throws ShaException {
|
||||||
|
Loading…
Reference in New Issue
Block a user