Skip to content

Commit

Permalink
Changed to using streams to load.
Browse files Browse the repository at this point in the history
  • Loading branch information
gerring committed Dec 19, 2019
1 parent 5868ef5 commit 40e2a6b
Show file tree
Hide file tree
Showing 16 changed files with 241 additions and 256 deletions.
43 changes: 16 additions & 27 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'findbugs'
apply plugin: 'pmd'
apply plugin: 'checkstyle'

// We aspire one day to be part of Eclipse January.
Expand All @@ -33,10 +31,10 @@ group 'io.github.h5jan'
description = "h5jan-core"

// To sign, enter the gradle command 'gradle(w) sign'
defaultTasks 'compileJava', 'classes', 'jar', 'sourceJar', 'compileTestJava', 'processTestResources', 'testClasses', 'findbugsMain', 'pmdMain', 'test'
defaultTasks 'compileJava', 'javadoc', 'enunciate', 'check', 'compileTestJava', 'processTestResources', 'test', 'jar'

ext {
baseVersion = "0.5.0"
baseVersion = "0.6.0"
if (project.hasProperty('version')) {
baseVersionNum = version
}
Expand Down Expand Up @@ -152,18 +150,6 @@ repositories {
}
}


findbugs {
ignoreFailures = true
sourceSets = [sourceSets.main]
reportsDir = file("$project.buildDir/reports/findbugs")
effort = "max"
}

pmd {
ignoreFailures = true
}

/**
The Suites are for local testing, gradle can file other unit tests
see https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html
Expand Down Expand Up @@ -198,6 +184,9 @@ dependencies {
// https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils
compile group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.4'

// https://mvnrepository.com/artifact/org.apache.commons/commons-csv
compile group: 'org.apache.commons', name: 'commons-csv', version: '1.7'

// https://mvnrepository.com/artifact/tec.units/indriya/1.0 Units BSD License
implementation group: 'tec.units', name: 'indriya', version: '1.0'

Expand Down Expand Up @@ -270,17 +259,17 @@ publishing {
}
}// create the signed artifacts

project.tasks.signArchives.signatureFiles.each {
artifact(it) {
def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/
if (matcher.find()) {
classifier = matcher.group(1)
} else {
classifier = null
}
extension = 'jar.asc'
}
}
//project.tasks.signArchives.signatureFiles.each {
// artifact(it) {
// def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/
// if (matcher.find()) {
// classifier = matcher.group(1)
// } else {
// classifier = null
// }
// extension = 'jar.asc'
// }
//}
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,19 @@

package io.github.h5jan.io;

import java.io.File;
import java.io.IOException;

import org.eclipse.january.DatasetException;
import org.eclipse.january.IMonitor;
import org.eclipse.january.dataset.Dataset;
import org.eclipse.january.dataset.DatasetUtils;
import org.eclipse.january.dataset.IDataset;
import org.eclipse.january.dataset.ILazyDataset;
import org.eclipse.january.dataset.LazyDataset;
import org.eclipse.january.dataset.SliceND;
import org.eclipse.january.io.ILazyLoader;

import io.github.h5jan.core.DataFrame;

/**
* A class which can be extended when implementing IFileLoader
*/
abstract class AbstractFileLoader implements IFileLoader {
abstract class AbstractStreamLoader implements IStreamLoader {

/**
* Name prefix for an image dataset (should be followed by two digits, starting with 01)
Expand All @@ -54,90 +48,47 @@ abstract class AbstractFileLoader implements IFileLoader {
*/
protected static final String FILEPATH_DATASET_SEPARATOR = ":";

protected File file = null;

protected void setFile(final File file) {
this.file = file;
}

protected Configuration configuration = null;

protected void setConfiguration(final Configuration configuration) {
this.configuration = configuration;
}

protected class LazyLoaderStub implements ILazyLoader {
protected abstract class LazyLoaderStub implements ILazyLoader {

public static final long serialVersionUID = 5057544213374303912L;
private IFileLoader loader;
private IStreamLoader loader;
private String name;

public LazyLoaderStub() {
loader = null;
name = null;
}

public LazyLoaderStub(IFileLoader loader) {
public LazyLoaderStub(IStreamLoader loader) {
this(loader, null);
}

/**
* @param loader
* @param name dataset name in data holder (can be null to signify first dataset)
*/
public LazyLoaderStub(IFileLoader loader, String name) {
public LazyLoaderStub(IStreamLoader loader, String name) {
this.loader = loader;
this.name = name;
}

public IFileLoader getLoader() {
public IStreamLoader getLoader() {
return loader;
}

@Override
public IDataset getDataset(IMonitor mon, SliceND slice) throws IOException {

if (loader == null) {
return null;
}

try {
DataFrame holder = load(file, configuration, mon);
if (holder != null) {
ILazyDataset lazy = name == null ? holder.get(0) : holder.get(name);
if (lazy != null) {
IDataset data = lazy.getSlice();
return DatasetUtils.convertToDataset(data).getSliceView(slice);
}
}

holder = loader.load(file, configuration, mon);
ILazyDataset lazy = name == null ? holder.get(0) : holder.get(name);
return lazy.getSlice().getSliceView(slice);

} catch (DatasetException de) {
throw new IOException(de);
}
}

public abstract IDataset getDataset(IMonitor mon, SliceND slice) throws IOException;

@Override
public boolean isFileReadable() {
return file.canRead();
return true;
}
}

protected LazyDataset createLazyDataset(LazyLoaderStub l, String dName, Class<? extends Dataset> clazz, int... shape) {
return new LazyDataset(l, dName, clazz, shape);
}

protected LazyDataset createLazyDataset(IFileLoader loader, String dName, Class<? extends Dataset> clazz, int... shape) {
return createLazyDataset(loader, dName, dName, clazz, shape);
}

protected LazyDataset createLazyDataset(IFileLoader loader, String dName, String dhName, Class<? extends Dataset> clazz, int... shape) {
return new LazyDataset(new LazyLoaderStub(loader, dhName), dName, clazz, shape);
}

/**
* @param mon
* @return false if cancelled
Expand Down
52 changes: 49 additions & 3 deletions src/main/java/io/github/h5jan/io/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
*******************************************************************************/
package io.github.h5jan.io;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.FilenameUtils;

/**
* A class to hold common dataset loading configurations.
*
Expand All @@ -24,17 +27,23 @@ public interface Configuration extends Map<String, Object> {
/**
* No conf
*/
public static final Configuration DEFAULT = new ConfigurationImpl();
public static Configuration createDefault() {
return new ConfigurationImpl();
}

/**
* Grey scale conf.
*/
public static final Configuration GREYSCALE = concrete("asGrey", Boolean.TRUE);
public static Configuration createGreyScale() {
return concrete("asGrey", Boolean.TRUE);
}

/**
* Keep pixel width
*/
public static final Configuration KEEPWIDTH = concrete("keepBitWidth", Boolean.TRUE);
public static Configuration createKeepWidth() {
return concrete("keepBitWidth", Boolean.TRUE);
}

/**
* Create any configuration with key value pairs
Expand All @@ -45,16 +54,42 @@ public static Configuration concrete(Object... values) {
return new ConfigurationImpl(values);
}

/**
* Align from name and type
* @param fileName - file name
* @param fileType - file type
* @param numBits - number of bits
* @param asUnsigned - signed or unsigned.
* @return configuration
*/
public static Configuration image(String fileName, String fileType, int numBits, boolean asUnsigned) {
return new ConfigurationImpl("fileName", fileName,
"fileType", fileType,
"numBits", numBits,
"asUnsigned", asUnsigned);
}

/**
* Align from file.
* @param file - file
* @param numBits - number of bits
* @param asUnsigned - signed or unsigned.
* @return configuration
*/
public static Configuration image(File file, int numBits, boolean asUnsigned) {
Configuration ret = new ConfigurationImpl("numBits", numBits,
"asUnsigned", asUnsigned);
ret.align(file);
return ret;
}

public default String getFileName() {
return (String)get("fileName");
}

public default String getFilePath() {
return (String)get("filePath");
}

public default String getFileType() {
return (String)get("fileType");
Expand All @@ -67,6 +102,17 @@ public default int getNumBits() {
public default boolean getAsUnsigned() {
return (Boolean)get("asUnsigned");
}

public default void align(File file) {
if (!containsKey("fileName")) put("fileName", file.getName());
if (!containsKey("filePath")) put("filePath", file.getAbsolutePath());
if (!containsKey("fileType")) {
String ext = FilenameUtils.getBaseName(file.getName());
if (ext!=null) {
put("fileType", ext.toUpperCase());
}
}
}
}

class ConfigurationImpl extends HashMap<String,Object> implements Configuration {
Expand Down
Loading

0 comments on commit 40e2a6b

Please sign in to comment.