Hi while upgrading to commons-compress-1.26.2 jar found that commons-lang3-3.14.0 or above jars is compatible with this version.
But now i am getting this error
Exception in thread “main” java.lang.NoSuchMethodError: org.apache.commons.lang3.StringUtils.getIfEmpty(Ljava/lang/CharSequence;Ljava/util/function/Supplier;)Ljava/lang/CharSequence;
at org.apache.commons.lang3.SystemProperties.getProperty(SystemProperties.java:774)
at org.apache.commons.lang3.SystemProperties.getProperty(SystemProperties.java:755)
at org.apache.commons.lang3.SystemProperties.getOsName(SystemProperties.java:718)
at org.apache.commons.compress.archivers.tar.TarArchiveEntry.normalizeFileName(TarArchiveEntry.java:231)
at org.apache.commons.compress.archivers.tar.TarArchiveEntry.(TarArchiveEntry.java:490)
What is causing this error? Any Lead?
And this is the java code that is triggering this error
** TarArchiveEntry entry = new TarArchiveEntry(file, “/” + file.getName());**
I have tried with this code
String installFilePath = “output.tar.gz”;
// List of files to add to the tar.gz archive
File[] files = {
new File("Text3"),
new File("Text4")
};
// Initialize output streams
FileOutputStream fOut = null;
BufferedOutputStream bOut = null;
GzipCompressorOutputStream gzOut = null;
TarArchiveOutputStream tOut = null;
try {
// Create the final tar.gz file
File finalTarFile = new File(installFilePath);
fOut = new FileOutputStream(finalTarFile);
bOut = new BufferedOutputStream(fOut);
gzOut = new GzipCompressorOutputStream(bOut);
tOut = new TarArchiveOutputStream(gzOut);
// Loop through the files and add each to the tar.gz archive
for (int i = 0; i < files.length; i++) {
File file = files[i];
// Create a new TarArchiveEntry
TarArchiveEntry entry = new TarArchiveEntry(file, "/" + file.getName());
tOut.putArchiveEntry(entry);
// Write the file content to the archive
try (FileInputStream fis = new FileInputStream(file)) {
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
tOut.write(buffer, 0, length);
}
}
// Close the current entry
tOut.closeArchiveEntry();
}
// Finish the tar output stream
tOut.finish();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
// Close all streams
if (tOut != null) tOut.close();
if (gzOut != null) gzOut.close();
if (bOut != null) bOut.close();
if (fOut != null) fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
sujithra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.