Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Load variable from java InputStream
Date: Thu, 15 Nov 2012 22:34:17 +0000 (UTC)
Organization: Authentix Inc
Lines: 13
Message-ID: <k83ql8$pi$1@newscl01ah.mathworks.com>
References: <i5p4v1$5kp$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1353018857 818 172.30.248.48 (15 Nov 2012 22:34:17 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 15 Nov 2012 22:34:17 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 3067624
Xref: news.mathworks.com comp.soft-sys.matlab:782884

I was looking at the same problem and discovered a solution that uses java.io.ByteArrayOutputStream.  This is an output stream that gathers bytes and then you can request them as a byte array.  I use streamCopier just like it is used in extractArchive.m, to copy from the zip entry to the ByteArrayOutputStream.

entry = zipFile.getEntry('myentry.txt');
stream = zipFile.getInputStream(entry);
byteoutstream = java.io.ByteArrayOutputStream();
streamCopier = com.mathworks.mlwidgets.io.InterruptibleStreamCopier.getInterruptibleStreamCopier;
streamCopier.copyStream(stream, byteoutstream);
sbytes = byteoutstream.toByteArray();
ubytes = uint8(int16(sbytes) + 256*int16(sbytes < 0));

Since toByteArray() returns (signed) int8 and I want uint8, I manually apply the wrap-around at the end.

-Jamie