Search in sources :

Example 36 with DataFormatException

use of java.util.zip.DataFormatException in project vcell by virtualcell.

the class ExportServiceImpl method makeRemoteFile.

/**
 * This function saves the remote file into a compressed zip file.
 * Creation date: (4/26/2004 6:47:56 PM)
 */
private ExportEvent makeRemoteFile(String fileFormat, String exportBaseDir, String exportBaseURL, ExportOutput[] exportOutputs, ExportSpecs exportSpecs, JobRequest newExportJob, FileDataContainerManager fileDataContainerManager) throws DataFormatException, IOException, MalformedURLException {
    boolean exportValid = true;
    fireExportAssembling(newExportJob.getJobID(), exportSpecs.getVCDataIdentifier(), fileFormat);
    // check outputs and package into zip file
    File zipFile = new File(exportBaseDir + newExportJob.getJobID() + ".zip");
    FileOutputStream fileOut = new FileOutputStream(zipFile);
    BufferedOutputStream bos = new BufferedOutputStream(fileOut);
    ZipOutputStream zipOut = new ZipOutputStream(bos);
    for (int i = 0; i < exportOutputs.length; i++) {
        if (exportOutputs[i].isValid()) {
            String filename = exportOutputs[i].getSimID() + exportOutputs[i].getDataID();
            if (!filename.endsWith(exportOutputs[i].getDataType())) {
                filename = filename + exportOutputs[i].getDataType();
            }
            ZipEntry zipEntry = new ZipEntry(filename);
            zipOut.putNextEntry(zipEntry);
            System.out.println("writing entry " + i);
            exportOutputs[i].writeDataToOutputStream(zipOut, fileDataContainerManager);
        // zipOut.write(exportOutputs[i].getData());
        } else {
            exportValid = false;
            break;
        }
    }
    zipOut.close();
    if (exportValid) {
        completedExportRequests.put(exportSpecs, newExportJob);
        if (lg.isTraceEnabled())
            lg.trace("ExportServiceImpl.makeRemoteFile(): Successfully exported to file: " + zipFile.getName());
        URL url = new URL(exportBaseURL + zipFile.getName());
        return fireExportCompleted(newExportJob.getJobID(), exportSpecs.getVCDataIdentifier(), fileFormat, url.toString(), exportSpecs);
    } else {
        throw new DataFormatException("Export Server could not produce valid data !");
    }
}
Also used : DataFormatException(java.util.zip.DataFormatException) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) URL(java.net.URL)

Example 37 with DataFormatException

use of java.util.zip.DataFormatException in project vcell by virtualcell.

the class ExportServiceImpl method makeRemoteFile_Unzipped.

/**
 * Save remote file in it original format without compression.
 */
private ExportEvent makeRemoteFile_Unzipped(String fileFormat, String exportBaseDir, String exportBaseURL, ExportOutput[] exportOutputs, ExportSpecs exportSpecs, JobRequest newExportJob, FileDataContainerManager fileDataContainerManager) throws DataFormatException, IOException, MalformedURLException {
    boolean exportValid = true;
    String fileNames = "";
    if (exportOutputs.length > 0 && exportOutputs[0].isValid()) {
        // do the first file of exportOutputs separately (for VFRAP, there is only one export output)
        String extStr = "." + fileFormat;
        File file = new File(exportBaseDir + newExportJob.getJobID() + extStr);
        FileOutputStream fileOut = new FileOutputStream(file);
        BufferedOutputStream out = new BufferedOutputStream(fileOut);
        exportOutputs[0].writeDataToOutputStream(out, fileDataContainerManager);
        // out.write(exportOutputs[0].getData());
        out.close();
        fileNames = fileNames + file.getName();
        // if there are more export outputs, loops through the second till the last.
        for (int i = 1; i < exportOutputs.length; i++) {
            if (exportOutputs[i].isValid()) {
                File moreFile = new File(exportBaseDir + newExportJob.getJobID() + "_" + i + extStr);
                FileOutputStream moreFileOut = new FileOutputStream(moreFile);
                ObjectOutputStream moreOut = new ObjectOutputStream(moreFileOut);
                exportOutputs[i].writeDataToOutputStream(moreOut, fileDataContainerManager);
                // moreOut.writeObject(exportOutputs[i].getData());
                moreOut.close();
                fileNames = "\t" + fileNames + moreFile.getName();
            } else {
                exportValid = false;
                break;
            }
        }
    } else {
        exportValid = false;
    }
    if (exportValid) {
        completedExportRequests.put(exportSpecs, newExportJob);
        if (lg.isTraceEnabled())
            lg.trace("ExportServiceImpl.makeRemoteFile(): Successfully exported to file: " + fileNames);
        URL url = new URL(exportBaseURL + fileNames);
        return fireExportCompleted(newExportJob.getJobID(), exportSpecs.getVCDataIdentifier(), fileFormat, url.toString(), exportSpecs);
    } else {
        throw new DataFormatException("Export Server could not produce valid data !");
    }
}
Also used : DataFormatException(java.util.zip.DataFormatException) FileOutputStream(java.io.FileOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) URL(java.net.URL)

Example 38 with DataFormatException

use of java.util.zip.DataFormatException in project vcell by virtualcell.

the class ExportUtils method extendMirrorPixels.

/**
 * This method was created in VisualAge.
 * @return int[]
 * @param pixels int[]
 */
public static int[] extendMirrorPixels(int[] pixels, int width, int height, int mode) throws DataFormatException {
    if (pixels.length != width * height)
        throw new DataFormatException("Pixel number incompatible with given width, height");
    int[] mirroredPixels;
    switch(mode) {
        case ExportConstants.MIRROR_LEFT:
            mirroredPixels = new int[pixels.length * 2];
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    mirroredPixels[j + width + i * 2 * width] = pixels[j + i * width];
                    mirroredPixels[width - j - 1 + i * 2 * width] = pixels[j + i * width];
                }
            }
            break;
        case ExportConstants.MIRROR_TOP:
            mirroredPixels = new int[pixels.length * 2];
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    mirroredPixels[j + (i + height) * width] = pixels[j + i * width];
                    mirroredPixels[j + (height - i - 1) * width] = pixels[j + i * width];
                }
            }
            break;
        case ExportConstants.MIRROR_RIGHT:
            mirroredPixels = new int[pixels.length * 2];
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    mirroredPixels[j + i * 2 * width] = pixels[j + i * width];
                    mirroredPixels[2 * width - j - 1 + i * 2 * width] = pixels[j + i * width];
                }
            }
            break;
        case ExportConstants.MIRROR_BOTTOM:
            mirroredPixels = new int[pixels.length * 2];
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    mirroredPixels[j + i * width] = pixels[j + i * width];
                    mirroredPixels[j + (2 * height - i - 1) * width] = pixels[j + i * width];
                }
            }
            break;
        default:
            mirroredPixels = pixels;
            break;
    }
    return mirroredPixels;
}
Also used : DataFormatException(java.util.zip.DataFormatException)

Example 39 with DataFormatException

use of java.util.zip.DataFormatException in project vcell by virtualcell.

the class IMGExporter method makeMedia.

// private ParticleInfo checkParticles_unused(final ExportSpecs exportSpecs,User user,DataServerImpl dataServerImpl,final long jobID) throws Exception{
// int particleMode = FormatSpecificSpecs.PARTICLE_NONE;
// if(exportSpecs.getFormatSpecificSpecs() instanceof ImageSpecs){
// particleMode = ((ImageSpecs)exportSpecs.getFormatSpecificSpecs()).getParticleMode();
// }else if (exportSpecs.getFormatSpecificSpecs() instanceof MovieSpecs){
// particleMode = ((MovieSpecs)exportSpecs.getFormatSpecificSpecs()).getParticleMode();
// }
// if(particleMode == FormatSpecificSpecs.PARTICLE_NONE){
// return null;
// }
// 
// final VCDataIdentifier vcdID = exportSpecs.getVCDataIdentifier();
// CartesianMesh cartesianMesh = dataServerImpl.getMesh(user, vcdID);
// int dimension = cartesianMesh.getGeometryDimension();
// 
// String[] variableNames = exportSpecs.getVariableSpecs().getVariableNames();
// 
// File visitExeLocation =
// new File(PropertyLoader.getRequiredProperty(PropertyLoader.visitSmoldynVisitExecutableProperty));
// File visitSmoldynScriptLocation =
// new File(PropertyLoader.getRequiredProperty(PropertyLoader.visitSmoldynScriptPathProperty));
// final File visitSmoldynScriptTempDir = PropertyLoader.getSystemTemporaryDirectory();
// 
// //-----Get all data (from archive if necessary)
// SimulationData.SimDataAmplistorInfo simDataAmplistorInfo = AmplistorUtils.getSimDataAmplistorInfoFromPropertyLoader();
// SimulationData simData = new SimulationData(vcdID,
// new File(PropertyLoader.getRequiredProperty(PropertyLoader.primarySimDataDirInternalProperty),vcdID.getOwner().getName()),
// new File(PropertyLoader.getProperty(PropertyLoader.primarySimDataDirInternalProperty,null),vcdID.getOwner().getName()),
// simDataAmplistorInfo);
// 
// File logFile = simData.getLogFile();
// if(!logFile.exists()){
// throw new Exception("ImgExport particle, Couldn't find Log file "+logFile.getAbsolutePath());
// }
// simData.getMesh();//gets mesh and meshmetrics files from archive if necessary
// simData.getSubdomainFile();
// simData.getFunctionsFile(false);
// int timeIndex = 1;//smoldyn always begins at timeindex 1
// while(true){
// if(!simData.getSmoldynOutputFile(timeIndex).exists()){//get smoldynOutput files
// break;
// }
// timeIndex++;
// }
// //-----
// 
// File visitDataPathFragment = new File(logFile.getParent(),vcdID.getID()+"_");
// System.out.println(visitExeLocation.getAbsolutePath());
// System.out.println(visitSmoldynScriptLocation.getAbsolutePath());
// System.out.println(visitSmoldynScriptTempDir.getAbsolutePath());
// System.out.println(visitDataPathFragment.getAbsolutePath());
// 
// //if(true){return new ParticleInfo(visitSmoldynScriptTempDir);}
// if(exportSpecs.getTimeSpecs().getAllTimes().length == 1){
// throw new IllegalArgumentException("Time zero not valid for smoldyn particle data");
// }
// int beginIndexTime = exportSpecs.getTimeSpecs().getBeginTimeIndex();
// int endIndexTime = exportSpecs.getTimeSpecs().getEndTimeIndex();
// 
// System.out.println("beginIndexTime="+beginIndexTime+" endIndexTime="+endIndexTime);
// 
// ArrayList<String> args = new ArrayList<String>();
// args.add(visitExeLocation.getAbsolutePath());//location of visit
// args.add("-nowin");
// args.add("-cli");
// args.add("-s");
// 
// args.add(visitSmoldynScriptLocation.getAbsolutePath());//location of the script
// args.add(visitDataPathFragment.getAbsolutePath()); //location of the SimID
// args.add(visitSmoldynScriptTempDir.getAbsolutePath());  // where frames are dumped
// args.add(dimension+""); //dimension
// args.add(beginIndexTime+"");
// args.add(endIndexTime+"");
// args.add(4+"");//particle sphere size
// args.add(FormatSpecificSpecs.SMOLDYN_DEFAULT_FRAME_SIZE.width+"");//frame size X
// args.add(FormatSpecificSpecs.SMOLDYN_DEFAULT_FRAME_SIZE.height+"");//frame size Y
// args.add(variableNames.length+""); // 0 = show all the particles.  >0 == show n different particles, to be listed below
// for (int i = 0; i < variableNames.length; i++) {
// args.add(variableNames[i]);
// }
// 
// final String tempFilePrefix = vcdID.getID()+"_p3d";
// 
// //Monitor progress of smoldyn script
// exportServiceImpl.fireExportProgress(jobID, vcdID, "MEDIA", 0.0);
// final boolean[] finishedFlag = new boolean[] {false};
// final int numTimePoints = exportSpecs.getTimeSpecs().getEndTimeIndex()-exportSpecs.getTimeSpecs().getBeginTimeIndex()+1;
// Thread progressThread = new Thread(new Runnable() {
// public void run() {
// System.out.println("smoldyn progress monitor started");
// while(!finishedFlag[0]){
// int count = 0;
// File[] tempFiles = visitSmoldynScriptTempDir.listFiles();
// for (int i = 0; i < tempFiles.length; i++) {
// if(tempFiles[i].getName().startsWith(tempFilePrefix) ||
// (tempFiles[i].getName().startsWith(vcdID.getID()) &&
// tempFiles[i].getName().endsWith(".jpeg"))){
// count+= 1;
// }
// }
// double progress = .5 * (double)count / (double)(2*numTimePoints);
// exportServiceImpl.fireExportProgress(jobID, vcdID, "MEDIA", progress);
// //System.out.println("All files read="+tempFiles.length+" Files counted="+count+" progress="+progress);
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// return;//This shouldn't happen but if so just quit
// }
// }
// System.out.println("smoldyn progress monitor finished");
// }
// });
// progressThread.start();
// 
// 
// try{
// final long TIME_OUT = 1200000; //20 minutes
// Executable executable = new Executable(args.toArray(new String[0]),TIME_OUT);
// executable.start();//blocking, internal monitoring, return after timeout
// if(!executable.getStatus().equals(ExecutableStatus.COMPLETE)){
// System.out.println(executable.getStderrString());
// System.out.println(executable.getStdoutString());
// throw new Exception("Particle data exporter did not complete normally. "+(executable.getStatus()==null?"":executable.getStatus().toString()));
// }
// }finally{
// finishedFlag[0] = true;
// //Remove temp files created by smoldyn script
// File[] tempFiles = visitSmoldynScriptTempDir.listFiles();
// for (int i = 0; i < tempFiles.length; i++) {
// if(tempFiles[i].getName().startsWith(tempFilePrefix)){
// tempFiles[i].delete();
// }
// }
// }
// return new ParticleInfo(visitSmoldynScriptTempDir);
// }
private static ExportOutput[] makeMedia(ExportServiceImpl exportServiceImpl, OutputContext outputContext, long jobID, User user, DataServerImpl dataServerImpl, ExportSpecs exportSpecs, ClientTaskStatusSupport clientTaskStatusSupport, ParticleInfo particleInfo, FileDataContainerManager fileDataContainerManager) throws RemoteException, IOException, GIFFormatException, DataAccessException, Exception {
    boolean bOverLay = false;
    int sliceIndicator = 0;
    if (particleInfo == null) {
        sliceIndicator = (exportSpecs.getGeometrySpecs().getModeID() == ExportConstants.GEOMETRY_FULL ? FULL_MODE_ALL_SLICES : exportSpecs.getGeometrySpecs().getSliceNumber());
    }
    int imageScale = 0;
    int meshMode = 0;
    int mirroringType = 0;
    int membraneScale = 0;
    double duration = 1.0;
    DisplayPreferences[] displayPreferences = null;
    int volVarMembrOutlineThickness = 1;
    if (exportSpecs.getFormatSpecificSpecs() instanceof ImageSpecs) {
        bOverLay = ((ImageSpecs) exportSpecs.getFormatSpecificSpecs()).getOverlayMode();
        imageScale = ((ImageSpecs) exportSpecs.getFormatSpecificSpecs()).getImageScaling();
        volVarMembrOutlineThickness = ((ImageSpecs) exportSpecs.getFormatSpecificSpecs()).getVolVarMembrOutlineThickness();
        meshMode = ((ImageSpecs) exportSpecs.getFormatSpecificSpecs()).getMeshMode();
        mirroringType = ((ImageSpecs) exportSpecs.getFormatSpecificSpecs()).getMirroringType();
        membraneScale = ((ImageSpecs) exportSpecs.getFormatSpecificSpecs()).getMembraneScaling();
        displayPreferences = ((ImageSpecs) exportSpecs.getFormatSpecificSpecs()).getDisplayPreferences();
        // convert from milliseconds to seconds
        duration = (double) ((ImageSpecs) exportSpecs.getFormatSpecificSpecs()).getDuration() / 1000.0;
    } else if (exportSpecs.getFormatSpecificSpecs() instanceof MovieSpecs) {
        bOverLay = ((MovieSpecs) exportSpecs.getFormatSpecificSpecs()).getOverlayMode();
        imageScale = ((MovieSpecs) exportSpecs.getFormatSpecificSpecs()).getImageScaling();
        volVarMembrOutlineThickness = ((MovieSpecs) exportSpecs.getFormatSpecificSpecs()).getVolVarMembrOutlineThickness();
        meshMode = ((MovieSpecs) exportSpecs.getFormatSpecificSpecs()).getMeshMode();
        mirroringType = ((MovieSpecs) exportSpecs.getFormatSpecificSpecs()).getMirroringType();
        membraneScale = ((MovieSpecs) exportSpecs.getFormatSpecificSpecs()).getMembraneScaling();
        displayPreferences = ((MovieSpecs) exportSpecs.getFormatSpecificSpecs()).getDisplayPreferences();
        // convert from milliseconds to seconds
        duration = ((MovieSpecs) exportSpecs.getFormatSpecificSpecs()).getDuration() / 1000.0;
    } else {
        throw new DataFormatException("Unknown FormatSpecificSpec " + exportSpecs.getFormatSpecificSpecs().getClass().getName());
    }
    Vector<ExportOutput> exportOutputV = new Vector<ExportOutput>();
    VCDataIdentifier vcdID = exportSpecs.getVCDataIdentifier();
    int beginTimeIndex = exportSpecs.getTimeSpecs().getBeginTimeIndex();
    int endTimeIndex = exportSpecs.getTimeSpecs().getEndTimeIndex();
    boolean bSingleTimePoint = beginTimeIndex == endTimeIndex;
    String[] varNames = (particleInfo == null ? exportSpecs.getVariableSpecs().getVariableNames() : new String[] { "smoldynParticleDummy" });
    double[] allTimes = dataServerImpl.getDataSetTimes(user, vcdID);
    int startSlice = (sliceIndicator == FULL_MODE_ALL_SLICES ? 0 : sliceIndicator);
    int sliceCount = FormatSpecificSpecs.getSliceCount(sliceIndicator == FULL_MODE_ALL_SLICES, exportSpecs.getGeometrySpecs().getAxis(), dataServerImpl.getMesh(user, vcdID));
    double progressIncr = 1.0 / (sliceCount * (endTimeIndex - beginTimeIndex + 1) * varNames.length);
    double progress = 0.0;
    MovieHolder movieHolder = new MovieHolder();
    Dimension imageDimension = FormatSpecificSpecs.getImageDimension(meshMode, imageScale, dataServerImpl.getMesh(user, vcdID), exportSpecs.getGeometrySpecs().getAxis());
    int originalWidth = (int) imageDimension.getWidth();
    int originalHeight = (int) imageDimension.getHeight();
    ExportRenderInfo exportRenderInfo = null;
    try {
        for (int sliceNumber = startSlice; sliceNumber < startSlice + sliceCount; sliceNumber++) {
            if (particleInfo == null) {
                PDEOffscreenRenderer offScreenRenderer = new PDEOffscreenRenderer(outputContext, user, dataServerImpl, vcdID);
                offScreenRenderer.setNormalAxis(exportSpecs.getGeometrySpecs().getAxis());
                offScreenRenderer.setSlice(sliceNumber);
                exportRenderInfo = new ExportRenderInfo(offScreenRenderer);
            } else {
                exportRenderInfo = new ExportRenderInfo(particleInfo, allTimes, vcdID, beginTimeIndex);
                Dimension particleImageSize = particleInfo.getImageFrameSize(vcdID);
                originalWidth = particleImageSize.width;
                originalHeight = particleImageSize.height;
            }
            int varNameIndex0 = 0;
            int timeIndex0 = beginTimeIndex;
            int[] overLayPixels = null;
            // set default time if only 1 timepoint
            movieHolder.setSampleDurationSeconds(duration);
            boolean bEndslice = sliceNumber == (startSlice + sliceCount - 1);
            while (true) {
                if (clientTaskStatusSupport != null) {
                    clientTaskStatusSupport.setProgress((int) (progress * 100));
                    if (clientTaskStatusSupport.isInterrupted()) {
                        throw UserCancelException.CANCEL_GENERIC;
                    }
                }
                exportServiceImpl.fireExportProgress(jobID, vcdID, "MEDIA", (particleInfo == null ? progress : .5 + (progress / 2.0)));
                progress += progressIncr;
                MirrorInfo currentSliceTimeMirrorInfo = renderAndMirrorSliceTimePixels(exportRenderInfo, varNames[varNameIndex0], allTimes[timeIndex0], displayPreferences[varNameIndex0], imageScale, membraneScale, meshMode, volVarMembrOutlineThickness, originalWidth, originalHeight, mirroringType);
                if (bOverLay) {
                    if (varNames.length == 1) {
                        overLayPixels = currentSliceTimeMirrorInfo.getPixels();
                    } else {
                        // Overlay append in Y-direction
                        if (overLayPixels == null) {
                            overLayPixels = new int[currentSliceTimeMirrorInfo.getPixels().length * varNames.length];
                        }
                        int appendIndex = currentSliceTimeMirrorInfo.getPixels().length * varNameIndex0;
                        System.arraycopy(currentSliceTimeMirrorInfo.getPixels(), 0, overLayPixels, appendIndex, currentSliceTimeMirrorInfo.getPixels().length);
                    }
                }
                if (timeIndex0 != endTimeIndex) {
                    // calculate duration for each timepoint
                    movieHolder.setSampleDurationSeconds((allTimes[timeIndex0 + 1] - allTimes[timeIndex0]) / (allTimes[endTimeIndex + (endTimeIndex == allTimes.length - 1 ? 0 : 1)] - allTimes[beginTimeIndex]) * duration);
                } else {
                    // when last or only 1 timepoint, use last duration set
                    movieHolder.setSampleDurationSeconds(movieHolder.getSampleDurationSeconds());
                }
                // Index var and time properly
                boolean bBegintime = timeIndex0 == beginTimeIndex;
                boolean bEndTime = timeIndex0 == endTimeIndex;
                if (bOverLay) {
                    varNameIndex0++;
                    if (varNameIndex0 == varNames.length) {
                        String dataID = createDataID(exportSpecs, sliceNumber, "overlay", timeIndex0);
                        createMedia(exportOutputV, vcdID, dataID, exportSpecs, true, bEndslice, bBegintime, bEndTime, bSingleTimePoint, varNames, displayPreferences, movieHolder, overLayPixels, currentSliceTimeMirrorInfo.getMirrorWidth(), currentSliceTimeMirrorInfo.getMirrorHeight() * varNames.length, fileDataContainerManager);
                        varNameIndex0 = 0;
                        timeIndex0++;
                        if (timeIndex0 > endTimeIndex) {
                            break;
                        }
                    }
                } else {
                    String dataID = createDataID(exportSpecs, sliceNumber, varNames[varNameIndex0], timeIndex0);
                    boolean bEndVars = varNameIndex0 == varNames.length - 1;
                    createMedia(exportOutputV, vcdID, dataID, exportSpecs, bEndVars, bEndslice, bBegintime, bEndTime, bSingleTimePoint, new String[] { varNames[varNameIndex0] }, new DisplayPreferences[] { displayPreferences[varNameIndex0] }, movieHolder, currentSliceTimeMirrorInfo.getPixels(), currentSliceTimeMirrorInfo.getMirrorWidth(), currentSliceTimeMirrorInfo.getMirrorHeight(), fileDataContainerManager);
                    timeIndex0++;
                    if (timeIndex0 > endTimeIndex) {
                        timeIndex0 = beginTimeIndex;
                        varNameIndex0++;
                        if (varNameIndex0 == varNames.length) {
                            break;
                        }
                    }
                }
            }
        }
    } finally {
        if (exportRenderInfo != null) {
            exportRenderInfo.cleanup();
        }
    }
    return exportOutputV.toArray(new ExportOutput[0]);
}
Also used : Dimension(java.awt.Dimension) DataFormatException(java.util.zip.DataFormatException) DisplayPreferences(cbit.image.DisplayPreferences) Vector(java.util.Vector) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier)

Example 40 with DataFormatException

use of java.util.zip.DataFormatException in project vcell by virtualcell.

the class FieldDataGUIPanel method fdFromFile.

private AsynchClientTask[] fdFromFile() {
    final RequestManager clientRequestManager = fieldDataWindowManager.getLocalRequestManager();
    AsynchClientTask[] addTasks = addNewExternalData(this, this, false);
    AsynchClientTask[] taskArray = new AsynchClientTask[2 + addTasks.length];
    // add to the end
    System.arraycopy(addTasks, 0, taskArray, 2, addTasks.length);
    taskArray[0] = new AsynchClientTask("select a file", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            FieldDataFileOperationSpec argfdos = (FieldDataFileOperationSpec) hashTable.get("argfdos");
            if (argfdos == null && hashTable.get(IMAGE_FILE_KEY) == null) {
                File imageFile = DatabaseWindowManager.showFileChooserDialog(fieldDataWindowManager, FileFilters.FILE_FILTER_FIELDIMAGES, clientRequestManager.getUserPreferences(), JFileChooser.FILES_AND_DIRECTORIES);
                hashTable.put(IMAGE_FILE_KEY, imageFile);
            }
        }
    };
    taskArray[1] = new AsynchClientTask("Import image", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            FieldDataFileOperationSpec fdos = null;
            String initFDName = null;
            FieldDataFileOperationSpec argfdos = (FieldDataFileOperationSpec) hashTable.get("argfdos");
            String arginitFDName = (String) hashTable.get("arginitFDName");
            if (argfdos == null) {
                File imageFile = (File) hashTable.get(IMAGE_FILE_KEY);
                if (imageFile == null) {
                    return;
                }
                initFDName = imageFile.getName();
                if (initFDName.indexOf(".vfrap") > -1) {
                /*					//read the image dataset from Virtual FRAP xml file
	                System.out.println("Loading " + initFDName + " ...");
	                
	                AnnotatedImageDataset annotatedImages = null;
	                String xmlString;
	                try {
	                        xmlString = XmlUtil.getXMLString(imageFile.getAbsolutePath());
	                        MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
	                        annotatedImages = xmlReader.getAnnotatedImageDataset(XmlUtil.stringToXML(xmlString, null).getRootElement(), this.getClientTaskStatusSupport());
	                        OverlayEditorPanelJAI overlayPanel = new OverlayEditorPanelJAI();
	                        overlayPanel.setImages(annotatedImages.getImageDataset(), 1, 0, new OverlayEditorPanelJAI.AllPixelValuesRange(1, 200) );
	                        DialogUtils.showComponentCloseDialog(FieldDataGUIPanel.this, overlayPanel, "this is it");
	                } catch (Exception e) {
	                        e.printStackTrace(System.out);
	                } */
                } else // not a .vfrap file
                {
                    try {
                        fdos = ClientRequestManager.createFDOSFromImageFile(imageFile, false, null);
                    } catch (DataFormatException ex) {
                        throw new Exception("Cannot read image " + imageFile.getAbsolutePath() + "\n" + ex.getMessage());
                    }
                }
            } else {
                fdos = argfdos;
                initFDName = arginitFDName;
            }
            fdos.owner = clientRequestManager.getDocumentManager().getUser();
            fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
            hashTable.put("fdos", fdos);
            hashTable.put("initFDName", initFDName);
        // addNewExternalData(clientRequestManager, fdos, initFDName, false);
        }
    };
    return taskArray;
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) RequestManager(cbit.vcell.client.RequestManager) ClientRequestManager(cbit.vcell.client.ClientRequestManager) DataFormatException(java.util.zip.DataFormatException) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) File(java.io.File) DataFormatException(java.util.zip.DataFormatException) UserCancelException(org.vcell.util.UserCancelException)

Aggregations

DataFormatException (java.util.zip.DataFormatException)71 IOException (java.io.IOException)32 Inflater (java.util.zip.Inflater)29 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ByteBuffer (java.nio.ByteBuffer)9 ArrayList (java.util.ArrayList)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 InputStream (java.io.InputStream)5 File (java.io.File)4 BufferedOutputStream (java.io.BufferedOutputStream)3 FileOutputStream (java.io.FileOutputStream)3 URL (java.net.URL)3 ImageException (cbit.image.ImageException)2 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)2 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 BaseMediaHeader (cbit.vcell.export.gloworm.atoms.BaseMediaHeader)2 BaseMediaInformation (cbit.vcell.export.gloworm.atoms.BaseMediaInformation)2 HandlerReference (cbit.vcell.export.gloworm.atoms.HandlerReference)2 VideoMediaInformation (cbit.vcell.export.gloworm.atoms.VideoMediaInformation)2 GeometryException (cbit.vcell.geometry.GeometryException)2