Skip to content

Commit

Permalink
change to vavr.io.control.Try.
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinBetanc0urt committed Feb 24, 2024
1 parent 3957fca commit a0c0639
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions base/src/org/adempiere/pipo/CreateZipFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.adempiere.pipo;


import io.vavr.control.Try;
import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
Expand All @@ -29,6 +30,7 @@
import org.apache.tools.ant.taskdefs.GZip;
import org.apache.tools.ant.taskdefs.Tar;
import org.apache.tools.ant.taskdefs.Zip;

/**
* Compress package
*
Expand Down Expand Up @@ -100,28 +102,28 @@ static public void unpackFile(File zipFilepath, File destinationDir)
Unzipper.execute();
}


static public String getParentDir(File zipFilepath) throws IOException
{
String fileName = "";
ZipFile zipFile = null;
try {
zipFile = new ZipFile(zipFilepath);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
ZipEntry entry = entries.nextElement();
File tempfile = new File(entry.getName());
while (tempfile.getParent()!=null) {
tempfile = tempfile.getParentFile();
}
fileName = tempfile.getName();
} catch (IOException ioe) {
System.err.println("Unhandled exception:");
ioe.printStackTrace();
} finally {
if (zipFile != null) {
zipFile.close();
}
}
return fileName;
Try<String> result = Try.withResources(() -> {
return new ZipFile(zipFilepath);
})
.of(zipFile -> {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
ZipEntry entry = entries.nextElement();
File tempfile = new File(entry.getName());
while (tempfile.getParent()!=null) {
tempfile = tempfile.getParentFile();
}
return tempfile.getName();
})
.onFailure(ioError -> {
System.err.println("Error reading file: " + ioError.getMessage());
ioError.printStackTrace();
})
;

return result.get();
}

} // CreateZipFile

0 comments on commit a0c0639

Please sign in to comment.