Closed RaymondLam1 closed 2 months ago
Sorry for the delayed reply. Turns out I didn't have email notifications enabled for the xz-java project.
The problem is that your code lacks xzOut.close()
.
If you didn't want to close fos
then xzOut.finish()
would be the right call. But in this example you want to close fos
too and xzOut.close()
does that.
Sorry for the delayed reply. Turns out I didn't have email notifications enabled for the xz-java project.
The problem is that your code lacks
xzOut.close()
.If you didn't want to close
fos
thenxzOut.finish()
would be the right call. But in this example you want to closefos
too andxzOut.close()
does that.
Thanks for your reply, I will try it.
Unfortunately, xzOut.close()
does not work. Actually, I use try with catch
, so xzOut.close()
is unnecessary. Maybe it is a bug ?
Actually, I use
try with catch
, soxzOut.close()
is unnecessary.
True, I didn't notice it, sorry. I haven't regularly used much beyond Java 5 features yet and I had a break from Java for three years. :-/
If I compress and decompress your two example JSON files, everything works correctly. Based on your code, I created a complete program that compresses to jdks.json.xz and the output is fine with both of your sample inputs. Thus, I cannot reproduce the problem with the information I currently have.
Note that the error message
Error 79 - Inappropriate file type or format.
is not from XZ for Java.
import java.io.; import java.nio.file.; import org.tukaani.xz.*;
class XZEncDemo { public void testXzCompress() throws IOException { String json = new String(Files.readAllBytes( Paths.get("jdks.json"))); compress(json); }
public void compress(String input) {
try (FileOutputStream fos = new FileOutputStream("jdks.json.xz");
XZOutputStream xzOut = new XZOutputStream(fos, new LZMA2Options())) {
byte[] jsonData = input.getBytes();
xzOut.write(jsonData);
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
}
public static void main(String[] args) throws Exception {
new XZEncDemo().testXzCompress();
}
}
I'm closing this because I cannot reproduce it and I don't have a reason to suspect a bug at XZ for Java. Please reopen if you have more information, especially if it is possible to have a small program to reproduce the issue. Thanks.
Describe the bug
I wrote a very simple program that uses json strings to generate an xz compressed file, but I found a puzzling bug.
When jdks.json is below, It will cause
Error 79 - Inappropriate file type or format.
when trying to open the generated jdks.json.xz in my mac.However, when jdk.json is below, The only difference is that a space is added after "jdks", It works well.
I'm not sure if this is a bug or a usage error on my part.
Version
1.9
Operating System
macOS Monterey
Relevant log output
No response