MATLAB Answers

java Class Inflater call from Matlab Command Window

조회 수: 2(최근 30일)
Stefano Gianoli
Stefano Gianoli 23 Nov 2016
편집: Stefano Gianoli 25 Nov 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?

  댓글 수: 0

로그인 to comment.

답변(1개)

Stefano Gianoli
Stefano Gianoli 25 Nov 2016
편집: Stefano Gianoli 25 Nov 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.

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그


Translated by