Browse code

Simplified master branch; working on pipes in dev

haywalk authored on 30/03/2021 11:44:32
Showing 6 changed files

1 1
Binary files a/PixelPoke.class and b/PixelPoke.class differ
... ...
@@ -12,8 +12,8 @@ public class PixelPoke {
12 12
 		// Create variables to store names of input and output files
13 13
 		String inputFileName = "";
14 14
 		String outputFileName = "";
15
-		
16
-		// See what was passed in as a command line argument or piped
15
+
16
+		// Get filename from arguments
17 17
 		if(args.length == 2) {
18 18
 			// If user specified an input file and output file, use those
19 19
 			inputFileName = args[0];
... ...
@@ -23,23 +23,7 @@ public class PixelPoke {
23 23
 			inputFileName = args[0];
24 24
 			outputFileName = inputFileName;
25 25
 		} else {
26
-			// If no arguments given, take filename from pipeline
27
-			BufferedReader pipeInput = new BufferedReader(new InputStreamReader(System.in));
28
-			String[] pipeArgs = pipeInput.readLine().split(" ");
29
-			// Use variables depending on input length
30
-			switch(pipeArgs.length){
31
-				case 1: 
32
-					inputFileName = pipeArgs[0];
33
-					outputFileName = inputFileName;
34
-					break;
35
-				case 2:
36
-					inputFileName = pipeArgs[0];
37
-					outputFileName = pipeArgs[1];
38
-					break;
39
-				default:
40
-					System.out.println("Invalid arguments\nUsage: negative [inputfile.jpg] [outputfile.jpg]");
41
-					System.exit(1);
42
-			}
26
+			inputError();
43 27
 		}
44 28
 		
45 29
 		// Create input and output files
... ...
@@ -53,8 +37,7 @@ public class PixelPoke {
53 37
 		try {
54 38
 			img = ImageIO.read(inputFile);
55 39
 		} catch(IOException e) {
56
-			System.out.println("Invalid arguments\nUsage: negative [inputfile.jpg] [outputfile.jpg]");
57
-			System.exit(1);
40
+			inputError();
58 41
 		}
59 42
 		
60 43
 		// Get the dimensions of the image
... ...
@@ -73,4 +56,10 @@ public class PixelPoke {
73 56
 		// Write the modified image to the output file
74 57
 		ImageIO.write(img, "jpg", outputFile);
75 58
 	}
59
+	
60
+	static void inputError() {
61
+		// Handles any input errors
62
+		System.out.println("Invalid arguments\nUsage: negative [inputfile.jpg] [outputfile.jpg]");
63
+		System.exit(1);
64
+	}
76 65
 }
... ...
@@ -1,5 +1,5 @@
1
-# PixelPoke
1
+# Negative
2 2
 
3 3
 This is a simple program that, when run, will take in an image file as an argument and create an inverted version of that image.
4 4
 
5
-Usage (in the directory with the .class file): `$ java PixelPoke [input.jpg] [output.jpg]` or if you follow the instructions in `pkg/`, you can use `$ negative [input.jpg] [output.jpg]`.
5
+Usage (in the directory with the `.class` file): `$ java PixelPoke [input.jpg] [output.jpg]` 
6 6
deleted file mode 100644
... ...
@@ -1 +0,0 @@
1
-If you put these two files somewhere in your path, you can run this program from anywhere, on any file. Make sure it's executable. Usage: `$ negative [input.jpg] [output.jpg]`
2 0
deleted file mode 100755
... ...
@@ -1,4 +0,0 @@
1
-#!/bin/sh
2
-DIRECTORY=`dirname $0`
3
-
4
-java -jar $DIRECTORY/negative.jar $1 $2
5 0
deleted file mode 100644
6 1
Binary files a/pkg/negative.jar and /dev/null differ