Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
EsotericEnderman committed Nov 2, 2024
1 parent 75f395a commit c4e8501
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package foundation.esoteric.utility.byte

import java.security.MessageDigest
import foundation.esoteric.utility.string.getSha1Hash
import foundation.esoteric.utility.file.getSha1Hash
import java.io.File

/**
* This method returns the SHA-1 hash of this `ByteArray`.
* This method calculates and returns the SHA-1 hash of this `ByteArray`.
* @return The SHA-1 hash of this `ByteArray`
* @see String.getSha1Hash
* @see File.getSha1Hash
* @author Esoteric Enderman
*/
fun ByteArray.getSha1Hash(): String {
val bytes = MessageDigest.getInstance("SHA-1").digest(this)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package foundation.esoteric.utility.file

import foundation.esoteric.utility.byte.getSha1Hash
import foundation.esoteric.utility.string.getSha1Hash
import net.lingala.zip4j.ZipFile
import java.io.File
import java.io.IOException
Expand All @@ -12,6 +13,11 @@ import java.nio.file.Path
* - The directory contains only **recursively empty** directories.
*
* Note that this `File` **must** be a directory to use this method.
* @return Whether this directory is **recursively empty**.
* @throws IllegalArgumentException If this directory does not exist.
* @throws IllegalArgumentException If this `File` is not a directory.
* @see Path.isRecursivelyEmpty
* @author Esoteric Enderman
*/
fun File.isRecursivelyEmpty(): Boolean {
require(this.exists()) { "The specified directory does not exist." }
Expand Down Expand Up @@ -43,15 +49,27 @@ fun File.isRecursivelyEmpty(): Boolean {
* - The directory contains only **recursively empty** directories.
*
* Note that this `Path` **must** lead to a directory to use this method.
* @return Whether the directory that this path leads to is **recursively empty**.
* @throws IllegalArgumentException If the file that this path leads to does not exist.
* @throws IllegalArgumentException If this `Path` does not lead to a directory.
* @see File.isRecursivelyEmpty
* @author Esoteric Enderman
*/
fun Path.isRecursivelyEmpty(): Boolean {
return this.toFile().isRecursivelyEmpty()
}

/**
* This method returns the SHA-1 hash of this `File`.
* This method computes and returns the SHA-1 hash of this `File`.
*
* Note that this `File` must not be a directory for this method to work.
* @return The SHA-1 hash of this `File`.
* @throws IllegalArgumentException If this `File` does not exist.
* @throws IllegalArgumentException If this `File` is a directory.
* @see Path.getSha1Hash
* @see String.getSha1Hash
* @see ByteArray.getSha1Hash
* @author Esoteric Enderman
*/
fun File.getSha1Hash(): String {
require(this.exists()) { "File does not exist." }
Expand All @@ -66,6 +84,13 @@ fun File.getSha1Hash(): String {
* This method returns the SHA-1 hash of the file that this `Path` leads to.
*
* Note that this `Path` must not lead to a directory for this method to work.
* @return The SHA-1 hash of the file that this `Path` leads to.
* @throws IllegalArgumentException If the file does not exist.
* @throws IllegalArgumentException If the file is a directory.
* @see File.getSha1Hash
* @see String.getSha1Hash
* @see ByteArray.getSha1Hash
* @author Esoteric Enderman
*/
fun Path.getSha1Hash(): String {
return this.toFile().getSha1Hash()
Expand All @@ -74,6 +99,10 @@ fun Path.getSha1Hash(): String {
/**
* This method creates a zip archive of the directory that this `File` represents and outputs it at the specified location parameter `zipFile`.
* @param zipFile The `File` location of where to output the zip archive.
* @throws IllegalArgumentException If this directory does not exist.
* @throws IllegalArgumentException If this file is not a directory.
* @see Path.zipFolder
* @author Esoteric Enderman
*/
@Throws(IOException::class)
fun File.zipFolder(zipFile: File) {
Expand All @@ -96,6 +125,10 @@ fun File.zipFolder(zipFile: File) {
/**
* This method creates a zip archive of the directory that this `Path` leads to and outputs it at the specified location parameter `zipFilePath`.
* @param zipFilePath The `Path` that specifies the output of the zip archive.
* @throws IllegalArgumentException If the directory that this `Path` leads to does not exist.
* @throws IllegalArgumentException If the file that this `Path` leads to is not a directory.
* @see File.zipFolder
* @author Esoteric Enderman
*/
@Throws(IOException::class)
fun Path.zipFolder(zipFilePath: Path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import java.util.jar.JarFile
/**
* This method loops through the subfolder of the **resources** folder specified by this `Path` and returns the `Path`s of all files stored in said subfolder.
* @return A set of all the paths of all files stored in the subfolder specified by this `Path`.
* @return The `Path`s of all files stored in this subfolder.
* @throws IllegalArgumentException If this `Path` does not lead to a valid resource.
* @see Path.saveResource
* @author Esoteric Enderman
*/
fun Path.getResourceFilePaths(): Set<Path> {
val filePaths = mutableSetOf<Path>()
Expand Down Expand Up @@ -54,7 +58,10 @@ fun Path.getResourceFilePaths(): Set<Path> {

/**
* This method saves the resource in the "resources" folder specified by this `Path` to the file specified as the `outputPath`.
* @param outputPath The path to the output file.
* @param outputPath The `Path` to the output file.
* @return The `Path`s of all files stored in this subfolder.
* @throws IllegalArgumentException If this `Path` does not lead to a valid resource.
* @author Esoteric Enderman
*/
fun Path.saveResource(outputPath: Path) {
val resourceStream: InputStream? = object {}.javaClass.classLoader.getResourceAsStream(this.toString())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package foundation.esoteric.utility.string

import foundation.esoteric.utility.byte.getSha1Hash
import foundation.esoteric.utility.file.getSha1Hash
import java.io.File

/**
* This method returns the SHA-1 hash of this `String`.
* @return The SHA-1 hash of this `String`
* @see ByteArray.getSha1Hash
* @see File.getSha1Hash
* @author Esoteric Enderman
*/
fun String.getSha1Hash(): String {
return this.toByteArray().getSha1Hash()
Expand Down

0 comments on commit c4e8501

Please sign in to comment.