diff --git a/InternalWorkingOfSpringBoot/.gitattributes b/InternalWorkingOfSpringBoot/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/InternalWorkingOfSpringBoot/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/InternalWorkingOfSpringBoot/.gitignore b/InternalWorkingOfSpringBoot/.gitignore new file mode 100644 index 0000000..667aaef --- /dev/null +++ b/InternalWorkingOfSpringBoot/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/InternalWorkingOfSpringBoot/.mvn/wrapper/maven-wrapper.properties b/InternalWorkingOfSpringBoot/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..c0bcafe --- /dev/null +++ b/InternalWorkingOfSpringBoot/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,3 @@ +wrapperVersion=3.3.4 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip diff --git a/InternalWorkingOfSpringBoot/mvnw b/InternalWorkingOfSpringBoot/mvnw new file mode 100755 index 0000000..bd8896b --- /dev/null +++ b/InternalWorkingOfSpringBoot/mvnw @@ -0,0 +1,295 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.4 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +scriptDir="$(dirname "$0")" +scriptName="$(basename "$0")" + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +actualDistributionDir="" + +# First try the expected directory name (for regular distributions) +if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then + if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then + actualDistributionDir="$distributionUrlNameMain" + fi +fi + +# If not found, search for any directory with the Maven executable (for snapshots) +if [ -z "$actualDistributionDir" ]; then + # enable globbing to iterate over items + set +f + for dir in "$TMP_DOWNLOAD_DIR"/*; do + if [ -d "$dir" ]; then + if [ -f "$dir/bin/$MVN_CMD" ]; then + actualDistributionDir="$(basename "$dir")" + break + fi + fi + done + set -f +fi + +if [ -z "$actualDistributionDir" ]; then + verbose "Contents of $TMP_DOWNLOAD_DIR:" + verbose "$(ls -la "$TMP_DOWNLOAD_DIR")" + die "Could not find Maven distribution directory in extracted archive" +fi + +verbose "Found extracted Maven distribution directory: $actualDistributionDir" +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/InternalWorkingOfSpringBoot/mvnw.cmd b/InternalWorkingOfSpringBoot/mvnw.cmd new file mode 100644 index 0000000..92450f9 --- /dev/null +++ b/InternalWorkingOfSpringBoot/mvnw.cmd @@ -0,0 +1,189 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.4 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' + +$MAVEN_M2_PATH = "$HOME/.m2" +if ($env:MAVEN_USER_HOME) { + $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" +} + +if (-not (Test-Path -Path $MAVEN_M2_PATH)) { + New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null +} + +$MAVEN_WRAPPER_DISTS = $null +if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { + $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" +} else { + $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" +} + +$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" +$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +$actualDistributionDir = "" + +# First try the expected directory name (for regular distributions) +$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" +$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" +if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { + $actualDistributionDir = $distributionUrlNameMain +} + +# If not found, search for any directory with the Maven executable (for snapshots) +if (!$actualDistributionDir) { + Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { + $testPath = Join-Path $_.FullName "bin/$MVN_CMD" + if (Test-Path -Path $testPath -PathType Leaf) { + $actualDistributionDir = $_.Name + } + } +} + +if (!$actualDistributionDir) { + Write-Error "Could not find Maven distribution directory in extracted archive" +} + +Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/InternalWorkingOfSpringBoot/pom.xml b/InternalWorkingOfSpringBoot/pom.xml new file mode 100644 index 0000000..839db57 --- /dev/null +++ b/InternalWorkingOfSpringBoot/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.5.6 + + + com.nexDew + InternalWorkingOfSpringBoot + 0.0.1-SNAPSHOT + InternalWorkingOfSpringBoot + Demo project for Spring Boot + + + + + + + + + + + + + + + 17 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/InternalWorkingOfSpringBoot/src/main/java/com/nexDew/InternalWorkingOfSpringBoot/InternalWorkingOfSpringBootApplication.java b/InternalWorkingOfSpringBoot/src/main/java/com/nexDew/InternalWorkingOfSpringBoot/InternalWorkingOfSpringBootApplication.java new file mode 100644 index 0000000..01acdcf --- /dev/null +++ b/InternalWorkingOfSpringBoot/src/main/java/com/nexDew/InternalWorkingOfSpringBoot/InternalWorkingOfSpringBootApplication.java @@ -0,0 +1,27 @@ +package com.nexDew.InternalWorkingOfSpringBoot; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class InternalWorkingOfSpringBootApplication implements CommandLineRunner { + + public static void main(String[] args) { + SpringApplication.run(InternalWorkingOfSpringBootApplication.class, args); + } + + public InternalWorkingOfSpringBootApplication(PaymentService paymentService) { + this.paymentService = paymentService; + } + + private PaymentService paymentService; + + @Override + public void run(String... args) throws Exception { + String payment = paymentService.payment(); + System.out.println("Payment done :"+payment); + + } +} + diff --git a/InternalWorkingOfSpringBoot/src/main/java/com/nexDew/InternalWorkingOfSpringBoot/PaymentService.java b/InternalWorkingOfSpringBoot/src/main/java/com/nexDew/InternalWorkingOfSpringBoot/PaymentService.java new file mode 100644 index 0000000..e84d0ad --- /dev/null +++ b/InternalWorkingOfSpringBoot/src/main/java/com/nexDew/InternalWorkingOfSpringBoot/PaymentService.java @@ -0,0 +1,5 @@ +package com.nexDew.InternalWorkingOfSpringBoot; + +public interface PaymentService { + String payment(); +} diff --git a/InternalWorkingOfSpringBoot/src/main/java/com/nexDew/InternalWorkingOfSpringBoot/PaytmPayment.java b/InternalWorkingOfSpringBoot/src/main/java/com/nexDew/InternalWorkingOfSpringBoot/PaytmPayment.java new file mode 100644 index 0000000..9034235 --- /dev/null +++ b/InternalWorkingOfSpringBoot/src/main/java/com/nexDew/InternalWorkingOfSpringBoot/PaytmPayment.java @@ -0,0 +1,16 @@ +package com.nexDew.InternalWorkingOfSpringBoot; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Component; + +@Component +@ConditionalOnProperty(name = "payment.provider", havingValue = "Paytm") +public class PaytmPayment implements PaymentService { + public String payment(){ + String payment = "Paytm"; + System.out.println("Payment from: "+payment); + return payment; + } + + +} diff --git a/InternalWorkingOfSpringBoot/src/main/java/com/nexDew/InternalWorkingOfSpringBoot/PhonePayPayment.java b/InternalWorkingOfSpringBoot/src/main/java/com/nexDew/InternalWorkingOfSpringBoot/PhonePayPayment.java new file mode 100644 index 0000000..7c25705 --- /dev/null +++ b/InternalWorkingOfSpringBoot/src/main/java/com/nexDew/InternalWorkingOfSpringBoot/PhonePayPayment.java @@ -0,0 +1,15 @@ +package com.nexDew.InternalWorkingOfSpringBoot; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Component; + +@Component +@ConditionalOnProperty(name = "payment.provider", havingValue = "PhonePay") +public class PhonePayPayment implements PaymentService{ + public String payment(){ + String payment = "PhonePay"; + System.out.println("PhonePay from: "+payment); + return payment; + } + +} diff --git a/InternalWorkingOfSpringBoot/src/main/resources/application.properties b/InternalWorkingOfSpringBoot/src/main/resources/application.properties new file mode 100644 index 0000000..6098fb6 --- /dev/null +++ b/InternalWorkingOfSpringBoot/src/main/resources/application.properties @@ -0,0 +1,2 @@ +spring.application.name=InternalWorkingOfSpringBoot +payment.provider=Paytm diff --git a/InternalWorkingOfSpringBoot/src/test/java/com/nexDew/InternalWorkingOfSpringBoot/InternalWorkingOfSpringBootApplicationTests.java b/InternalWorkingOfSpringBoot/src/test/java/com/nexDew/InternalWorkingOfSpringBoot/InternalWorkingOfSpringBootApplicationTests.java new file mode 100644 index 0000000..e5454ee --- /dev/null +++ b/InternalWorkingOfSpringBoot/src/test/java/com/nexDew/InternalWorkingOfSpringBoot/InternalWorkingOfSpringBootApplicationTests.java @@ -0,0 +1,13 @@ +package com.nexDew.InternalWorkingOfSpringBoot; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class InternalWorkingOfSpringBootApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/JavaFileHandling/CSVActions.java b/JavaFileHandling/CSVActions.java new file mode 100644 index 0000000..0facbba --- /dev/null +++ b/JavaFileHandling/CSVActions.java @@ -0,0 +1,243 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.Comparator; +import java.util.List; +import java.util.Scanner; + +public class CSVActions { + // 1. Create CSV File + public static void CreateCSVFile(String CsvFilePath) throws IOException { + File file = new File(CsvFilePath); + if(file.createNewFile()){ + System.out.println("File Created... "+CsvFilePath); + }else { + System.out.println("File Already Exist.. "+CsvFilePath); + } +// // Write Sample Data +// FileWriter writer = new FileWriter(CsvFilePath); +// writer.write("Name, Age, City\n"); +// writer.write("Gaurav, 25, New York\n"); +// writer.write("Mannu, 30, London\n"); +// writer.close(); +// System.out.println("Data written to file successfully..."); + + } + // Read CSV File + public static void ReadCsvFile(String CsvFilePath) throws FileNotFoundException { + File file = new File(CsvFilePath); + Scanner scanner = new Scanner(file); + scanner.useDelimiter(","); + while(scanner.hasNext()){ + System.out.print(scanner.next()+"\t"); + } + scanner.close(); + } + // Write to CSV File + public static void WriteToCsvFile(String csvFilePath, String data) throws IOException { + try (FileWriter writer = new FileWriter(csvFilePath, true)) { + writer.append(data).append("\n"); + System.out.println("Row added: " + data); + } + } + public static void SearchInCsvFile(String csvFilePath, String keyword) throws FileNotFoundException { + try (Scanner scanner = new Scanner(new File(csvFilePath))) { + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + if (line.toLowerCase().contains(keyword.toLowerCase())) { + System.out.println("Found: " + line); + return; + } + } + System.out.println("No record found for: " + keyword); + } + } + public static void UpdateCsvRecord(String csvFilePath, String oldValue, String newValue) throws IOException { + File file = new File(csvFilePath); + StringBuilder content = new StringBuilder(); + + try (Scanner scanner = new Scanner(file)) { + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + content.append(line.replace(oldValue, newValue)).append("\n"); + } + } + + try (FileWriter writer = new FileWriter(file)) { + writer.write(content.toString()); + } + + System.out.println("Updated all '" + oldValue + "' to '" + newValue + "'"); + } + public static void DeleteCsvRecord(String csvFilePath, String keyword) throws IOException { + File inputFile = new File(csvFilePath); + StringBuilder newContent = new StringBuilder(); + + try (Scanner scanner = new Scanner(inputFile)) { + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + if (!line.contains(keyword)) { + newContent.append(line).append("\n"); + } + } + } + + try (FileWriter writer = new FileWriter(inputFile)) { + writer.write(newContent.toString()); + } + + System.out.println("Deleted records containing: " + keyword); + } + public static void CountCsvRecords(String csvFilePath) throws FileNotFoundException { + int count = 0; + try (Scanner scanner = new Scanner(new File(csvFilePath))) { + while (scanner.hasNextLine()) { + scanner.nextLine(); + count++; + } + } + System.out.println("Total rows (including header): " + count); + } + public static void GetCsvHeaders(String csvFilePath) throws IOException { + try (Scanner scanner = new Scanner(new File(csvFilePath))) { + if (scanner.hasNextLine()) { + System.out.println("Header: " + scanner.nextLine()); + } + } + } + public static void DisplayCsvAsTable(String csvFilePath) throws FileNotFoundException { + try (Scanner scanner = new Scanner(new File(csvFilePath))) { + scanner.useDelimiter("[,\n]"); + int col = 0; + while (scanner.hasNext()) { + System.out.printf("%-15s", scanner.next()); + col++; + if (col == 3) { // 3 columns + System.out.println(); + col = 0; + } + } + } + } + + + public static void BackupCsvFile(String csvFilePath, String backupPath) throws IOException { + Path src = Paths.get(csvFilePath); + Path dest = Paths.get(backupPath); + Files.copy(src, dest, StandardCopyOption.REPLACE_EXISTING); + System.out.println("Backup created at: " + backupPath); + } + + + public static void SortCsvByColumn(String csvFilePath, int columnIndex) throws IOException { + List lines = Files.readAllLines(Paths.get(csvFilePath)); + String header = lines.remove(0); + + lines.sort(Comparator.comparing(line -> line.split(",")[columnIndex])); + lines.add(0, header); + + Files.write(Paths.get(csvFilePath), lines); + System.out.println("CSV sorted by column index: " + columnIndex); + } + public static void main(String[] args) throws IOException { + Scanner sc = new Scanner(System.in); + String filePath = "/Users/mannu/Desktop/FileHandling/MyFiles/User.csv"; + String backupPath = "/Users/mannu/Desktop/FileHandling/MyFiles/Backup/User_Backup.csv"; + while (true) { + System.out.println("\n========== CSV FILE MANAGEMENT =========="); + System.out.println("1. Create CSV File"); + System.out.println("2. Write to CSV File"); + System.out.println("3. Read CSV File"); + System.out.println("4. Search in CSV File"); + System.out.println("5. Update CSV Record"); + System.out.println("6. Delete CSV Record"); + System.out.println("7. Count CSV Records"); + System.out.println("8. Get CSV Headers"); + System.out.println("9. Display CSV as Table"); + System.out.println("10. Backup CSV File"); + System.out.println("11. Sort CSV by Column"); + System.out.println("12. Exit"); + System.out.print("Enter your choice: "); + int choice = sc.nextInt(); + sc.nextLine(); // consume newline + + switch (choice) { + case 1: + CSVActions.CreateCSVFile(filePath); + break; + + case 2: + System.out.print("Enter Name: "); + String name = sc.nextLine(); + System.out.print("Enter Age: "); + String age = sc.nextLine(); + System.out.print("Enter City: "); + String city = sc.nextLine(); + String data = name + "," + age + "," + city; + CSVActions.WriteToCsvFile(filePath, data); + break; + + case 3: + CSVActions.ReadCsvFile(filePath); + break; + + case 4: + System.out.print("Enter keyword to search: "); + String keyword = sc.nextLine(); + CSVActions.SearchInCsvFile(filePath, keyword); + break; + + case 5: + System.out.print("Enter old value: "); + String oldValue = sc.nextLine(); + System.out.print("Enter new value: "); + String newValue = sc.nextLine(); + CSVActions.UpdateCsvRecord(filePath, oldValue, newValue); + break; + + case 6: + System.out.print("Enter keyword to delete: "); + String keyToDelete = sc.nextLine(); + CSVActions.DeleteCsvRecord(filePath, keyToDelete); + break; + + case 7: + CSVActions.CountCsvRecords(filePath); + break; + + case 8: + CSVActions.GetCsvHeaders(filePath); + break; + + case 9: + CSVActions.DisplayCsvAsTable(filePath); + break; + + case 10: + CSVActions.BackupCsvFile(filePath, backupPath); + break; + + case 11: + System.out.print("Enter column index (0 for Name, 1 for Age, 2 for City): "); + int colIndex = sc.nextInt(); + CSVActions.SortCsvByColumn(filePath, colIndex); + break; + + case 12: + System.out.println("Exiting... šŸ‘‹"); + sc.close(); + System.exit(0); + break; + + default: + System.out.println("āŒ Invalid choice! Please try again."); + } + + } + } +} diff --git a/JavaFileHandling/FileActions.java b/JavaFileHandling/FileActions.java new file mode 100644 index 0000000..ea76f23 --- /dev/null +++ b/JavaFileHandling/FileActions.java @@ -0,0 +1,328 @@ +import java.io.*; +import java.nio.file.*; +import java.util.Scanner; + +public class FileActions { + + // 1.Create a File + public static String CreateFile(String filePath) throws IOException { + File file = new File(filePath); + return file.createNewFile() ? "File Created: " + filePath : " File Already Exists."; + } + + // 2.Check if File Exists + public static String FileExistOrNot(String filePath) { + File file = new File(filePath); + return file.exists() ? "File Exists: " + filePath : " File Not Found."; + } + + // 3.Write to File (overwrite) + public static void WriteFile(String filePath) throws IOException { + try (FileWriter fw = new FileWriter(filePath)) { + fw.write("Welcome to Java File Handling!\nThis file was written using FileWriter."); + System.out.println("File written successfully."); + } + } + + // 4.Append to File (add content without overwriting) + public static void AppendToFile(String filePath, String data) throws IOException { + try (FileWriter fw = new FileWriter(filePath, true)) { + fw.write(data + "\n"); + System.out.println("Appended data: " + data); + } + } + + // 5.Read File (using Scanner) + public static void ReadFile(String filePath) throws FileNotFoundException { + try (Scanner sc = new Scanner(new File(filePath))) { + while (sc.hasNextLine()) { + System.out.println(sc.nextLine()); + } + } + } + + // 6.Read File Using BufferedReader (efficient) + public static void ReadFileByBuffer(String filePath) throws IOException { + try (BufferedReader br = new BufferedReader(new FileReader(filePath))) { + String line; + while ((line = br.readLine()) != null) { + System.out.println(line); + } + } + } + + // 7.Rename File + public static String RenameFile(String oldPath, String newPath) { + File oldFile = new File(oldPath); + File newFile = new File(newPath); + return oldFile.renameTo(newFile) ? " File Renamed Successfully." : " Rename Failed."; + } + + // 8.Delete File + public static String DeleteFile(String filePath) { + File file = new File(filePath); + return file.delete() ? "šŸ—‘ļø File Deleted Successfully." : "Delete Failed."; + } + + // 9.Copy File + public static void CopyFile(String sourcePath, String destPath) throws IOException { + Files.copy(Paths.get(sourcePath), Paths.get(destPath), StandardCopyOption.REPLACE_EXISTING); + System.out.println(" File Copied Successfully!"); + } + + // 10.Move File + public static void MoveFile(String sourcePath, String destPath) throws IOException { + Files.move(Paths.get(sourcePath), Paths.get(destPath), StandardCopyOption.REPLACE_EXISTING); + System.out.println(" File Moved Successfully!"); + } + + // 11. Count Lines in File + public static void CountFileLines(String filePath) throws IOException { + int count = 0; + try (BufferedReader br = new BufferedReader(new FileReader(filePath))) { + while (br.readLine() != null) count++; + } + System.out.println(" Total Lines: " + count); + } + + // 12. Get File Details (Metadata) + public static void GetFileDetails(String filePath) { + File file = new File(filePath); + if (file.exists()) { + System.out.println(" File Details:"); + System.out.println("Name: " + file.getName()); + System.out.println("Path: " + file.getAbsolutePath()); + System.out.println("Size: " + file.length() + " bytes"); + System.out.println("Readable: " + file.canRead()); + System.out.println("Writable: " + file.canWrite()); + System.out.println("Executable: " + file.canExecute()); + System.out.println("Last Modified: " + file.lastModified()); + } else { + System.out.println(" File not found!"); + } + } + + // 13. List Files in Directory + public static void ListFilesInDirectory(String folderPath) { + File folder = new File(folderPath); + File[] files = folder.listFiles(); + if (files != null) { + System.out.println(" Files in Directory:"); + for (File f : files) { + System.out.println((f.isDirectory() ? "[DIR] " : "[FILE] ") + f.getName()); + } + } else { + System.out.println(" Directory not found!"); + } + } + + // 14. Write Multiple Lines + public static void WriteMultipleLines(String filePath, String[] lines) throws IOException { + try (BufferedWriter bw = new BufferedWriter(new FileWriter(filePath))) { + for (String line : lines) { + bw.write(line); + bw.newLine(); + } + } + System.out.println(" Multiple lines written successfully!"); + } + + // 15. File Permissions + public static void FilePermissions(String filePath) { + File file = new File(filePath); + if (file.exists()) { + System.out.println(" File Permissions:"); + System.out.println("Readable: " + file.canRead()); + System.out.println("Writable: " + file.canWrite()); + System.out.println("Executable: " + file.canExecute()); + } else { + System.out.println("File not found!"); + } + } + + // 16. Replace Word in File + public static void ReplaceWordInFile(String filePath, String oldWord, String newWord) throws IOException { + File file = new File(filePath); + StringBuilder content = new StringBuilder(); + + try (Scanner sc = new Scanner(file)) { + while (sc.hasNextLine()) { + content.append(sc.nextLine().replace(oldWord, newWord)).append("\n"); + } + } + + try (FileWriter writer = new FileWriter(file)) { + writer.write(content.toString()); + } + + System.out.println("Replaced '" + oldWord + "' with '" + newWord + "' successfully!"); + } + + // 17. Delete Directory Recursively + public static void DeleteDirectory(String folderPath) { + File folder = new File(folderPath); + if (folder.isDirectory()) { + for (File sub : folder.listFiles()) { + if (sub.isDirectory()) DeleteDirectory(sub.getAbsolutePath()); + else sub.delete(); + } + } + folder.delete(); + System.out.println("Directory deleted: " + folderPath); + } + + // 18. Search Word in File + public static void SearchWordInFile(String filePath, String keyword) throws FileNotFoundException { + File file = new File(filePath); + int lineNumber = 1; + try (Scanner sc = new Scanner(file)) { + boolean found = false; + while (sc.hasNextLine()) { + String line = sc.nextLine(); + if (line.toLowerCase().contains(keyword.toLowerCase())) { + System.out.println(" Found '" + keyword + "' at line " + lineNumber + ": " + line); + found = true; + } + lineNumber++; + } + if (!found) System.out.println("Word not found: " + keyword); + } + } + + public static void main(String[] args) throws IOException { + Scanner sc = new Scanner(System.in); + String baseFolder = "/Users/mannu/Desktop/FileHandling/MyFiles/"; + String filePath = baseFolder + "User.txt"; + String newFilePath = baseFolder + "User_Renamed.txt"; + String backupPath = baseFolder + "Backup/User_Backup.txt"; + String movedPath = baseFolder + "Moved/User_Moved.txt"; + + System.out.println(" FILE HANDLING MANAGER STARTED SUCCESSFULLY!"); + + while (true) { + System.out.println("\n========== FILE HANDLING MENU =========="); + System.out.println("1. Create File"); + System.out.println("2. Check if File Exists"); + System.out.println("3. Write to File"); + System.out.println("4. Append to File"); + System.out.println("5. Read File"); + System.out.println("6. Rename File"); + System.out.println("7. Get File Details"); + System.out.println("8. Count File Lines"); + System.out.println("9. Replace Word in File"); + System.out.println("10. Search Word in File"); + System.out.println("11. Check File Permissions"); + System.out.println("12. Copy File"); + System.out.println("13. Move File"); + System.out.println("14. List Files in Directory"); + System.out.println("15. Write Multiple Lines"); + System.out.println("16. Exit"); + System.out.print("\n Enter your choice: "); + + int choice; + if (sc.hasNextInt()) { + choice = sc.nextInt(); + } else { + System.out.println(" Please enter a valid number!"); + sc.nextLine(); + continue; + } + sc.nextLine(); // consume newline + + try { + switch (choice) { + case 1: + System.out.println(FileActions.CreateFile(filePath)); + break; + + case 2: + System.out.println(FileActions.FileExistOrNot(filePath)); + break; + + case 3: + FileActions.WriteFile(filePath); + break; + + case 4: + System.out.print("Enter text to append: "); + String appendData = sc.nextLine(); + FileActions.AppendToFile(filePath, appendData); + break; + + case 5: + System.out.println("\nšŸ“– Reading File:"); + FileActions.ReadFile(filePath); + break; + + case 6: + System.out.println(FileActions.RenameFile(filePath, newFilePath)); + break; + + case 7: + System.out.println("\nšŸ“„ File Details:"); + FileActions.GetFileDetails(newFilePath); + break; + + case 8: + FileActions.CountFileLines(newFilePath); + break; + + case 9: + System.out.print("Enter old word: "); + String oldWord = sc.nextLine(); + System.out.print("Enter new word: "); + String newWord = sc.nextLine(); + FileActions.ReplaceWordInFile(newFilePath, oldWord, newWord); + break; + + case 10: + System.out.print("Enter word to search: "); + String keyword = sc.nextLine(); + FileActions.SearchWordInFile(newFilePath, keyword); + break; + + case 11: + FileActions.FilePermissions(newFilePath); + break; + + case 12: + FileActions.CopyFile(newFilePath, backupPath); + break; + + case 13: + FileActions.MoveFile(newFilePath, movedPath); + break; + + case 14: + System.out.println("\nšŸ“‚ Files in Directory:"); + FileActions.ListFilesInDirectory(baseFolder); + break; + + case 15: + System.out.println("Enter number of lines to write: "); + int n = sc.nextInt(); + sc.nextLine(); + String[] lines = new String[n]; + for (int i = 0; i < n; i++) { + System.out.print("Line " + (i + 1) + ": "); + lines[i] = sc.nextLine(); + } + FileActions.WriteMultipleLines(baseFolder + "MultiLine.txt", lines); + break; + + case 16: + System.out.println("\nšŸ‘‹ Exiting File Manager... Goodbye!"); + sc.close(); + System.exit(0); + break; + + default: + System.out.println("Invalid choice! Please try again."); + } + } catch (Exception e) { + System.out.println(" Error: " + e.getMessage()); + } + + } + } +} \ No newline at end of file diff --git a/JavaFileHandling/FolderActions.java b/JavaFileHandling/FolderActions.java new file mode 100644 index 0000000..a176909 --- /dev/null +++ b/JavaFileHandling/FolderActions.java @@ -0,0 +1,97 @@ +import java.io.File; +import java.util.Scanner; + +public class FolderActions { + + // 1. Create Folder + public static void CreateFolder(String folderPath){ + File folder = new File(folderPath); + if(!folder.exists()){ + folder.mkdir(); + System.out.println("Folder Created... "+folderPath); + } + } + + // 2. Check folder is Exist or Not + public static String FolderExistOrNot(String folderPath){ + File folder = new File(folderPath); + boolean exists = folder.exists(); + return exists ? "File Already exist.. "+folderPath: "File not exist.."; + } + + // 3. Update Folder Name + public static String UpdateFolderName(String oldFolderPath,String newFolderPath){ + File oldFolder = new File(oldFolderPath); + File newFolder = new File(newFolderPath); + return oldFolder.exists() + ? (oldFolder.renameTo(newFolder) ? "File name Renamed.. "+newFolderPath: "Rename Failed") + : "File does Not Exist..."; + } + + // 4. Delete Folder + public static String DeleteFolder(String folderPath){ + File folder = new File(folderPath); + + return folder.exists() ? + (folder.delete() ? "File deleted Successfully.. "+folderPath: "Deletion Failed..!") + : "Folder not Exist.."; + } + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + String baseFolder = "/Users/mannu/Desktop/FileHandling/"; + String folderPath = baseFolder + "MyFiles"; + String newFolderPath = baseFolder + "MyFiles_Renamed"; + + System.out.println(" FOLDER HANDLING MANAGER STARTED SUCCESSFULLY!"); + while(true){ + System.out.println("\n========== FOLDER HANDLING MENU =========="); + System.out.println("1. Create Folder"); + System.out.println("2. Check if Folder Exists"); + System.out.println("3. Raname Folder Name"); + System.out.println("4. Delete Folder Name"); + System.out.println("5. List Files in Directory"); + System.out.println("6. Delete Directory Recursively"); + System.out.println("7. Backup Directory"); + System.out.println("8. Exit"); + System.out.println("Welcome to FileHandling project!"); + System.out.print(" Enter your choice: "); + + int choice; + if(sc.hasNextInt()){ + choice=sc.nextInt(); + } + else{ + System.out.println("Invalid Choice! Please try again."); + continue; + } + sc.nextLine(); + try{ + switch (choice){ + case 1: + FolderActions.CreateFolder(folderPath); + break; + case 2: + System.out.println(FolderActions.FolderExistOrNot(folderPath)); + break; + case 3: + System.out.println(FolderActions.UpdateFolderName(folderPath, newFolderPath)); + break; + case 4: + System.out.println(FolderActions.DeleteFolder(folderPath)); + break; + default: + System.out.println("Invalid Choice! Please try again."); + break; + } + + } catch (Exception e) { + throw new RuntimeException(e); + } + + } + + } + + +} diff --git a/JavaFileHandling/UserInfo.java b/JavaFileHandling/UserInfo.java new file mode 100644 index 0000000..cb85083 --- /dev/null +++ b/JavaFileHandling/UserInfo.java @@ -0,0 +1,40 @@ +import java.io.*; +import java.util.Scanner; + +public class UserInfo { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + String fileName = "user_info.txt"; + + // Step 1: Take username and store it + System.out.print("Enter your name to store in file or press Enter to skip: "); + String userName = scanner.nextLine(); + + if (!userName.isEmpty()) { + try (FileWriter writer = new FileWriter(fileName, true)) { + writer.write(userName + "\n"); + System.out.println("Name saved successfully!"); + } catch (IOException e) { + System.out.println("Error writing to file: " + e.getMessage()); + } + } + + // Step 2: Ask if user wants to display all names + System.out.print("Do you want to see all user names? (y/n): "); + String showInfo = scanner.nextLine(); + + if (showInfo.equalsIgnoreCase("y")) { + try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) { + System.out.println("\nšŸ“‹ Saved User Names:"); + String line; + while ((line = reader.readLine()) != null) { + System.out.println(line.trim()); + } + } catch (IOException e) { + System.out.println("Error reading file: " + e.getMessage()); + } + } + + scanner.close(); + } +} \ No newline at end of file diff --git a/programming-language b/programming-language new file mode 160000 index 0000000..da8cb8f --- /dev/null +++ b/programming-language @@ -0,0 +1 @@ +Subproject commit da8cb8fc9397c56e4877a8be9934b2fd118f396a