Skip to content

Commit 8fd183e

Browse files
committed
[io] update embedded IO toolboxes: jsonlab, jnifty, jsnirfy, easyh5
1 parent 0d31813 commit 8fd183e

22 files changed

+999
-97
lines changed

gzipdecode.m

+2-6
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,15 @@
3636
if (nargin == 0)
3737
error('you must provide at least 1 input');
3838
end
39-
40-
nozmat = getvarfrom({'caller', 'base'}, 'NO_ZMAT');
41-
42-
if ((exist('zmat', 'file') == 2 || exist('zmat', 'file') == 3) && (isempty(nozmat) || nozmat == 0))
39+
if (exist('zmat', 'file') == 2 || exist('zmat', 'file') == 3)
4340
if (nargin > 1)
4441
[varargout{1:nargout}] = zmat(varargin{1}, varargin{2:end});
4542
else
4643
[varargout{1:nargout}] = zmat(varargin{1}, 0, 'gzip', varargin{2:end});
4744
end
4845
return
4946
elseif (isoctavemesh)
50-
[varargout{1:nargout}] = octavezmat(varargin{1}, 0, 'gzip');
51-
return
47+
error('You must install the ZMat toolbox (http://github.com/NeuroJSON/zmat) to use this function in Octave');
5248
end
5349
error(javachk('jvm'));
5450

gzipencode.m

+5-13
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,20 @@
3535
error('you must provide at least 1 input');
3636
end
3737

38-
nozmat = getvarfrom({'caller', 'base'}, 'NO_ZMAT');
39-
40-
if ((exist('zmat', 'file') == 2 || exist('zmat', 'file') == 3) && (isempty(nozmat) || nozmat == 0))
38+
if (exist('zmat', 'file') == 2 || exist('zmat', 'file') == 3)
4139
[varargout{1:nargout}] = zmat(varargin{1}, 1, 'gzip');
4240
return
4341
elseif (isoctavemesh)
44-
[varargout{1:nargout}] = octavezmat(varargin{1}, 1, 'gzip');
45-
return
42+
error('You must install the ZMat toolbox (http://github.com/NeuroJSON/zmat) to use this function in Octave');
4643
end
4744

4845
error(javachk('jvm'));
4946

50-
input = varargin{1}(:)';
51-
if (ischar(input))
52-
input = uint8(input);
53-
elseif (isa(input, 'string'))
54-
input = uint8(char(input));
55-
else
56-
input = typecast(input, 'uint8');
47+
if (ischar(varargin{1}))
48+
varargin{1} = uint8(varargin{1});
5749
end
5850

59-
input = typecast(input, 'uint8');
51+
input = typecast(varargin{1}(:)', 'uint8');
6052

6153
buffer = java.io.ByteArrayOutputStream();
6254
gzip = java.util.zip.GZIPOutputStream(buffer);

jdatadecode.m

+23-6
Original file line numberDiff line numberDiff line change
@@ -477,12 +477,29 @@
477477
end
478478
if (~isempty(ref.path))
479479
uripath = [ref.proto ref.path];
480-
[newdata, fname] = jdlink(uripath);
481-
if (exist(fname, 'file'))
482-
opt.maxlinklevel = opt.maxlinklevel - 1;
483-
if (~isempty(ref.jsonpath))
484-
newdata = jsonpath(newdata, ref.jsonpath);
485-
end
480+
[fpath, fname, fext] = fileparts(uripath);
481+
opt.maxlinklevel = opt.maxlinklevel - 1;
482+
switch (lower(fext))
483+
case {'.json', '.jnii', '.jdt', '.jdat', '.jmsh', '.jnirs'}
484+
newdata = loadjson(uripath, opt);
485+
case {'.bjd', '.bnii', '.jdb', '.jbat', '.bmsh', '.bnirs', '.pmat'}
486+
newdata = loadbj(uripath, opt, 'Base64', 0);
487+
case {'.ubj'}
488+
newdata = loadubjson(uripath, opt, 'Base64', 0);
489+
case {'.msgpack'}
490+
newdata = loadmsgpack(uripath, opt, 'Base64', 0);
491+
case {'.h5', '.hdf5', '.snirf'} % this requires EasyH5 toolbox
492+
newdata = loadh5(uripath, opt);
493+
otherwise
494+
% _DataLink_ url does not specify type, assuming JSON format
495+
if (regexpi(datalink, '^\s*(http|https|ftp|file)://'))
496+
newdata = loadjson(uripath, opt);
497+
else
498+
warning('_DataLink_ url is not supported');
499+
end
500+
end
501+
if (~isempty(ref.jsonpath))
502+
newdata = getfromjsonpath(newdata, ref.jsonpath);
486503
end
487504
end
488505
end

jdataencode.m

+4-12
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
newitem = mat2jd(item, varargin{:});
108108
elseif (ischar(item) || isa(item, 'string'))
109109
newitem = mat2jd(item, varargin{:});
110-
elseif (isa(item, 'containers.Map') || isa(item, 'dictionary'))
110+
elseif (isa(item, 'containers.Map'))
111111
newitem = map2jd(item, varargin{:});
112112
elseif (isa(item, 'categorical'))
113113
newitem = cell2jd(cellstr(item), varargin{:});
@@ -166,21 +166,13 @@
166166
end
167167
end
168168
else % keep as a map and only encode its values
169-
if (isa(item, 'dictionary'))
170-
newitem = dictionary();
171-
elseif (strcmp(item.KeyType, 'char'))
169+
if (strcmp(item.KeyType, 'char'))
172170
newitem = containers.Map();
173171
else
174172
newitem = containers.Map('KeyType', item.KeyType, 'ValueType', 'any');
175173
end
176-
if (isa(item, 'dictionary'))
177-
for i = 1:length(names)
178-
newitem(names(i)) = obj2jd(item(names(i)), varargin{:});
179-
end
180-
else
181-
for i = 1:length(names)
182-
newitem(names{i}) = obj2jd(item(names{i}), varargin{:});
183-
end
174+
for i = 1:length(names)
175+
newitem(names{i}) = obj2jd(item(names{i}), varargin{:});
184176
end
185177
end
186178

0 commit comments

Comments
 (0)