addMap
method.
If you want to take advantage of map load and save features, you have
to manage the serialization of the reader, that is, provide methods
that perform the required functions.public class MyDEMReader extends IlvRasterAbstractReader { // list of files to be read. private ArrayList filenameList = new ArrayList(); /** default constructor */ public MyDEMReader() { }
addMap
method to
compute the IlvRasterProperties and IlvRasterMappedBuffer attached to the file name, see Raster image management,
and then add this information to the list managed by the reader. As
this step is heavily dependent upon format, only a summary is provided
here.public void addMap(final String filename) throws IOException { IlvRasterProperties loadingRaster = read/compute raster properties ... IlvRasterMappedBuffer source= read/compute raster pixel values... loadingRaster.setBaseName(filename); // to retrieve the file name when serializing data. addRaster(loadingRaster, source); }
public void write(IlvOutputStream stream) throws IOException { super.write(stream); int imageCount = getImageCount(); for (int i = 0; i < imageCount; i++) { IlvRasterProperties props=getRasterProperties(i); stream.write("filename"+i,props.getBaseName()); } }
public MyDEMReader(IlvInputStream stream) throws IlvReadFileException { super(stream); try { for(int count=0;true;count++) { String filename = stream.readString("filename"+count); filenameList.add(filename); } } catch (IlvReadFileException e1) { // No more filenames to read } }
public void reload(IlvThreadMonitoringData monitorInfo) { super.reload(monitorInfo); // clear all images dispose(); // save the known filenames in a temporary array – the addMap would else add them again. String[] filenames = (String[])filenameList.toArray(new String[0]); // clear the file name list filenameList.clear(); for (int i = 0; i < filenames.length; i++) { try { // load each file addMap(filenames[i]); if (monitorInfo != null) { // update the thread monitoring information, if necessary int percent = Math.round(i/(float)filenames.length * 100); monitorInfo.updateProgress(percent); } } catch (IOException e) { new IlvExceptionMessage(e,null); } } }