Giter VIP home page Giter VIP logo

sprint1_t5_javautils's Introduction

Sprint1_T5_JavaUtils

java -version

Level 1

Java can be used exclusively, or the Apache Commons IO library if you prefer.

  • Exercise 1

Create a class that alphabetically lists the contents of a directory received by parameter.

javac src/n1Exe1/App.java
java -cp src n1Exe1.App
  • Exercise 2

Add to the class from the previous exercise, the functionality to list a directory tree with the contents of all its levels (recursively) so that they are printed to the screen in alphabetical order within each level, also indicating whether it is a directory (D) or a file (F), and its last modified date.

javac src/n1Exe2/App.java
java -cp src n1Exe2.App
  • Exercise 3

Modify the previous exercise. Now, instead of displaying the result on the screen, it saves the result in a TXT file.

javac src/n1Exe3/App.java
java -cp src n1Exe3.App
  • Exercise 4

Adds the functionality to read any TXT file and display its contents by console.

javac src/n1Exe4/App.java
java -cp src n1Exe4.App
  • Exercise 5

Now the program needs to serialize a Java Object to a .ser file and then deserialize it.

javac src/n1Exe5/App.java
java -cp src n1Exe5.App

Level 2

  • Exercise 1

Run exercise 3 from the previous level by parameterizing all methods in a configuration file.

You can use a Java Properties file, or the Apache Commons Configuration library if you prefer.

From the previous exercise, parameterize the following:

Directory to read.

Name and directory of the resulting TXT file.

javac src/n2Exe1/App.java
java -cp src n2Exe1.App

Level 3

  • Exercise 1

Create a utility that encrypts and decrypts the files resulting from the previous levels.

Use AES algorithm in ECB or CBC working mode with PKCS5Padding padding method. Either javax.crypto or org.apache.commons.crypto can be used.

javac src/n3Exe1/App.java
java -cp src n3Exe1.App

sprint1_t5_javautils's People

Watchers

 avatar

sprint1_t5_javautils's Issues

[Documenting] Set of Exception caught on n3Exe1.AESCypher class

Security:

import java.security.InvalidKeyException;
This is the exception for invalid Keys (invalid encoding, wrong length, uninitialized, etc).

import java.security.NoSuchAlgorithmException;
This exception is thrown when a particular cryptographic algorithm is requested but is not available in the environment.

Crypto:
import javax.crypto.BadPaddingException;
This exception is thrown when a particular padding mechanism is expected for the input data but the data is not padded properly.

import javax.crypto.IllegalBlockSizeException;
This exception is thrown when the length of data provided to a block cipher is incorrect, i.e., does not match the block size of the cipher.

import javax.crypto.NoSuchPaddingException;
This exception is thrown when a particular padding mechanism is requested but is not available in the environment.

Wrong/incomplete Exception management

Nivel 1 Ex3-Ex4-Ex5 Nivel 2 y Nivel 3:

  • La firma del método dice que este este podría arrojar una excepción, sin embargo lo que se hace es capturarla:
public void readDirectoryFromBackup () throws IOException {

		try {

			FileReader input = new FileReader 

					("directoryBackup.txt");

			BufferedReader buffer = new BufferedReader(input);

			String line = "";

			while (line != null) {

				line = buffer.readLine();

				System.out.print(line + "\n");

			}

			buffer.close();

		} catch (IOException event) {

			System.out.println(FILE_NOT_FOUND_MSG);


		}


	}
public void readDirectoryFromBackup () throws IOException {

		try {

			FileReader input = new FileReader 

					("directoryBackup.txt");

			BufferedReader buffer = new BufferedReader(input);

			String line = "";

			while (line != null) {

				line = buffer.readLine();

				System.out.print(line + "\n");

			}

			buffer.close();

		} catch (IOException event) {

			System.err.println(FILE_NOT_FOUND_MSG);

		}

	}
```

public void serializeDirectoryToFile () throws IOException {

	try {

		FileOutputStream fileOutputStream = new FileOutputStream("directoryBackup.ser");

		ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);

		objectOutputStream.writeObject(this);

		objectOutputStream.close();

	} catch (IOException e) {

		System.err.println(FILE_NOT_FOUND_MSG);

	}

}


	```
public void desSeriaizeDirectoryFromFileToObject () throws IOException, ClassNotFoundException {

		try {

			FileInputStream fileOutputStream = new FileInputStream("directoryBackup.ser");

			ObjectInputStream objectInputStream = new ObjectInputStream(fileOutputStream);

			DirectoryAlphabeticList desSerializedDirectoryAlphaList = (DirectoryAlphabeticList) objectInputStream.readObject();

			objectInputStream.close();

			for (String s : desSerializedDirectoryAlphaList.getDirectoryList()) {

				System.out.println(s);

			}


		} catch (IOException | ClassNotFoundException e) {

			System.err.println(FILE_NOT_FOUND_MSG);

		}

	} 

Improves properties file creation, read, load, etc. The resources involved should close

Actual:

private static final long serialVersionUID = 1L;
private Properties properties;
AESCypher encrypter;
private File dir;
private ArrayList<String> directoryList;
private final String FILE_NOT_FOUND_MSG = "File not found";

public DirectoryAlphabeticList(File dir) {
	properties = new Properties();
	loadDirectoryAlphabeticListProperties();
	encrypter = new AESCypher();
	directoryList = new ArrayList<String>();
	this.dir = dir;
}



private void loadDirectoryAlphabeticListProperties() {
	try {
		this.properties.load(new FileReader("file.properties"));
	} catch (IOException e) {
		System.err.println(FILE_NOT_FOUND_MSG);
	}
}

Please check: https://www.baeldung.com/java-properties

Adds README.md

The exercises of the 3 levels must be executed from the command line, and not only from the editor. Create a file called "readme.txt" to explain the command to execute in each exercise.

Cristian code review

@christianamor3

https://github.com/christianamor3/Especializacion-Java-BackEnd/tree/master/S1T5

Feedback:

exe1:

general

  • usar err, en lugar de out on print
  • guardar los mensajes que se repitan en variables finales como atributo de clase puede que guste

//

Method private createKey says that it throws an exception, but it is not doing so

Nivel 3:

  • El método dice que arroja una excepción, pero no lo está haciendo:
private SecretKeySpec createKey (String key) throws UnsupportedEncodingException, NoSuchAlgorithmException {


		byte[] keyEncryption = key.getBytes("UTF-8");


		MessageDigest sha = MessageDigest.getInstance("SHA-1");


		keyEncryption = sha.digest(keyEncryption);

		keyEncryption = Arrays.copyOf(keyEncryption, 16);


		SecretKeySpec secretKey = new SecretKeySpec(keyEncryption,"AES");


		return secretKey;

	}

Check:

public String encrypt (String data, String key) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException {

public String desencrypt (String encryptedData, String key) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException {

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.