java Class Inflater call from Matlab Command Window

2 ビュー (過去 30 日間)
Stefano Gianoli
Stefano Gianoli 2016 年 11 月 23 日
編集済み: Stefano Gianoli 2016 年 11 月 25 日
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 Center および File ExchangeCall Java from MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by