java Class Inflater call from Matlab Command Window

조회 수: 8 (최근 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 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