New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
15 can you please add support to decompress to zipoutputstream #18
base: release-5.0.1
Are you sure you want to change the base?
Changes from 19 commits
994d300
4b22ad3
5708147
abcb9c6
23cdcdc
9ab9bc5
2ebc0ce
fc0333c
01a884c
e0d6cd4
1b4f1eb
521c136
65c942b
e390069
2065481
39b0095
0bf3a24
d45495b
a647500
6d1f194
a9b96c3
414657d
a07cdbf
04a155d
5b3761f
6a04989
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Declares that this is the top-level configuration | ||
root = true | ||
|
||
# Applies to all files | ||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
# Applies to all Markdown files | ||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
# Applies to all C# and Java files, overriding rules declared before | ||
[*.{cs,java}] | ||
indent_size = 4 |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -36,17 +36,25 @@ | |||||||||||||||||||||||||||||||||||||||||||||
/*****************************************************************************/ | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
import java.io.*; | ||||||||||||||||||||||||||||||||||||||||||||||
import java.util.zip.GZIPOutputStream; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
class TerseDecompress { | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
private static final String DetailedHelp = new String( | ||||||||||||||||||||||||||||||||||||||||||||||
"Usage: \"TerseDecompress <input file> <output file> [-b]\"\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||
+"Java TerseDecompress will decompress a file compressed using the terse program on z/OS\n" | ||||||||||||||||||||||||||||||||||||||||||||||
+"Default mode is text mode, which will attempt EBCDIC -> ASCII conversion\n" | ||||||||||||||||||||||||||||||||||||||||||||||
+"The -b flag turns on binary mode, no conversion will be attempted\n" | ||||||||||||||||||||||||||||||||||||||||||||||
+"If no <output file> provided in text mode, it will default to <input file>.txt\n" | ||||||||||||||||||||||||||||||||||||||||||||||
+"Options:\n" | ||||||||||||||||||||||||||||||||||||||||||||||
+"-b flag turns on binary mode, no conversion will be attempted\n" | ||||||||||||||||||||||||||||||||||||||||||||||
+"-h or --help prints this message\n" | ||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
private static final String Version = new String ("Version 5, March 2021"); | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
private static final String Version = new String ("Version 6, March 2024"); | ||||||||||||||||||||||||||||||||||||||||||||||
private String inputFileName = null; | ||||||||||||||||||||||||||||||||||||||||||||||
private String outputFileName = null; | ||||||||||||||||||||||||||||||||||||||||||||||
private boolean isHelpRequested = false; | ||||||||||||||||||||||||||||||||||||||||||||||
private boolean textMode = true; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
private void printUsageAndExit() { | ||||||||||||||||||||||||||||||||||||||||||||||
System.out.println(DetailedHelp); | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -55,15 +63,15 @@ private void printUsageAndExit() { | |||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
private void process (String args[]) throws Exception { | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
String inputFileName = null; | ||||||||||||||||||||||||||||||||||||||||||||||
String outputFileName = null; | ||||||||||||||||||||||||||||||||||||||||||||||
boolean textMode = true; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
if (args.length == 0) | ||||||||||||||||||||||||||||||||||||||||||||||
parseArgs(args); | ||||||||||||||||||||||||||||||||||||||||||||||
if (args.length == 0 || (inputFileName == null && outputFileName == null) || (outputFileName == null && textMode == false) || isHelpRequested == true) | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CAN BE IGNORED - check for isHelpRequested right after args.length, reasons:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Um, this is the other dude's change I merged with. Updated |
||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||
printUsageAndExit(); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
if (outputFileName == null) { | ||||||||||||||||||||||||||||||||||||||||||||||
outputFileName = inputFileName + ".txt"; | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
for (int i=0; i < args.length; i++) | ||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -95,18 +103,49 @@ else if (outputFileName == null) | |||||||||||||||||||||||||||||||||||||||||||||
printUsageAndExit(); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
System.out.println("Attempting to decompress input file (" + inputFileName +") to output file (" + outputFileName +")"); | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is an example how it will be more streamlined:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
if (outputFileName.endsWith(".gz")) { | ||||||||||||||||||||||||||||||||||||||||||||||
try (TerseDecompresser outputWriter = TerseDecompresser.create(new FileInputStream(inputFileName), new GZIPOutputStream(new FileOutputStream(outputFileName), 8192, true))) | ||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||
outputWriter.TextFlag = textMode; | ||||||||||||||||||||||||||||||||||||||||||||||
outputWriter.decode(); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
else { | ||||||||||||||||||||||||||||||||||||||||||||||
try (TerseDecompresser outputWriter = TerseDecompresser.create(new FileInputStream(inputFileName), new FileOutputStream(outputFileName))) | ||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||
outputWriter.TextFlag = textMode; | ||||||||||||||||||||||||||||||||||||||||||||||
outputWriter.decode(); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
try (TerseDecompresser outputWriter | ||||||||||||||||||||||||||||||||||||||||||||||
= TerseDecompresser.create(new FileInputStream(inputFileName), new FileOutputStream(outputFileName))) | ||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||
outputWriter.TextFlag = textMode; | ||||||||||||||||||||||||||||||||||||||||||||||
System.out.println("Attempting to decompress input file (" + inputFileName +") to output file (" + outputFileName +")"); | ||||||||||||||||||||||||||||||||||||||||||||||
outputWriter.decode(); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
System.out.println("Processing completed"); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
private void parseArgs(String args[]) { | ||||||||||||||||||||||||||||||||||||||||||||||
for (int i = 0; i < args.length; i++) { | ||||||||||||||||||||||||||||||||||||||||||||||
if (args[i].equals("-h") || args[i].equals("--help")) { | ||||||||||||||||||||||||||||||||||||||||||||||
isHelpRequested = true; | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
else if (args[i].equals("-b")) { | ||||||||||||||||||||||||||||||||||||||||||||||
textMode = false; | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
// first non-flag argument is the input file name | ||||||||||||||||||||||||||||||||||||||||||||||
else if (inputFileName == null) { | ||||||||||||||||||||||||||||||||||||||||||||||
inputFileName = args[i]; | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
// second non-flag argument is the input file name | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like typo, should it be "second non-flag argument is the output file name" ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is part of the other guy's change I merged with. Updated now |
||||||||||||||||||||||||||||||||||||||||||||||
else if (outputFileName == null) { | ||||||||||||||||||||||||||||||||||||||||||||||
outputFileName = args[i]; | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
else // we have more args than we know what to do with | ||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||
isHelpRequested = true; | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets call break here, as there is no point to run more this loop There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this was the previous dudes change I was asked to merged with. Updated. |
||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
public static void main (String args[]) throws Exception { | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
TerseDecompress tersed = new TerseDecompress(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add .editorconfig to .gitignore too, as it is per developer to setup own
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note this now means that the default tabsize when viewing in github is 8, which was what I was initially trying to correct