From 5b01530fcebacc2ee021d08f017a688bb4831ce7 Mon Sep 17 00:00:00 2001 From: "Begerad, Stefan" Date: Wed, 2 Mar 2022 22:05:34 +0100 Subject: [PATCH] feat(lines-br): initial commit --- lines-buffered-reader/.gitignore | 31 +++++++ lines-buffered-reader/pom.xml | 86 +++++++++++++++++++ .../main/java/de/swingbe/lines_br/Main.java | 53 ++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 lines-buffered-reader/.gitignore create mode 100644 lines-buffered-reader/pom.xml create mode 100644 lines-buffered-reader/src/main/java/de/swingbe/lines_br/Main.java diff --git a/lines-buffered-reader/.gitignore b/lines-buffered-reader/.gitignore new file mode 100644 index 0000000..33653da --- /dev/null +++ b/lines-buffered-reader/.gitignore @@ -0,0 +1,31 @@ + +# Files +.classpath +.externalToolBuilders +.gradle +.project +.pydevproject +.settings +.sonar +*~ +*.ipr +*.iml +*.iws +*.swp +*.DS_Store +*.snap.debug +dependency-reduced-pom.xml + +# Directories +.idea/ +.run/ +.venv/ +_site/ +build/ +dist/ +docs/_build/ +gen-java/ +gen-javabean/ +gen-py/ +node_modules/ +target/ diff --git a/lines-buffered-reader/pom.xml b/lines-buffered-reader/pom.xml new file mode 100644 index 0000000..5bfdab6 --- /dev/null +++ b/lines-buffered-reader/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + + lines_br + description + https://swingbe.de + de.swingbe + lines_br + 0.0.1 + jar + + + + GNU General Public License + https://www.gnu.org/licenses/gpl-3.0.txt + + + + + https://github.com/Software-Ingenieur-Begerad/sandbox-java + + + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + 11 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + package + + shade + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + true + + shaded + + + + + de.swingbe.lines_br.Main + + + + + + + + + + + diff --git a/lines-buffered-reader/src/main/java/de/swingbe/lines_br/Main.java b/lines-buffered-reader/src/main/java/de/swingbe/lines_br/Main.java new file mode 100644 index 0000000..7dd83c1 --- /dev/null +++ b/lines-buffered-reader/src/main/java/de/swingbe/lines_br/Main.java @@ -0,0 +1,53 @@ +package de.swingbe.lines_br; + +import java.io.*; + +public class Main { + + static void usage() { + System.err.println("usage: java Main file"); + System.exit(-1); + } + + public static void main(String[] args) { + System.out.println("Hello world!"); + + // parse arguments + if (args.length == 0 || args.length > 2) usage(); + + int fileArg = 0; + + // get lines count + try { + FileUtil fileUtil = new FileUtil(args[fileArg]); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + try { + System.out.println("No. of lines in file: " + FileUtil.getLineCount()); + } catch (IOException e) { + e.printStackTrace(); + } + return; + } +} + +class FileUtil { + static BufferedReader reader = null; + + public FileUtil(String filePath) throws FileNotFoundException { + File file = new File(filePath); + FileInputStream fileStream = new FileInputStream(file); + InputStreamReader input = new InputStreamReader(fileStream); + reader = new BufferedReader(input); + } + + public static int getLineCount() throws IOException { + int lineCount = 0; + String data; + while ((data = reader.readLine()) != null) { + lineCount++; + } + return lineCount; + } +} \ No newline at end of file