Skip to content
Snippets Groups Projects
Commit aa843377 authored by Vojtěch Moravec's avatar Vojtěch Moravec
Browse files

Use specific InputData types in specific loader.

Use FileInputData in SCIFIOLoader and in the RawDataLoader.
PlaneLoaderFactory will cast the generic DataInput to the concrete
class object. We can do this, becase we check the dataLoaderType
beforehand.
parent 9b3f65ea
Branches
No related tags found
No related merge requests found
package azgracompress.io.loader;
import azgracompress.io.BufferInputData;
import azgracompress.io.FileInputData;
import azgracompress.io.InputData;
import java.nio.Buffer;
public final class PlaneLoaderFactory {
/**
......@@ -14,11 +18,11 @@ public final class PlaneLoaderFactory {
public static IPlaneLoader getPlaneLoaderForInputFile(final InputData inputDataInfo) throws Exception {
switch (inputDataInfo.getDataLoaderType()) {
case RawDataLoader:
return new RawDataLoader(inputDataInfo);
return new RawDataLoader((FileInputData) inputDataInfo);
case SCIFIOLoader:
return new SCIFIOLoader(inputDataInfo);
return new SCIFIOLoader((FileInputData)inputDataInfo);
case ImageJBufferLoader:
return new ImageJBufferLoader();
return new ImageJBufferLoader((BufferInputData) inputDataInfo);
default:
throw new Exception("Unsupported data loader.");
}
......
......@@ -10,9 +10,9 @@ import java.io.*;
import java.util.Arrays;
public class RawDataLoader implements IPlaneLoader {
private final InputData inputDataInfo;
private final FileInputData inputDataInfo;
public RawDataLoader(final InputData inputDataInfo) {
public RawDataLoader(final FileInputData inputDataInfo) {
this.inputDataInfo = inputDataInfo;
}
......@@ -21,7 +21,7 @@ public class RawDataLoader implements IPlaneLoader {
byte[] buffer;
final V3i rawDataDimension = inputDataInfo.getDimensions();
try (FileInputStream fileStream = new FileInputStream(((FileInputData)inputDataInfo).getFilePath())) {
try (FileInputStream fileStream = new FileInputStream(inputDataInfo.getFilePath())) {
final long planeSize = (long) rawDataDimension.getX() * (long) rawDataDimension.getY() * 2;
final long expectedFileSize = planeSize * rawDataDimension.getZ();
final long fileSize = fileStream.getChannel().size();
......@@ -70,7 +70,7 @@ public class RawDataLoader implements IPlaneLoader {
Arrays.sort(planes);
try (FileInputStream fileStream = new FileInputStream(((FileInputData)inputDataInfo).getFilePath());
try (FileInputStream fileStream = new FileInputStream(inputDataInfo.getFilePath());
DataInputStream dis = new DataInputStream(new BufferedInputStream(fileStream, 8192))) {
int lastIndex = 0;
......@@ -107,7 +107,7 @@ public class RawDataLoader implements IPlaneLoader {
int[] values = new int[(int) dataSize];
try (FileInputStream fileStream = new FileInputStream(((FileInputData)inputDataInfo).getFilePath());
try (FileInputStream fileStream = new FileInputStream(inputDataInfo.getFilePath());
DataInputStream dis = new DataInputStream(new BufferedInputStream(fileStream, 8192))) {
for (int i = 0; i < (int) dataSize; i++) {
......
......@@ -4,7 +4,6 @@ import azgracompress.ScifioWrapper;
import azgracompress.data.ImageU16;
import azgracompress.data.V3i;
import azgracompress.io.FileInputData;
import azgracompress.io.InputData;
import azgracompress.utilities.TypeConverter;
import io.scif.FormatException;
import io.scif.Reader;
......@@ -14,7 +13,7 @@ import java.util.Arrays;
public class SCIFIOLoader implements IPlaneLoader {
private final InputData inputDataInfo;
private final FileInputData inputDataInfo;
private final Reader reader;
/**
......@@ -24,9 +23,9 @@ public class SCIFIOLoader implements IPlaneLoader {
* @throws IOException When fails to create SCIFIO reader.
* @throws FormatException When fails to create SCIFIO reader.
*/
public SCIFIOLoader(final InputData inputDataInfo) throws IOException, FormatException {
public SCIFIOLoader(final FileInputData inputDataInfo) throws IOException, FormatException {
this.inputDataInfo = inputDataInfo;
this.reader = ScifioWrapper.getReader(((FileInputData)this.inputDataInfo).getFilePath());
this.reader = ScifioWrapper.getReader(this.inputDataInfo.getFilePath());
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment