From 88fe097c0161c13119272220f72d918af3b11ac1 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 19 Mar 2022 11:46:09 +0100 Subject: [PATCH] =?UTF-8?q?Optimisation=20l=C3=A9g=C3=A8re=20du=20code=20+?= =?UTF-8?q?=20correction=20orthographe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/App.java | 8 +- .../java/lightcontainer/domains/Task.java | 14 +- .../domains/client/ClientHandler.java | 8 +- .../domains/client/Context.java | 8 +- .../domains/client/RequestBundle.java | 12 +- .../domains/client/StoreProcessor.java | 31 +++-- .../lightcontainer/enumerations/TaskType.java | 2 +- .../interfaces/ClientHandlerFFE.java | 1 + .../interfaces/MulticastSPR.java | 3 + .../interfaces/ProtocolRepository.java | 2 +- .../interfaces/StoreProcessorFFE.java | 6 +- .../lightcontainer/interfaces/UnicastCHR.java | 3 + .../protocol/ProtocolReader.java | 3 +- .../protocol/ProtocolWriter.java | 9 +- .../protocol/rules/reader/RemoveFileRule.java | 1 + .../protocol/rules/reader/RetrieveOkRule.java | 9 +- .../protocol/rules/reader/SavefileRule.java | 6 +- .../protocol/rules/reader/SendErrorRule.java | 2 +- .../protocol/rules/reader/SigninRule.java | 2 +- .../protocol/rules/reader/SignupRule.java | 2 +- .../protocol/rules/writer/GetFileOkRule.java | 12 +- .../protocol/rules/writer/SaveFileOkRule.java | 3 +- .../protocol/rules/writer/SendfileRule.java | 2 +- .../repository/ClientHandlerRepository.java | 24 ++-- .../repository/FileFrontEnd.java | 4 +- .../repository/StoreProcessorRepository.java | 22 +-- .../lightcontainer/storage/AppConfig.java | 1 + .../java/lightcontainer/utils/AES_GCM.java | 129 ++++++++---------- .../lightcontainer/utils/FileReceiver.java | 21 ++- .../java/lightcontainer/utils/FileSender.java | 21 +-- .../java/lightcontainer/utils/NetChooser.java | 12 +- .../main/java/lightcontainer/utils/SHA.java | 29 ++-- 32 files changed, 217 insertions(+), 195 deletions(-) diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index 862211f..31d329f 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -23,7 +23,7 @@ public class App { public static void main(String[] args) { setupVM(); Repository repositoryStorage = prepareStorage(); - + // Create all repository ClientHandlerRepository clientRep = new ClientHandlerRepository(); StoreProcessorRepository storeRep = new StoreProcessorRepository(); @@ -87,9 +87,9 @@ public class App { } private static void setupVM() { - System.setProperty("javax.net.ssl.keyStore","../ffe.labo.swilabus.com.p12"); - System.setProperty("javax.net.ssl.keyStorePassword","labo2022"); - System.setProperty("https.protocols","TLSv1.3"); + System.setProperty("javax.net.ssl.keyStore", "../ffe.labo.swilabus.com.p12"); + System.setProperty("javax.net.ssl.keyStorePassword", "labo2022"); + System.setProperty("https.protocols", "TLSv1.3"); } } diff --git a/app/src/main/java/lightcontainer/domains/Task.java b/app/src/main/java/lightcontainer/domains/Task.java index 4a89b7b..2ae95ed 100644 --- a/app/src/main/java/lightcontainer/domains/Task.java +++ b/app/src/main/java/lightcontainer/domains/Task.java @@ -10,13 +10,13 @@ import lightcontainer.protocol.ProtocolWriter; public class Task { // Variables 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) { this.context = context; @@ -26,17 +26,18 @@ public class Task { /** * Permet de créer une instance de la class {@link Task} + * * @param context Context à utiliser pour cette tâche * @param command Commande à exécuter * @return L'instance de la tâche créée */ public static Task newInstance(Context context, ProtocolWriter.ProtocolResult command) { - Task task = new Task(context, TaskStatus.PENDING, command); - return task; + return new Task(context, TaskStatus.PENDING, command); } /** * Permet de savoir si la réponse est destinée au client + * * @param storeDomain Nom du store back end fournissant la 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 + * * @return Login du client */ public String getClient() { @@ -54,6 +56,7 @@ public class Task { /** * Permet de récupérer la commande à executer + * * @return Commande à exécuter */ public ProtocolWriter.ProtocolResult getCommand() { @@ -62,6 +65,7 @@ public class Task { /** * Permet de définir le StorBackEnd à utiliser pour cette tâche + * * @param storeDomain Le StorBackEnd à utiliser */ public void setDomain(String storeDomain) { diff --git a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java index 36014e6..5a5b439 100644 --- a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java @@ -29,12 +29,12 @@ import java.nio.charset.StandardCharsets; */ public class ClientHandler implements Runnable, AutoCloseable { // Variables - private ClientHandlerFFE fileFrontEnd; + private final ClientHandlerFFE fileFrontEnd; private final Socket client; - private ProtocolRepository protocolRep; - private Context context; + private final ProtocolRepository protocolRep; + private final Context context; private boolean client_run; - private UnicastCHR repository; + private final UnicastCHR repository; private BufferedReader reader; diff --git a/app/src/main/java/lightcontainer/domains/client/Context.java b/app/src/main/java/lightcontainer/domains/client/Context.java index 7864ca4..dc143a1 100644 --- a/app/src/main/java/lightcontainer/domains/client/Context.java +++ b/app/src/main/java/lightcontainer/domains/client/Context.java @@ -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 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 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 * @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 * @return La valeur associée à la clé diff --git a/app/src/main/java/lightcontainer/domains/client/RequestBundle.java b/app/src/main/java/lightcontainer/domains/client/RequestBundle.java index 8e32156..6d9fd09 100644 --- a/app/src/main/java/lightcontainer/domains/client/RequestBundle.java +++ b/app/src/main/java/lightcontainer/domains/client/RequestBundle.java @@ -5,13 +5,14 @@ import java.util.Map; public class RequestBundle { - private Map stringData = new HashMap<>(); + private final Map stringData = new HashMap<>(); - private Map intData = new HashMap<>(); + private final Map intData = new HashMap<>(); /** * 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é */ public void putString(String key, String value) { @@ -20,7 +21,8 @@ public class RequestBundle { /** * 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é */ public void putInt(String key, int value) { @@ -29,6 +31,7 @@ public class RequestBundle { /** * Permet de récupérer des données string + * * @param key La clé permettant de retrouver la valeur * @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 + * * @param key La clé permettant de retrouver la valeur * @return La valeur associée à la clé */ diff --git a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java index d7158f6..9016510 100644 --- a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java @@ -8,23 +8,21 @@ import lightcontainer.protocol.ProtocolWriter; import java.io.*; import java.net.Socket; -import java.net.SocketException; import java.nio.charset.StandardCharsets; import java.util.Objects; /** * StoreProcessor - * + *

* MULTICAST CLIENT * Class communicating with the storebackend and * processing the tasks in the FileFrontEnd * - * @version 1.1 - * @since 1.0 - * - * @see Runnable - * @see AutoCloseable - * @author Jérémi NIHART + * @author Jérémi NIHART + * @version 1.1 + * @see Runnable + * @see AutoCloseable + * @since 1.0 */ public class StoreProcessor extends Thread implements AutoCloseable { // Variables @@ -37,7 +35,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { private Context context; private PrintWriter writer; private ProtocolWriter.ProtocolResult protocolResult; - private ProtocolRepository protocolRep; + private final ProtocolRepository protocolRep; // Constructor 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é System.out.println("STOPPER"); // Envoie au client que la requête n'a pu être traitée - alertAvalaible(null); + alertAvailable(null); break; } @@ -110,14 +108,14 @@ public class StoreProcessor extends Thread implements AutoCloseable { this.store.getInputStream() ); - alertAvalaible(responseResult.getResultCommand()); + alertAvailable(responseResult.getResultCommand()); } else { System.out.println("StoreBackEnd result: Commande null"); - alertAvalaible(null); + alertAvailable(null); } } else { System.out.println("StoreBackEnd: Commande null"); - alertAvalaible(null); + alertAvailable(null); } } catch (IOException exception) { @@ -139,6 +137,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { /** * Permet de demander au StoreBackEnd d'effectuer une commande + * * @param protocolResult La commande à effectuer */ 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 */ - private void alertAvalaible(ProtocolWriter.ProtocolResult responseCommand) { + private void alertAvailable(ProtocolWriter.ProtocolResult responseCommand) { synchronized (this) { this.protocolResult = null; if (responseCommand == null) { @@ -169,7 +168,9 @@ public class StoreProcessor extends Thread implements AutoCloseable { synchronized (this) { try { this.wait(); - } catch (InterruptedException e) { e.printStackTrace(); } + } catch (InterruptedException e) { + e.printStackTrace(); + } } } diff --git a/app/src/main/java/lightcontainer/enumerations/TaskType.java b/app/src/main/java/lightcontainer/enumerations/TaskType.java index 347e6ce..6a59ca3 100644 --- a/app/src/main/java/lightcontainer/enumerations/TaskType.java +++ b/app/src/main/java/lightcontainer/enumerations/TaskType.java @@ -3,7 +3,7 @@ package lightcontainer.enumerations; import lightcontainer.domains.Task; /** - * enumeration to define the type of a {@link Task}. + * enumeration to define the type of {@link Task}. */ public enum TaskType { SEND, diff --git a/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java b/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java index 30b6b1a..5e5074d 100644 --- a/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java +++ b/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java @@ -13,6 +13,7 @@ public interface ClientHandlerFFE { /** * Demande le traitement d'une commande + * * @param context Context de la requête * @param command Commande à traiter */ diff --git a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java index 5727721..7d5b83a 100644 --- a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java +++ b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java @@ -11,12 +11,14 @@ import lightcontainer.repository.StoreProcessorRepository; public interface MulticastSPR { /** * Setter, allow to define the ServerListener of a repository. + * * @param server ServerListener to set as default. */ void setServerListener(MulticastServerListener server); /** * Add a StorePorcessor. + * * @param store Store processor to add. */ boolean addStore(StoreProcessor store); @@ -36,6 +38,7 @@ public interface MulticastSPR { /** * Permet de déconnecter un SBE + * * @param domain Le domaine du SBE à déconnecter */ void closeStore(String domain); diff --git a/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java b/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java index ccae2fe..d707f39 100644 --- a/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java +++ b/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java @@ -8,7 +8,7 @@ public interface ProtocolRepository { T executeReader(Context context, String data); - T executeWriter(Context context, String cmdName, String... data); + T executeWriter(Context context, String cmdName, String... data); void addReader(ProtocolReader reader); diff --git a/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java b/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java index 15e3561..8848242 100644 --- a/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java +++ b/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java @@ -10,13 +10,15 @@ import lightcontainer.repository.FileFrontEnd; public interface StoreProcessorFFE { /** * Allows a {@link StoreProcessor} to notify the FFE that it's available. - * @param store The store processor that is now available. - * @param responseCommand + * + * @param store The store processor that is now available. + * @param response */ void onStoreAvailable(StoreProcessor store, ProtocolWriter.ProtocolResult response); /** * Permet de déconnecter un SBE + * * @param domain Le domaine du SBE à déconnecter */ void onStoreDisconnect(String domain); diff --git a/app/src/main/java/lightcontainer/interfaces/UnicastCHR.java b/app/src/main/java/lightcontainer/interfaces/UnicastCHR.java index 53af817..21441b3 100644 --- a/app/src/main/java/lightcontainer/interfaces/UnicastCHR.java +++ b/app/src/main/java/lightcontainer/interfaces/UnicastCHR.java @@ -12,18 +12,21 @@ import lightcontainer.repository.ClientHandlerRepository; public interface UnicastCHR { /** * Setter, allow to define the ServerListener of a repository. + * * @param server ServerListener to set as default. */ void setServerListener(UnicastServerListener server); /** * Add a ClientHandler. + * * @param client Client Handler to add. */ void addClient(ClientHandler client); /** * Permet de demander la déconnection d'un client + * * @param client Le client à déconnecter */ void disconnect(ClientHandler client); diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java index 634f0af..b6e4c0f 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -95,7 +95,8 @@ public abstract class ProtocolReader { * * @param reader Buffer rempli du fichier */ - public void read(InputStream reader) { } + public void read(InputStream reader) { + } /** * Permet de récupérer le context courant diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java index 6449229..2f15e98 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java @@ -23,6 +23,7 @@ public abstract class ProtocolWriter { /** * Permet de récupérer le nom de la commande. + * * @return Nom de la commande. */ 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. * Redéfinissez cette méthode pour l'utiliser. + * * @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 + * * @return Context */ public Context getContext() { @@ -66,6 +70,7 @@ public abstract class ProtocolWriter { /** * 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 * @return La commande construites */ @@ -74,7 +79,7 @@ public abstract class ProtocolWriter { StringBuilder builder = new StringBuilder(this.cmdName); for (String param : data) - builder.append(" " + param); + builder.append(" ").append(param); 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 diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java index 7024478..2ec6135 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RemoveFileRule.java @@ -69,6 +69,7 @@ public class RemoveFileRule extends ProtocolReader { /** * TODO : But futur est de pouvoir en avoir plusieurs * Cette méthode permet de choisir le domaine voulu. + * * @param storageIterator Les domaines * @return Le domain choisi */ diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java index 3d7044d..7b4cf26 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/RetrieveOkRule.java @@ -20,8 +20,8 @@ public class RetrieveOkRule extends ProtocolReader { private static final int HASHED_FILE_CONTENT = 2; // Index hashed file content // Variables - private ProtocolRepository protocolRep; - private String storagePath; + private final ProtocolRepository protocolRep; + private final String storagePath; // Variables public RetrieveOkRule(ProtocolRepository protocolRep, String storagePath) { @@ -32,8 +32,8 @@ public class RetrieveOkRule extends ProtocolReader { public class Result extends ProtocolResult { // Variables - private String filename; - private int filesize; + private final String filename; + private final int filesize; private 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 */ @Override diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java index 9128f97..c1ec1b1 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java @@ -26,8 +26,8 @@ public class SavefileRule extends ProtocolReader { private static final int FILE_NAME = 0; // Index file name. private static final int FILE_SIZE = 1; // Index file size. - private ProtocolRepository protocolRep; - private String storagePath; + private final ProtocolRepository protocolRep; + private final String storagePath; // Constructor public SavefileRule(ProtocolRepository protocolRep, String storagePath) { @@ -39,7 +39,7 @@ public class SavefileRule extends ProtocolReader { public class Result extends ProtocolResult { // Variables private String filename; - private int size; + private final int size; // Construct public Result(Context context, String filename, int size) { diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java index 520fa19..132f20f 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java @@ -14,7 +14,7 @@ public class SendErrorRule extends ProtocolReader { private static final String NAME = "SEND_ERROR"; - private ProtocolRepository protocolRep; + private final ProtocolRepository protocolRep; // Constructor public SendErrorRule(ProtocolRepository protocolRep) { diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java index 6f697b5..e61a307 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java @@ -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 PASSWORD = 1; // Index du port dans le tableau de données - private ProtocolRepository protocolRep; + private final ProtocolRepository protocolRep; // Constructor public SigninRule(ProtocolRepository protocolRep) { diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java index fbb56ed..8f27cb4 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java @@ -16,7 +16,7 @@ public class SignupRule extends ProtocolReader { private static final int LOGIN = 0; private static final int PASSWORD = 1; - private ProtocolRepository protocolRep; + private final ProtocolRepository protocolRep; public SignupRule(ProtocolRepository protocolRep) { super(NAME, PATTERN); diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java index 8b5078a..48c363f 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/GetFileOkRule.java @@ -18,7 +18,7 @@ public class GetFileOkRule extends ProtocolWriter { private static final int FILE_SIZE = 1; // Index file size // Variables - private String storagePath; + private final String storagePath; // Constructors public GetFileOkRule(String storagePath) { @@ -28,8 +28,8 @@ public class GetFileOkRule extends ProtocolWriter { public class Result extends ProtocolWriter.ProtocolResult { // Variables - private String filename; - private int filesize; + private final String filename; + private final int filesize; // Constructors public Result(Context context, String filename, int filesize) { @@ -40,13 +40,14 @@ public class GetFileOkRule extends ProtocolWriter { /** * Oh yeahh baby by tonton EndMove ;-) + * * @param writer Buffer à remplir qui sera envoyer via le réseau */ @Override public void write(OutputStream writer) throws IOException { System.out.printf("Sauvegarde du fichier : %s %d\n", this.filename, this.filesize); - System.out.println("Encrypted size for parsing: " + getContext().getDataInt("encryptedFileSize")+" normal: "+getContext().getDataInt("fileSize")); + System.out.println("Encrypted size for parsing: " + getContext().getDataInt("encryptedFileSize") + " normal: " + getContext().getDataInt("fileSize")); FileSender fileSender = new FileSender(storagePath); fileSender.sendFile( getContext().getDataString("hashedFileName"), @@ -58,7 +59,8 @@ public class GetFileOkRule extends ProtocolWriter { try { Files.deleteIfExists(Path.of(String.format("%s/%s", storagePath, getContext().getDataString("hashedFileName")))); - } catch (IOException ignore) { } + } catch (IOException ignore) { + } } } diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java index 13473f5..230cccd 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java @@ -34,7 +34,8 @@ public class SaveFileOkRule extends ProtocolWriter { String hashedFileName = context.getHashedFileName(context.getDataString("fileName")); try { Files.deleteIfExists(Path.of(String.format("%s/%s", storagePath, hashedFileName))); - } catch (IOException ignore) {} + } catch (IOException ignore) { + } return result; } } diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java index 3eae4bd..19abaca 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java @@ -20,7 +20,7 @@ public class SendfileRule extends ProtocolWriter { private static final int FILE_SIZE = 1; // Index file size. private static final int HASHED_FILE_CONTENT = 2; // Index file content hashed. - private String storagePath; + private final String storagePath; public SendfileRule(String storagePath) { super(NAME, PATTERN); diff --git a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java index ff17247..9c69784 100644 --- a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java +++ b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java @@ -8,18 +8,18 @@ import lightcontainer.protocol.ProtocolWriter; import java.util.ArrayList; import java.util.List; // TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;) + /** * ClientHandlerRepository - * + *

* Repository storing ClientHandler class. * Contains some utility functions. * - * @version 1.0 - * @since 1.0 - * - * @see ClientHandler - * @see AutoCloseable - * @author Jérémi NIHART + * @author Jérémi NIHART + * @version 1.0 + * @see ClientHandler + * @see AutoCloseable + * @since 1.0 */ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR { // Variable @@ -34,9 +34,9 @@ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR { /** * Setter, allow to define the ServerListener of a repository. * & Start the server. - * @param server ServerListener to set as default. * - * @since 1.0 + * @param server ServerListener to set as default. + * @since 1.0 */ @Override public void setServerListener(UnicastServerListener server) { @@ -46,9 +46,9 @@ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR { /** * Add a ClientHandler. - * @param client Client Handler to add. * - * @since 1.0 + * @param client Client Handler to add. + * @since 1.0 */ @Override public void addClient(ClientHandler client) { @@ -75,7 +75,7 @@ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR { * AutoClosable Function * Closes all ClientHandlers stored in this repository and deallocates all resources. * - * @since 1.0 + * @since 1.0 */ @Override public void close() { diff --git a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java index acde83e..39d4809 100644 --- a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java +++ b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java @@ -16,8 +16,8 @@ import java.util.concurrent.ConcurrentLinkedDeque; public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { // Variables private Deque tasks = new ConcurrentLinkedDeque<>(); - private ClientHandlerRepository clientRepository; // TODO -> pourquoi pas une interface ? end - private StoreProcessorRepository storeRepository; // TODO -> pourquoi pas une interface ? end + private final ClientHandlerRepository clientRepository; // TODO -> pourquoi pas une interface ? end + private final StoreProcessorRepository storeRepository; // TODO -> pourquoi pas une interface ? end private ProtocolRepository protocolRepository; // Constructor diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java index 163ee96..0d21f9d 100644 --- a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -9,17 +9,17 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; // TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;) + /** * StoreProcessorRepository - * + *

* Repository storing StorePorcessor class. * Contains some utility functions. * - * @version 1.0 - * @since 1.0 - * - * @see StoreProcessor - * @author Jérémi NIHART + * @author Jérémi NIHART + * @version 1.0 + * @see StoreProcessor + * @since 1.0 */ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { // Variables @@ -34,9 +34,9 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { /** * Setter, allow to define the ServerListener of a repository. * & start the server. - * @param server ServerListener to set as default. * - * @since 1.0 + * @param server ServerListener to set as default. + * @since 1.0 */ @Override public void setServerListener(MulticastServerListener server) { @@ -46,9 +46,9 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { /** * Add a StorePorcessor. - * @param store Store processor to add. * - * @since 1.0 + * @param store Store processor to add. + * @since 1.0 */ @Override public boolean addStore(StoreProcessor store) { @@ -129,7 +129,7 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { * AutoClosable Function * Closes all StoreProcessor stored in this repository and deallocates all resources. * - * @since 1.0 + * @since 1.0 */ @Override public void close() { diff --git a/app/src/main/java/lightcontainer/storage/AppConfig.java b/app/src/main/java/lightcontainer/storage/AppConfig.java index 7cc0033..9bc6945 100644 --- a/app/src/main/java/lightcontainer/storage/AppConfig.java +++ b/app/src/main/java/lightcontainer/storage/AppConfig.java @@ -90,6 +90,7 @@ public class AppConfig { /** * Méthode permettant de récupérer le chemin de sauvegarde des fichiers + * * @return Chemin de sauvegarde */ public String getStoragePath() { diff --git a/app/src/main/java/lightcontainer/utils/AES_GCM.java b/app/src/main/java/lightcontainer/utils/AES_GCM.java index 020d5de..8addb45 100644 --- a/app/src/main/java/lightcontainer/utils/AES_GCM.java +++ b/app/src/main/java/lightcontainer/utils/AES_GCM.java @@ -11,10 +11,9 @@ import java.util.Base64; /** * AES GCM 256 Encryption Class [DO NOT EDIT] * - * @since 1.0 - * @version 1.0 - * * @author Jérémi Nihart + * @version 1.0 + * @since 1.0 */ public class AES_GCM { // Constants @@ -23,8 +22,7 @@ public class AES_GCM { public static final int GCM_TAG_LENGTH = 16; // Main method for testing - public static void main(String[] args) throws Exception - { + public static void main(String[] args) throws Exception { /* * FILE ENCRYPTION DEMO */ @@ -38,20 +36,20 @@ public class AES_GCM { String IVFile = generateIV(); String keyFile = generateSecretKey(); // Show options - System.out.println("IV : "+IVFile); - System.out.println("Key : "+keyFile); + System.out.println("IV : " + IVFile); + System.out.println("Key : " + keyFile); // Encrypt encryptStream( - new FileInputStream(inFile), - new FileOutputStream(outFile), + new FileInputStream(inFile), + new FileOutputStream(outFile), inFile.length(), IVFile, keyFile ); // Decrypt decryptStream( - new FileInputStream(outFile), - new FileOutputStream(clearFile), + new FileInputStream(outFile), + new FileOutputStream(clearFile), outFile.length(), IVFile, keyFile @@ -65,8 +63,8 @@ public class AES_GCM { String IV = generateIV(); String key = generateSecretKey(); // Show options - System.out.println("IV : "+IV); - System.out.println("Key : "+key); + System.out.println("IV : " + IV); + System.out.println("Key : " + key); System.out.println("Original text : " + plainText); // Crypt String cryptText = encrypt(plainText, key, IV); @@ -79,8 +77,8 @@ public class AES_GCM { /** * Decoder to decode base64 vector to byte vector. * - * @param base64Vector A base64 encoded vector. - * @return Byte vector. + * @param base64Vector A base64 encoded vector. + * @return Byte vector. */ private static byte[] decodeBase64Vector(String base64Vector) { Base64.Decoder b64Decoder = Base64.getDecoder(); @@ -90,10 +88,9 @@ public class AES_GCM { /** * Decoder to decode base64 string to plain string. * - * @param base64String A base64 encoded string. - * @return Plain string. - * - * @see AES_GCM#decodeBase64Vector(String) + * @param base64String A base64 encoded string. + * @return Plain string. + * @see AES_GCM#decodeBase64Vector(String) */ private static String decodeBase64String(String base64String) { return new String(decodeBase64Vector(base64String)); @@ -101,8 +98,9 @@ public class AES_GCM { /** * Encoder to encode vector to base64 string. - * @param rawVector A raw vector. - * @return A base64 encoded vector. + * + * @param rawVector A raw vector. + * @return A base64 encoded vector. */ private static String encodeBase64(byte[] rawVector) { Base64.Encoder b64Encoder = Base64.getEncoder(); @@ -111,10 +109,10 @@ public class AES_GCM { /** * Encoder to encode string to base64 string. - * @param rawString A raw string. - * @return A base64 encoded string. * - * @see AES_GCM#encodeBase64(byte[])) + * @param rawString A raw string. + * @return A base64 encoded string. + * @see AES_GCM#encodeBase64(byte[])) */ private static String encodeBase64(String rawString) { return encodeBase64(rawString.getBytes(StandardCharsets.UTF_8)); @@ -123,14 +121,12 @@ public class AES_GCM { /** * FACTORY, to setting up a Java cryptographic cypher. * - * @param op_mode the operation mode of this cipher (this is one of the - * following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE) - * @param key Base64 encoded secret key. - * @param IV Base64 encoded vector. - * - * @return A Cryptography cypher. - * - * @throws AesGcmException Throw an exception in case of an error occur while setting up the the cypher. + * @param op_mode the operation mode of this cipher (this is one of the + * following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE) + * @param key Base64 encoded secret key. + * @param IV Base64 encoded vector. + * @return A Cryptography 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 { try { @@ -151,9 +147,8 @@ public class AES_GCM { /** * Generate a secret key base64 encoded. * - * @return New Secret key b64 encoded. - * - * @throws AesGcmException Exception if an error occur. + * @return New Secret key b64 encoded. + * @throws AesGcmException Exception if an error occur. */ public static String generateSecretKey() throws AesGcmException { try { @@ -169,7 +164,7 @@ public class AES_GCM { /** * Generate an IV (initialisation vector) base64 encoded. * - * @return New generated IV b64 encoded. + * @return New generated IV b64 encoded. */ public static String generateIV() { byte[] IV = new byte[GCM_IV_LENGTH]; @@ -181,13 +176,11 @@ public class AES_GCM { /** * Encrypt text, with AES GCM. * - * @param plainText Plain text to encrypt. - * @param key Base64 encoded secret key. - * @param IV Base64 encoded vector. - * - * @return The encrypted plain text Base64 encoded. - * - * @throws AesGcmException Exception if an error occur. + * @param plainText Plain text to encrypt. + * @param key Base64 encoded secret key. + * @param IV Base64 encoded vector. + * @return The encrypted plain text Base64 encoded. + * @throws AesGcmException Exception if an error occur. */ public static String encrypt(String plainText, String key, String IV) throws AesGcmException { try { @@ -204,13 +197,12 @@ public class AES_GCM { * Encrypt stream, with AES GCM. * The output stream is automatically closed after processing. * - * @param in InputStream to the input, flux to encrypt. - * @param out OutputStream to the output, encrypted flux. - * @param fileSize Stream/file size (! unencrypted size !). - * @param key Base64 encoded secret key. - * @param IV Base64 encoded vector. - * - * @throws AesGcmException Exception if an error occur. + * @param in InputStream to the input, flux to encrypt. + * @param out OutputStream to the output, encrypted flux. + * @param fileSize Stream/file size (! unencrypted size !). + * @param key Base64 encoded secret key. + * @param IV Base64 encoded vector. + * @throws AesGcmException Exception if an error occur. */ public static void encryptStream(InputStream in, OutputStream out, long fileSize, String key, String IV) throws AesGcmException { byte[] buffer = new byte[1024]; @@ -222,7 +214,7 @@ public class AES_GCM { // Initialize a CipherOutputStream CipherOutputStream cipherOut = new CipherOutputStream(out, cipher); // Encryption Process - while((currentSize < fileSize) && (bytes = in.read(buffer)) > 0) { + while ((currentSize < fileSize) && (bytes = in.read(buffer)) > 0) { cipherOut.write(buffer, 0, bytes); cipherOut.flush(); currentSize += bytes; @@ -237,13 +229,11 @@ public class AES_GCM { /** * Decrypt, with AES GCM. * - * @param cryptText The encrypted text. - * @param key Base64 encoded secret key. - * @param IV Base64 encoded vector. - * - * @return The decrypted plain text. - * - * @throws AesGcmException Exception if an error occur. + * @param cryptText The encrypted text. + * @param key Base64 encoded secret key. + * @param IV Base64 encoded vector. + * @return The decrypted plain text. + * @throws AesGcmException Exception if an error occur. */ public static String decrypt(String cryptText, String key, String IV) throws AesGcmException { try { @@ -260,13 +250,12 @@ public class AES_GCM { * Decrypt stream, with AES GCM. * The input stream is automatically closed after processing. * - * @param in InputStream to the input, flux to decrypt. - * @param out OutputStream to the output, decrypted flux. - * @param fileSize Stream/file size (! encrypted size !). - * @param key Base64 encoded secret key. - * @param IV Base64 encoded vector. - * - * @throws AesGcmException Exception if an error occur. + * @param in InputStream to the input, flux to decrypt. + * @param out OutputStream to the output, decrypted flux. + * @param fileSize Stream/file size (! encrypted size !). + * @param key Base64 encoded secret key. + * @param IV Base64 encoded vector. + * @throws AesGcmException Exception if an error occur. */ public static void decryptStream(InputStream in, OutputStream out, long fileSize, String key, String IV) throws AesGcmException { byte[] buffer = new byte[1024]; @@ -278,7 +267,7 @@ public class AES_GCM { // Initialize a CipherOutputStream CipherInputStream cipherIn = new CipherInputStream(in, cipher); // Encryption Process - while((currentSize < fileSize) && (bytes = cipherIn.read(buffer)) > 0) { + while ((currentSize < fileSize) && (bytes = cipherIn.read(buffer)) > 0) { out.write(buffer, 0, bytes); out.flush(); currentSize += bytes; @@ -301,7 +290,7 @@ public class AES_GCM { * Constructor of AesGcmException, * which define it's own detail message. * - * @param msg The detail message. + * @param msg The detail message. */ public AesGcmException(String msg) { super(msg); @@ -312,7 +301,7 @@ public class AES_GCM { * which propagates the error triggering * a crash of the encryption system. * - * @param e Previous exception throwable. + * @param e Previous exception throwable. */ public AesGcmException(Throwable e) { super(e); @@ -324,8 +313,8 @@ public class AES_GCM { * a crash of the encryption system with * a chosen detail message. * - * @param e Previous exception throwable. - * @param msg The detail message. + * @param e Previous exception throwable. + * @param msg The detail message. */ public AesGcmException(GeneralSecurityException e, String msg) { super(msg, e); diff --git a/app/src/main/java/lightcontainer/utils/FileReceiver.java b/app/src/main/java/lightcontainer/utils/FileReceiver.java index f852587..634e5ec 100644 --- a/app/src/main/java/lightcontainer/utils/FileReceiver.java +++ b/app/src/main/java/lightcontainer/utils/FileReceiver.java @@ -3,9 +3,11 @@ package lightcontainer.utils; import java.io.*; 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) { try { @@ -16,8 +18,8 @@ public class FileReceiver { AES_GCM.encryptStream(input, bufferedStream, fileSize, key, iv); } } - return (int)file.length(); // TODO change the size to LONG - } catch(IOException | AES_GCM.AesGcmException ex) { + return (int) file.length(); // TODO change the size to LONG + } catch (IOException | AES_GCM.AesGcmException ex) { ex.printStackTrace(); return -1; } @@ -32,7 +34,7 @@ public class FileReceiver { bosFile = new BufferedOutputStream(new FileOutputStream(String.format("%s/%s", path, fileName))); long currentOffset = 0; - while((currentOffset < fileSize) && ((bytesReceived = input.read(buffer)) > 0)) { + while ((currentOffset < fileSize) && ((bytesReceived = input.read(buffer)) > 0)) { bosFile.write(buffer, 0, bytesReceived); currentOffset += bytesReceived; } @@ -40,9 +42,14 @@ public class FileReceiver { bosFile.close(); return true; - } catch(Exception ex) { + } catch (Exception ex) { ex.printStackTrace(); - if(bosFile != null) { try { bosFile.close(); } catch(Exception e) {} } + if (bosFile != null) { + try { + bosFile.close(); + } catch (Exception e) { + } + } return false; } } diff --git a/app/src/main/java/lightcontainer/utils/FileSender.java b/app/src/main/java/lightcontainer/utils/FileSender.java index 227855d..fe97aa3 100644 --- a/app/src/main/java/lightcontainer/utils/FileSender.java +++ b/app/src/main/java/lightcontainer/utils/FileSender.java @@ -3,23 +3,25 @@ package lightcontainer.utils; import java.io.*; public class FileSender { - private static final int DEFAULT_BUFFER=8000; + private static final int DEFAULT_BUFFER = 8000; 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 { BufferedInputStream bisFile; System.out.printf("Envoie fichier : %s - %s - %s \n", filename, aesKey, iv); try { File f = new File(String.format("%s/%s", path, filename)); - if(f.exists()) { + if (f.exists()) { bisFile = new BufferedInputStream(new FileInputStream(f)); AES_GCM.decryptStream(bisFile, out, fileSize, aesKey, iv); return true; } else return false; - } catch(IOException | AES_GCM.AesGcmException ex) { + } catch (IOException | AES_GCM.AesGcmException ex) { throw new IOException(); } } @@ -30,19 +32,20 @@ public class FileSender { try { File file = new File(String.format("%s/%s", path, filename)); long fileSize = file.length(); - if(file.exists()) { + if (file.exists()) { byte[] buffer = new byte[DEFAULT_BUFFER]; bisFile = new BufferedInputStream(new FileInputStream(file)); long currentOffset = 0; - while((currentOffset < fileSize) && (bytesReaded = bisFile.read(buffer)) > 0) { - out.write(buffer, 0, bytesReaded); out.flush(); - currentOffset+= bytesReaded; + while ((currentOffset < fileSize) && (bytesReaded = bisFile.read(buffer)) > 0) { + out.write(buffer, 0, bytesReaded); + out.flush(); + currentOffset += bytesReaded; } bisFile.close(); return true; } else return false; - } catch(IOException ex) {// todo change + } catch (IOException ex) {// todo change throw ex; } } diff --git a/app/src/main/java/lightcontainer/utils/NetChooser.java b/app/src/main/java/lightcontainer/utils/NetChooser.java index d7ebcbe..d46de32 100644 --- a/app/src/main/java/lightcontainer/utils/NetChooser.java +++ b/app/src/main/java/lightcontainer/utils/NetChooser.java @@ -18,7 +18,7 @@ public class NetChooser { public NetworkInterface requestInterface() { Scanner console = new Scanner(System.in); String[] allInterfaceNames = getInterfaces(); - for(int index=0; index < allInterfaceNames.length; ++index) { + for (int index = 0; index < allInterfaceNames.length; ++index) { System.out.printf("%d. %s\n", index, allInterfaceNames[index]); } System.out.printf("Select your interface :"); @@ -35,28 +35,28 @@ public class NetChooser { NetworkInterface currentInterface = discoveredInterfaces.nextElement(); Enumeration inetAddresses = currentInterface.getInetAddresses(); int ipCount = 0; - while(inetAddresses.hasMoreElements()) { + while (inetAddresses.hasMoreElements()) { InetAddress currentAddress = inetAddresses.nextElement(); ipCount++; } - if(ipCount > 0) + if (ipCount > 0) interfaces.add(currentInterface); } - } catch(SocketException ex) { + } catch (SocketException ex) { ex.printStackTrace(); } } public NetworkInterface getInterfacesByIndex(int i) { - if(i >= 0) + if (i >= 0) return interfaces.get(i); else return null; } public String[] getInterfaces() { - if(interfaces.size() > 0) { + if (interfaces.size() > 0) { String[] result = new String[interfaces.size()]; for (int i = 0; i < interfaces.size(); ++i) { result[i] = interfaces.get(i).getDisplayName() + " --> " + interfaces.get(i).getName(); diff --git a/app/src/main/java/lightcontainer/utils/SHA.java b/app/src/main/java/lightcontainer/utils/SHA.java index 25cd806..5c1963a 100644 --- a/app/src/main/java/lightcontainer/utils/SHA.java +++ b/app/src/main/java/lightcontainer/utils/SHA.java @@ -13,10 +13,9 @@ import java.util.Base64; /** * SHA 256 Hashing and borrowing Class [DO NOT EDIT] * - * @since 1.0 - * @version 1.0 - * * @author Jérémi Nihart + * @version 1.0 + * @since 1.0 */ public class SHA { // Constants @@ -42,12 +41,10 @@ public class SHA { /** * Make a borrowing of the stream. * - * @param in InputStream to the input, flux to hash. - * @param fileSize Stream/file size. - * - * @return Borrowing of the full current flux. - * - * @throws ShaException if an error occur. + * @param in InputStream to the input, flux to hash. + * @param fileSize Stream/file size. + * @return Borrowing of the full current flux. + * @throws ShaException if an error occur. */ public static String hashStream(InputStream in, long fileSize) throws ShaException { StringBuilder sb = new StringBuilder(); @@ -58,7 +55,7 @@ public class SHA { // Init Digest algo MessageDigest digest = MessageDigest.getInstance(SHA_VERSION); // Process flux - while ((currentSize < fileSize) && (bytes=in.read(buffer)) > 0) { + while ((currentSize < fileSize) && (bytes = in.read(buffer)) > 0) { digest.update(buffer, 0, bytes); currentSize += bytes; } @@ -77,12 +74,10 @@ public class SHA { /** * Make a borrowing of the file. * - * @param rootPath Root path of the file. - * @param fileName File Name. - * - * @return Borrowing of the file. - * - * @throws ShaException if an error occur. + * @param rootPath Root path of the file. + * @param fileName File Name. + * @return Borrowing of the file. + * @throws ShaException if an error occur. */ public static String hashFile(String rootPath, String fileName) throws ShaException { try { @@ -109,7 +104,7 @@ public class SHA { * which propagates the error triggering * a crash of the hash system. * - * @param e Previous exception throwable. + * @param e Previous exception throwable. */ public ShaException(Throwable e) { super(e);