-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
major new feature: support array compression and decompression
- Loading branch information
Showing
12 changed files
with
410 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function output = base64decode(input) | ||
%BASE64DECODE Decode Base64 string to a byte array. | ||
% | ||
% output = base64decode(input) | ||
% | ||
% The function takes a Base64 string INPUT and returns a uint8 array | ||
% OUTPUT. JAVA must be running to use this function. The result is always | ||
% given as a 1-by-N array, and doesn't retrieve the original dimensions. | ||
% | ||
% See also base64encode | ||
% | ||
% Copyright (c) 2012, Kota Yamaguchi | ||
% URL: https://www.mathworks.com/matlabcentral/fileexchange/39526-byte-encoding-utilities | ||
% License : BSD, see LICENSE_*.txt | ||
% | ||
|
||
error(nargchk(1, 1, nargin)); | ||
error(javachk('jvm')); | ||
if ischar(input), input = uint8(input); end | ||
|
||
output = typecast(org.apache.commons.codec.binary.Base64.decodeBase64(input), 'uint8')'; | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function output = base64encode(input) | ||
%BASE64ENCODE Encode a byte array using Base64 codec. | ||
% | ||
% output = base64encode(input) | ||
% | ||
% The function takes a char, int8, or uint8 array INPUT and returns Base64 | ||
% encoded string OUTPUT. JAVA must be running to use this function. Note | ||
% that encoding doesn't preserve input dimensions. | ||
% | ||
% See also base64decode | ||
% | ||
% Copyright (c) 2012, Kota Yamaguchi | ||
% URL: https://www.mathworks.com/matlabcentral/fileexchange/39526-byte-encoding-utilities | ||
% License : BSD, see LICENSE_*.txt | ||
% | ||
|
||
error(nargchk(1, 1, nargin)); | ||
error(javachk('jvm')); | ||
if ischar(input), input = uint8(input); end | ||
|
||
output = char(org.apache.commons.codec.binary.Base64.encodeBase64Chunked(input))'; | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
function output = gzipdecode(input) | ||
%GZIPDECODE Decompress input bytes using GZIP. | ||
% | ||
% output = gzipdecode(input) | ||
% | ||
% The function takes a compressed byte array INPUT and returns inflated | ||
% bytes OUTPUT. The INPUT is a result of GZIPENCODE function. The OUTPUT | ||
% is always an 1-by-N uint8 array. JAVA must be enabled to use the function. | ||
% | ||
% See also gzipencode typecast | ||
% | ||
% Copyright (c) 2012, Kota Yamaguchi | ||
% URL: https://www.mathworks.com/matlabcentral/fileexchange/39526-byte-encoding-utilities | ||
% License : BSD, see LICENSE_*.txt | ||
% | ||
|
||
error(nargchk(1, 1, nargin)); | ||
error(javachk('jvm')); | ||
if ischar(input) | ||
warning('gzipdecode:inputTypeMismatch', ... | ||
'Input is char, but treated as uint8.'); | ||
input = uint8(input); | ||
end | ||
if ~isa(input, 'int8') && ~isa(input, 'uint8') | ||
error('Input must be either int8 or uint8.'); | ||
end | ||
|
||
gzip = java.util.zip.GZIPInputStream(java.io.ByteArrayInputStream(input)); | ||
buffer = java.io.ByteArrayOutputStream(); | ||
org.apache.commons.io.IOUtils.copy(gzip, buffer); | ||
gzip.close(); | ||
output = typecast(buffer.toByteArray(), 'uint8')'; | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function output = gzipencode(input) | ||
%GZIPENCODE Compress input bytes with GZIP. | ||
% | ||
% output = gzipencode(input) | ||
% | ||
% The function takes a char, int8, or uint8 array INPUT and returns | ||
% compressed bytes OUTPUT as a uint8 array. Note that the compression | ||
% doesn't preserve input dimensions. JAVA must be enabled to use the | ||
% function. | ||
% | ||
% See also gzipdecode typecast | ||
% | ||
% Copyright (c) 2012, Kota Yamaguchi | ||
% URL: https://www.mathworks.com/matlabcentral/fileexchange/39526-byte-encoding-utilities | ||
% License : BSD, see LICENSE_*.txt | ||
% | ||
|
||
error(nargchk(1, 1, nargin)); | ||
error(javachk('jvm')); | ||
if ischar(input), input = uint8(input); end | ||
if ~isa(input, 'int8') && ~isa(input, 'uint8') | ||
error('Input must be either char, int8 or uint8.'); | ||
end | ||
|
||
buffer = java.io.ByteArrayOutputStream(); | ||
gzip = java.util.zip.GZIPOutputStream(buffer); | ||
gzip.write(input, 0, numel(input)); | ||
gzip.close(); | ||
output = typecast(buffer.toByteArray(), 'uint8')'; | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.