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
Open
kiwi1969
wants to merge
26
commits into
openmainframeproject:release-5.0.1
Choose a base branch
from
kiwi1969:15-can-you-please-add-support-to-decompress-to-zipoutputstream
base: release-5.0.1
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
994d300
Update README.md
kiwi1969 4b22ad3
Update pom.xml
kiwi1969 5708147
Handle gzip output files
kiwi1969 abcb9c6
Handle gzip output files
kiwi1969 23cdcdc
Handle gzip output files
kiwi1969 9ab9bc5
Handle gzip output files
kiwi1969 2ebc0ce
Update README.md
kiwi1969 fc0333c
Update pom.xml
kiwi1969 01a884c
Update TerseDecompress.java
kiwi1969 e0d6cd4
Update TerseDecompress.java
kiwi1969 1b4f1eb
Update pom.xml
kiwi1969 521c136
Update README.md
kiwi1969 65c942b
Update README.md
kiwi1969 e390069
Update .gitignore
kiwi1969 2065481
Update pom.xml
kiwi1969 39b0095
Update TerseDecompress.java
kiwi1969 0bf3a24
Update pom.xml
kiwi1969 d45495b
Create .editorconfig
kiwi1969 a647500
Update .editorconfig
kiwi1969 6d1f194
Update .gitignore
kiwi1969 a9b96c3
Update TerseDecompress.java
kiwi1969 414657d
Update TerseDecompress.java
kiwi1969 a07cdbf
Update TerseDecompress.java
kiwi1969 04a155d
Update TerseDecompress.java
kiwi1969 5b3761f
Update TerseDecompress.java
kiwi1969 6a04989
Update TerseDecompress.java
kiwi1969 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,17 +36,28 @@ | |
/*****************************************************************************/ | ||
|
||
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> is provided, it will default to either\n" | ||
+" 1) if <input file.trs> then <input file>\n" | ||
+" 2) if <input file> and text mode, then <input file.txt>\n" | ||
+" 3) if <input file> and binary mode, then <input file.bin>\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,58 +66,72 @@ private void printUsageAndExit() { | |
} | ||
|
||
private void process (String args[]) throws Exception { | ||
|
||
String inputFileName = null; | ||
String outputFileName = null; | ||
boolean textMode = true; | ||
|
||
if (args.length == 0) | ||
{ | ||
printUsageAndExit(); | ||
} | ||
parseArgs(args); | ||
|
||
for (int i=0; i < args.length; i++) | ||
{ | ||
if (args[i].equals("-h") || args[i].equals("--help")) | ||
{ | ||
printUsageAndExit(); | ||
} | ||
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 | ||
else if (outputFileName == null) | ||
{ | ||
outputFileName = args[i]; | ||
} | ||
else // we have more args than we know what to do with | ||
{ | ||
printUsageAndExit(); | ||
} | ||
} | ||
if (inputFileName == null || outputFileName == null) | ||
{ | ||
if (isHelpRequested == true) | ||
printUsageAndExit(); | ||
|
||
if (inputFileName == null) | ||
printUsageAndExit(); | ||
} | ||
|
||
if (outputFileName == null) { | ||
if (inputFileName.toLowerCase().endsWith(".trs") ) | ||
outputFileName = inputFileName.substring(0, inputFileName.length() - 4); | ||
else { | ||
if (textMode) | ||
outputFileName = inputFileName.concat(".txt"); | ||
else | ||
outputFileName = inputFileName.concat(".bin"); | ||
} | ||
} | ||
|
||
System.out.println("Attempting to decompress input file (" + inputFileName + ") to output file (" + outputFileName + ")"); | ||
|
||
TerseDecompresser outputWriter = null; | ||
try { | ||
if (outputFileName.endsWith(".gz")) | ||
outputWriter = TerseDecompresser.create(new FileInputStream(inputFileName), new GZIPOutputStream(new FileOutputStream(outputFileName), 8192, true)); | ||
else | ||
outputWriter = TerseDecompresser.create(new FileInputStream(inputFileName), new FileOutputStream(outputFileName)); | ||
|
||
outputWriter.TextFlag = textMode; | ||
outputWriter.decode(); | ||
} | ||
catch( IOException e) { | ||
System.out.println("Got exception while decompressing input file (" + inputFileName + ").\nError message:\n" + e.toString()); | ||
} | ||
finally { | ||
if (outputWriter != null) | ||
outputWriter.close(); | ||
} | ||
|
||
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 output file name | ||
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. |
||
break; | ||
} | ||
} | ||
} | ||
|
||
public static void main (String args[]) throws Exception { | ||
|
||
TerseDecompress tersed = new TerseDecompress(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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