java Class Inflater call from Matlab Command Window

3 次查看(过去 30 天)
From Java documentation on the web page:
I can get the following code compiled and running in java:
// Encode a String into bytes
String inputString = "blahblahblah??";
byte[] input = inputString.getBytes("UTF-8");
// Compress the bytes
byte[] output = new byte[100];
Deflater compresser = new Deflater();
compresser.setInput(input);
compresser.finish();
int compressedDataLength = compresser.deflate(output);
However, when I am writing this appropriately adapted for Matlab Command Window:
import java.util.zip.Inflater
% Encode a String into bytes
inputString = javaObject('java.lang.String','blahblahblah??');
input = inputString.getBytes('UTF-8');
% Compress the bytes
output = javaArray('java.lang.Byte',100);
compresser = java.util.zip.Deflater();
compresser.setInput(input);
compresser.finish();
compressedDataLength = compresser.deflate(output);
I got for the last line of code the following error message:
No method 'deflate' with matching signature found for class 'java.util.zip.Deflater'.
The signature of the class is the correct one as it takes
java.lang.Byte[]
as it can be seen with the command:
methodsview(compresser)
Any ideas why does not work?

回答(1 个)

Stefano Gianoli
Stefano Gianoli 2016-11-25
编辑:Stefano Gianoli 2016-11-25
The following Matlab newsreader threads:
as well as the in these threads mentioned Matlab File Exchange contributions:
plus this Matlab File exchange contribution:
addressed me to a possible workaround.
Workaround: Use java.io.ByteArrayOutputStream() and java.util.zip.DeflaterOutputStream(,)
import java.util.zip.Inflater
% Encode a String into bytes
inputString = javaObject('java.lang.String','blahblahblah??');
input = inputString.getBytes('UTF-8');
% Compress the bytes
output = java.io.ByteArrayOutputStream();
compresser = java.util.zip.Deflater();
outstrm = java.util.zip.DeflaterOutputStream(output,compresser);
outstrm.write(input);
compresser.finish();
outstrm.close();
% output to ByteArray
output.toByteArray()
% output to String
output.toString()
Still, I have no explanation why the Matlab line of code:
compressedDataLength = compresser.deflate(output);
in the context of the above question, should produce an error.

类别

Help CenterFile Exchange 中查找有关 Java Package Integration 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by