Skip to content
Snippets Groups Projects
Commit a25de514 authored by carlosuc3m's avatar carlosuc3m
Browse files

keep correcting small errors

parent 8263cc73
No related branches found
No related tags found
No related merge requests found
...@@ -32,9 +32,10 @@ public final class MappedBufferToImgLib2 ...@@ -32,9 +32,10 @@ public final class MappedBufferToImgLib2
* Pattern that matches the header of the temporal file for interprocess communication * Pattern that matches the header of the temporal file for interprocess communication
* and retrieves data type and shape * and retrieves data type and shape
*/ */
private static final Pattern HEADER_PATTERN = private static final Pattern HEADER_PATTERN = Pattern.compile("'dtype':'([a-zA-Z0-9]+)'"
Pattern.compile("\\{'dtype':'([a-zA-Z0-9]+)','axes':'([a-zA-Z0-9]+)'" + ",'axes':'([a-zA-Z]+)'"
+ ",'name':'(.+?)',shape':'\\[(\\d+(,\\d+)*)\\]'}"); + ",'name':'([^']*)'"
+ ",'shape':'(\\[\\s*(?:(?:[1-9]\\d*|0)\\s*,\\s*)*(?:[1-9]\\d*|0)?\\s*\\])'");
/** /**
* Key for data type info * Key for data type info
*/ */
...@@ -248,17 +249,19 @@ public final class MappedBufferToImgLib2 ...@@ -248,17 +249,19 @@ public final class MappedBufferToImgLib2
* @return * @return
*/ */
public static HashMap<String, Object> getDataTypeAndShape(String infoStr) { public static HashMap<String, Object> getDataTypeAndShape(String infoStr) {
Matcher m = HEADER_PATTERN.matcher(infoStr); Matcher matcher = HEADER_PATTERN.matcher(infoStr);
if (!m.find()) { if (!matcher.find()) {
throw new IllegalArgumentException("Cannot find datatype and dimensions " throw new IllegalArgumentException("Cannot find datatype, name, axes and dimensions "
+ "info in file hader: " + infoStr); + "info in file header: " + infoStr);
} }
String typeStr = m.group(1); String typeStr = matcher.group(1);
String axesStr = m.group(2); String axesStr = matcher.group(2);
String nameStr = m.group(3); String nameStr = matcher.group(3);
String shapeStr = m.group(4); String shapeStr = matcher.group(4);
long[] shape = new long[0]; long[] shape = new long[0];
if (!shapeStr.isEmpty() && !shapeStr.equals("[]")) { if (!shapeStr.isEmpty() && !shapeStr.equals("[]")) {
shapeStr = shapeStr.substring(0, shapeStr.length() - 1);
String[] tokens = shapeStr.split(", ?"); String[] tokens = shapeStr.split(", ?");
shape = Arrays.stream(tokens).mapToLong(Long::parseLong).toArray(); shape = Arrays.stream(tokens).mapToLong(Long::parseLong).toArray();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment