Skip to content
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
wants to merge 26 commits into
base: release-5.0.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions .editorconfig
@@ -0,0 +1,15 @@
# Declares that this is the top-level configuration

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Author

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

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
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -109,4 +109,6 @@ buildNumber.properties
.mvn/wrapper/maven-wrapper.jar
.flattened-pom.xml

# End of https://www.gitignore.io/api/java,maven,eclipse
# End of https://www.gitignore.io/api/java,maven,eclipse

.vscode
11 changes: 10 additions & 1 deletion README.md
Expand Up @@ -15,6 +15,15 @@ IBM Mainframe files on any workstation or laptop etc. that supports Java.

## Updates ##

**Version 5.0.2: March 2024**

- Added support to decompress then recompress into a gzip file if output-file name ends in ".gz"
- Updated pom.xml to have Maven compile using Java 17, and shade the jar.

**Version 5.0.1: July 2023**

- allow user to specify only <input file> for text files. Resulting <output file> will be <input file>.txt

**Version 5: March 2021**

- Support for variable length binary records. Variable length records processed in binary mode will be prefixed with a 4 byte field in the same format as the IBM RDW i.e. 2 byte record length field (including RDW length, big-endian) followed by 2 bytes of zeros.
Expand All @@ -25,7 +34,7 @@ For execution, TerseDecompress needs a JVM runtime environment.

Usage:

```java -jar tersedecompress-5.0.0.jar [-b] tersed-file output-file```
```java -jar tersedecompress-5.0.2.jar [-b] tersed-file output-file```

Default mode is text mode, which will attempt EBCDIC -> ASCII conversion.

Expand Down
52 changes: 46 additions & 6 deletions pom.xml
Expand Up @@ -5,31 +5,35 @@

<groupId>org.openmainframeproject.tersedecompress</groupId>
<artifactId>tersedecompress</artifactId>
<version>5.0.0</version>
<version>5.0.2</version>
<packaging>jar</packaging>

<name>tersedecompress</name>
<url>https://github.com/openmainframeproject/tersedecompress-testdata</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk-release>17</jdk-release>
<junit-version>4.13.2</junit-version>
<maven-compiler-version>3.12.1</maven-compiler-version>
<maven-jar-version>3.2.0</maven-jar-version>
<maven-shade-version>3.5.1</maven-shade-version>
<skipTests>true</skipTests>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>${maven-compiler-version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<release>${jdk-release}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<version>${maven-jar-version}</version>
<configuration>
<archive>
<manifest>
Expand All @@ -39,13 +43,49 @@
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<minimizeJar>true</minimizeJar>
<entryPoints>
<entryPoint>org.openmainframeproject.tersedecompress.TerseDecompress</entryPoint>
</entryPoints>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>org.openmainframeproject.tersedecompress.TerseDecompress</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Expand Up @@ -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);
Expand All @@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CAN BE IGNORED - check for isHelpRequested right after args.length, reasons:

  • faster in case of isHelpRequested
  • simpler to read code, as it first check simple things, later more complicated

Copy link
Author

Choose a reason for hiding this comment

The 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++)
{
Expand Down Expand Up @@ -95,18 +103,49 @@ else if (outputFileName == null)
printUsageAndExit();
}

System.out.println("Attempting to decompress input file (" + inputFileName +") to output file (" + outputFileName +")");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an example how it will be more streamlined:

Suggested change
System.out.println("Attempting to decompress input file (" + inputFileName +") to output file (" + outputFileName +")");
System.out.println("Opening output file (" + outputFileName + ")");
var outputStream = null;
try {
if (outputFileName.endsWith(".gz")) {
outputStream = new GZIPOutputStream(new FileOutputStream(outputFileName), 8192, true);
}
else {
outputStream = new FileOutputStream(outputFileName);
}
}
catch (Exception e) {
System.out.println("Got exception while opening output file (" + outputFileName + ").\nError message:\n" + e.toString());
}
System.out.println("Attempting to decompress input file (" + inputFileName + ") to output file (" + outputFileName + ")");
try (TerseDecompresser outputWriter = TerseDecompresser.create(new FileInputStream(inputFileName), outputStream)) {
outputWriter.TextFlag = textMode;
outputWriter.decode();
}
catch (Exception e) {
System.out.println("Got exception while decompressing input file (" + inputFileName + ").\nError message:\n" + e.toString());
}

Copy link
Author

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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" ?

Copy link
Author

Choose a reason for hiding this comment

The 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;

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The 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();
Expand Down