java Class Inflater call from Matlab Command Window

3 visualizaciones (últimos 30 días)
Stefano Gianoli
Stefano Gianoli el 23 de Nov. de 2016
Editada: Stefano Gianoli el 25 de Nov. de 2016
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?

Respuestas (1)

Stefano Gianoli
Stefano Gianoli el 25 de Nov. de 2016
Editada: Stefano Gianoli el 25 de Nov. de 2016
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.

Categorías

Más información sobre Java Package Integration en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by