List of usage examples for org.apache.commons.vfs2 FileObject getURL
URL getURL() throws FileSystemException;
From source file:org.kalypso.commons.io.VFSUtilities.java
/** * This function creates a temporary directory, which has a unique file name. * * @param prefix//from w w w. jav a 2s .c o m * This prefix will be used for the temporary directory. * @param parentDir * The parent directory. In it the new directory will be created. * @return The new unique directory. */ public static FileObject createTempDirectory(final String prefix, final FileObject parentDir, final FileSystemManager fsManager) throws FileSystemException { while (true) { final String dirParent = parentDir.getURL().toExternalForm(); final String dirName = prefix + String.valueOf(System.currentTimeMillis()); final FileObject newDir = fsManager.resolveFile(dirParent + "/" + dirName); //$NON-NLS-1$ if (newDir.exists()) { continue; } KalypsoCommonsDebug.DEBUG.printf("Creating folder %s ...%n", newDir.getName().getPath()); //$NON-NLS-1$ newDir.createFolder(); return newDir; } }
From source file:org.kalypso.commons.io.VFSUtilities.java
/** * resolves the input stream from given {@link FileObject} based on the file extention, known types are gz and zip, in * case of zip archiv the first file will be taken. *///from ww w .jav a 2 s . c o m public static InputStream getInputStreamFromFileObject(final FileObject file) throws FileSystemException, IOException, URISyntaxException { /* open stream */ if ("gz".equalsIgnoreCase(file.getName().getExtension()))//$NON-NLS-1$ return new GZIPInputStream(new BufferedInputStream(file.getContent().getInputStream())); if ("zip".equalsIgnoreCase(file.getName().getExtension()))//$NON-NLS-1$ return ZipUtilities.getInputStreamForFirstFile(file.getURL()); return new BufferedInputStream(file.getContent().getInputStream()); }
From source file:org.kalypso.kalypsomodel1d2d.conv.Gml2TelemacConv.java
/** * *//* w ww .j av a2 s .c o m*/ private int writeAllElements(final List<GM_Triangle> pTriangles, final FileObject pFileObjWorkingDir) { m_listAllNodes = new ArrayList<>(countNodes(pTriangles)); if (m_boolDoShift) { m_iparams[2] = m_globalMinX; m_iparams[3] = m_globalMinY; } SerafinWriter serafinWriter = new SerafinWriter(m_calculationUnit.getName(), pTriangles/* , pMapPositionsToConditions */, m_listAllNodes, m_listBoundNodes, m_iparams, m_strCRS); // int timeSteps = 1; try { FileObject serafinFile = pFileObjWorkingDir .resolveFile(GEO_FILE_PREFIX + getProjectFileName() + SERAFIN_FILE_EXTENTION); serafinWriter.setFile(new File(serafinFile.getURL().toURI()));// pFileObjWorkingDir.getURL().toURI().resolve( // "test_telemac.slf" ) ) ); timeSteps serafinWriter.writeAll(m_paramNames, m_paramUnits, m_restartNodes); writeBoundNodes(); writeBoundaries(); } catch (Exception e) { e.printStackTrace(); } return 0; }
From source file:org.kalypso.kalypsomodel1d2d.conv.SWANDataConverterHelper.java
public static GM_Position readCoordinateShiftValues(final FileObject pFile) { GM_Position lPosRes = null;//from w w w .j a va 2s. c om Scanner scannerFile = null; Scanner scannerLine = null; try { FileObject swanShiftCoordFileObject = pFile.getParent() .getChild(ISimulation1D2DConstants.SIM_SWAN_COORD_SHIFT_FILE); if (swanShiftCoordFileObject == null) { return lPosRes; } File lFile = new File(swanShiftCoordFileObject.getURL().toURI()); scannerFile = new Scanner(lFile); Double lDoubleShiftY = null; Double lDoubleShiftX = null; while (scannerFile.hasNextLine()) { String lStrNextLine = scannerFile.nextLine(); if (lStrNextLine.contains("=")) { //$NON-NLS-1$ scannerLine = new Scanner(lStrNextLine); scannerLine.useDelimiter("="); //$NON-NLS-1$ String lStrValueName = scannerLine.next(); String lStrValue = scannerLine.next(); if (ISimulation1D2DConstants.SIM_SWAN_COORD_SHIFT_X.equalsIgnoreCase(lStrValueName)) { lDoubleShiftX = Double.parseDouble(lStrValue); } else if (ISimulation1D2DConstants.SIM_SWAN_COORD_SHIFT_Y.equalsIgnoreCase(lStrValueName)) { lDoubleShiftY = Double.parseDouble(lStrValue); } scannerLine.close(); } else { // System.out.println("Empty or invalid line. Unable to process. Processing the results without shift!"); } } if (lDoubleShiftX != null && lDoubleShiftY != null) lPosRes = GeometryFactory.createGM_Position(lDoubleShiftX, lDoubleShiftY); } catch (Exception e) { e.printStackTrace(); } finally { if (scannerFile != null) scannerFile.close(); if (scannerLine != null) scannerLine.close(); } return lPosRes; }
From source file:org.kalypso.kalypsomodel1d2d.sim.ProcessResultTelemacOperation.java
private IStatus readTelemacResults() { final SerafinReader convTelemac = new SerafinReader(); final FileObject inputFile = getOrUnzipResult(m_inputFile, m_outputDir); if (inputFile == null) { return new Status(IStatus.ERROR, PluginUtilities.id(KalypsoModel1D2DPlugin.getDefault()), "error - no result file found!"); }//w ww . jav a 2s . c o m try { convTelemac.setFile(new File(inputFile.getURL().toURI())); convTelemac.doReadAll(); } catch (URISyntaxException | IOException e1) { e1.printStackTrace(); final String msg = "error while reading telemac results file"; return new Status(IStatus.ERROR, PluginUtilities.id(KalypsoModel1D2DPlugin.getDefault()), msg, e1); } // Map<String, Map<String, List<Double>>> mapResults = convTelemac.doRead(); for (Date stepDate : m_stepDates) { // stepDate = findStepDate( file ); // m_geoLog.formatLog( IStatus.INFO, CODE_RUNNING_FINE, Messages.getString( "org.kalypso.kalypsomodel1d2d.sim.ResultManager.14" ), inputFile.getURL().toString() ); //$NON-NLS-1$ final String outDirName = NodeResultHelper.createOutDirName(stepDate); final File resultOutputDir = new File(m_outputDir, outDirName); resultOutputDir.mkdirs(); KalypsoModel1D2DDebug.SIMULATIONRESULT.printf("%s", //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.16")); //$NON-NLS-1$ final Runtime runtime = Runtime.getRuntime(); runtime.gc(); final TimeLogger logger = new TimeLogger( Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.17")); //$NON-NLS-1$ final File gmlZipResultFile = new File(resultOutputDir, "results.gz"); //$NON-NLS-1$ IStepResultMeta stepResultMeta = m_unitResultMeta.addStepResult(); try { /* GMLWorkspace fr Ergebnisse anlegen */ final GMLWorkspace resultWorkspace = FeatureFactory.createGMLWorkspace(INodeResultCollection.QNAME, gmlZipResultFile.toURI().toURL(), null); final URL lsObsUrl = LengthSectionHandler2d.class .getResource("resources/lengthSectionTemplate.gml"); //$NON-NLS-1$ final String componentID = IWspmDictionaryConstants.LS_COMPONENT_STATION; final LengthSectionHandler1d lsHandler = new LengthSectionHandler1d(componentID, lsObsUrl); /* .2d Datei lesen und GML fllen */ final String crs = KalypsoDeegreePlugin.getDefault().getCoordinateSystem(); final MultiTriangleEater multiEater = new MultiTriangleEater(); if (m_boolDoFullEvaluate) { for (final ResultType parameter : m_parameters) { /* GML(s) */ if (parameter == ResultType.TERRAIN && !ResultMeta1d2dHelper.containsTerrain(stepResultMeta)) { /* create TIN-Dir for FEM terrain model */ // TODO: obscure, why go outside our output dir... TODO: refaktor it! final String calcUnitPath = resultOutputDir.getParent(); final File modelPath = new File(calcUnitPath, "model"); //$NON-NLS-1$ if (!modelPath.exists()) { modelPath.mkdirs(); final File modelTinPath = new File(modelPath, "Tin"); //$NON-NLS-1$ modelTinPath.mkdirs(); final File tinResultFile = new File(modelTinPath, "tin.gz"); //$NON-NLS-1$ final ITriangleEater gmlTriangleEater = NodeResultHelper .createTinEater(tinResultFile, parameter, crs); multiEater.addEater(gmlTriangleEater); } } else { /* create TIN-Dir for results */ final File tinPath = new File(resultOutputDir, "Tin"); //$NON-NLS-1$ tinPath.mkdirs(); final File tinZipResultFile = new File(tinPath, "tin.gz"); //$NON-NLS-1$ final ITriangleEater tinEater = NodeResultHelper.createTinEater(tinZipResultFile, parameter, crs); multiEater.addEater(tinEater); } } } final NodeResultsHandler handler = new NodeResultsHandler(resultWorkspace, multiEater, m_flowModel, m_controlModel, m_discModel, resultMinMaxCatcher, lsHandler, m_mapResults); convTelemac.setModelElementHandler(handler); logger.takeInterimTime(); logger.printCurrentInterim(Messages .getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.54", m_inputFile.getName())); //$NON-NLS-1$ System.out.println(stepDate); int iStep = resolveStepNr(stepDate); convTelemac.feedHandler(iStep); logger.takeInterimTime(); logger.printCurrentInterim( Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.56")); //$NON-NLS-1$ if (m_boolDoFullEvaluate) { convTelemac.feedHandlerWithTriangles(); } // finish MultiEater and engage serializer KalypsoModel1D2DDebug.SIMULATIONRESULT.printf("%s", //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.58")); //$NON-NLS-1$ multiEater.finished(); KalypsoModel1D2DDebug.SIMULATIONRESULT.printf("%s", //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.60")); //$NON-NLS-1$ /* Node-GML in Datei schreiben */ GmlSerializer.serializeWorkspace(gmlZipResultFile, resultWorkspace, "UTF-8"); //$NON-NLS-1$UTF-8 /* LengthSection in Datei schreiben */ final ICalculationUnit1D[] calcUnits = lsHandler.getCalcUnits(); for (final ICalculationUnit1D calcUnit : calcUnits) { final File lsObsFile = new File(resultOutputDir, "lengthSection_" + calcUnit.getId() + ".gml"); //$NON-NLS-1$ //$NON-NLS-2$ final IObservation<TupleResult> lsObs = lsHandler.getObservation(calcUnit); final GMLWorkspace lsObsWorkspace = lsHandler.getWorkspace(calcUnit); if (lsObs.getResult().size() > 0) { ObservationFeatureFactory.toFeature(lsObs, lsObsWorkspace.getRootFeature()); GmlSerializer.serializeWorkspace(lsObsFile, lsObsWorkspace, "UTF-8"); //$NON-NLS-1$ /* length section entry in result db */ // TODO: use station range for min max... ResultMeta1d2dHelper.addDocument(stepResultMeta, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.65") //$NON-NLS-1$ + calcUnit.getName(), Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.66"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.lengthSection, new Path(lsObsFile.getName()), Status.OK_STATUS, new BigDecimal(0), new BigDecimal(0)); } } logger.takeInterimTime(); logger.printCurrentInterim( Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.67")); //$NON-NLS-1$ BigDecimal min; BigDecimal max; if (m_boolDoFullEvaluate) { for (final ResultType parameter : m_parameters) { /* GML(s) */ /* result db */ switch (parameter) { case TERRAIN: if (stepResultMeta != null && !ResultMeta1d2dHelper.containsTerrain(stepResultMeta)) { /* check if there exists already an entry for terrainTin */ final ICalcUnitResultMeta calcUnitResult = (ICalcUnitResultMeta) stepResultMeta .getOwner(); min = new BigDecimal(resultMinMaxCatcher.getMinTerrain()).setScale(3, BigDecimal.ROUND_HALF_UP); max = new BigDecimal(resultMinMaxCatcher.getMaxTerrain()).setScale(3, BigDecimal.ROUND_HALF_UP); ResultMeta1d2dHelper.addDocument(calcUnitResult, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.68"), //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.69"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.tinTerrain, new Path("model/Tin/tin_TERRAIN.gz"), Status.OK_STATUS, min, max); //$NON-NLS-1$ } break; case DEPTH: // TODO: Handle minimum at infinity min = new BigDecimal(resultMinMaxCatcher.getMinDepth()).setScale(3, BigDecimal.ROUND_HALF_UP); max = new BigDecimal(resultMinMaxCatcher.getMaxDepth()).setScale(3, BigDecimal.ROUND_HALF_UP); ResultMeta1d2dHelper.addDocument(stepResultMeta, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.71"), //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.1"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.tinDepth, new Path("Tin/tin_DEPTH.gz"), //$NON-NLS-1$ Status.OK_STATUS, min, max); break; case VELOCITY: min = new BigDecimal(resultMinMaxCatcher.getMinVelocityAbs()).setScale(3, BigDecimal.ROUND_HALF_UP); max = new BigDecimal(resultMinMaxCatcher.getMaxVelocityAbs()).setScale(3, BigDecimal.ROUND_HALF_UP); ResultMeta1d2dHelper.addDocument(stepResultMeta, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.74"), //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.75"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.tinVelo, new Path("Tin/tin_VELOCITY.gz"), //$NON-NLS-1$ Status.OK_STATUS, min, max); break; case VELOCITY_X: min = new BigDecimal(resultMinMaxCatcher.getMinVelocityAbs()).setScale(3, BigDecimal.ROUND_HALF_UP); max = new BigDecimal(resultMinMaxCatcher.getMaxVelocityAbs()).setScale(3, BigDecimal.ROUND_HALF_UP); ResultMeta1d2dHelper.addDocument(stepResultMeta, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.77"), //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.78"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.tinVelo, new Path("Tin/tin_VELOCITY_X.gz"), //$NON-NLS-1$ Status.OK_STATUS, min, max); break; case VELOCITY_Y: min = new BigDecimal(resultMinMaxCatcher.getMinVelocityAbs()).setScale(3, BigDecimal.ROUND_HALF_UP); max = new BigDecimal(resultMinMaxCatcher.getMaxVelocityAbs()).setScale(3, BigDecimal.ROUND_HALF_UP); ResultMeta1d2dHelper.addDocument(stepResultMeta, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.80"), //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.81"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.tinVelo, new Path("Tin/tin_VELOCITY_Y.gz"), //$NON-NLS-1$ Status.OK_STATUS, min, max); break; case WATERLEVEL: min = new BigDecimal(resultMinMaxCatcher.getMinWaterlevel()).setScale(3, BigDecimal.ROUND_HALF_UP); max = new BigDecimal(resultMinMaxCatcher.getMaxWaterlevel()).setScale(3, BigDecimal.ROUND_HALF_UP); ResultMeta1d2dHelper.addDocument(stepResultMeta, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.83"), //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.84"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.tinWsp, new Path("Tin/tin_WATERLEVEL.gz"), //$NON-NLS-1$ Status.OK_STATUS, min, max); break; case SHEARSTRESS: min = new BigDecimal(resultMinMaxCatcher.getMinShearStress()).setScale(3, BigDecimal.ROUND_HALF_UP); max = new BigDecimal(resultMinMaxCatcher.getMaxShearStress()).setScale(3, BigDecimal.ROUND_HALF_UP); ResultMeta1d2dHelper.addDocument(stepResultMeta, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.86"), //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.87"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.tinShearStress, new Path("Tin/tin_SHEARSTRESS.gz"), Status.OK_STATUS, min, max); //$NON-NLS-1$ break; default: throw new UnsupportedOperationException(); } } } // we will set all min max results to the node results meta also ResultMeta1d2dHelper.addDocument(stepResultMeta, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.89"), //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.90"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.nodes, new Path("results.gz"), Status.OK_STATUS, //$NON-NLS-1$ resultMinMaxCatcher); // TODO: maybe check if time and stepTime are equal? if (stepResultMeta != null) ResultMeta1d2dHelper.addToResultDB(stepResultMeta, stepDate, resultOutputDir); // return gmlZipResultFile; } // catch( CoreException | IOException | GmlSerializeException | GMLSchemaException e ) catch (Exception e) { e.printStackTrace(); final String msg = "error while reading telemac results"; return new Status(IStatus.ERROR, PluginUtilities.id(KalypsoModel1D2DPlugin.getDefault()), msg, e); } finally { // IOUtils.closeQuietly( is ); logger.takeInterimTime(); logger.printCurrentInterim( Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.92")); //$NON-NLS-1$ runtime.gc(); } } return Status.OK_STATUS; }
From source file:org.kalypso.kalypsomodel1d2d.sim.ProcessResultTelemacOperation.java
private FileObject getOrUnzipResult(final FileObject input, final File outputDir) { FileObject inputFile = input; FileObject outputFile = input; if (inputFile.getName().getFriendlyURI().endsWith("zip")) //$NON-NLS-1$ {/*w w w. ja v a 2 s.c o m*/ try { ZipUtilities.unzip(new File(inputFile.getURL().toURI()), new File(outputDir.toURI())); List<String> listNames = ZipUtilities.getFilesNamesFromZip(inputFile.getURL()); if (listNames.size() > 1 || listNames.isEmpty()) { // should not be return null; } outputFile = m_vfsManager.resolveFile(outputDir, listNames.get(0)); //$NON-NLS-1$ } catch (IOException | URISyntaxException e) { e.printStackTrace(); return null; } } return outputFile; }
From source file:org.kalypso.kalypsomodel1d2d.sim.ResultManager.java
private void prepareSWANResults() throws ZipException, IOException, URISyntaxException, FileSystemException, MalformedURLException { if (!m_resultDirSWAN.getName().getBaseName().endsWith("zip")) //$NON-NLS-1$ {/*from w w w.j a va 2s . c om*/ try { final FileObject swanResFile = m_resultDirSWAN .getChild(ISimulation1D2DConstants.SIM_SWAN_TRIANGLE_FILE + "." //$NON-NLS-1$ + ISimulation1D2DConstants.SIM_SWAN_MAT_RESULT_EXT); final FileObject swanResShiftFile = m_resultDirSWAN .getChild(ISimulation1D2DConstants.SIM_SWAN_COORD_SHIFT_FILE); final FileObject swanResOutTabFile = m_resultDirSWAN .getChild(ISimulation1D2DConstants.SIM_SWAN_TRIANGLE_FILE + "_out.tab"); //$NON-NLS-1$ processSWANTabFile(swanResOutTabFile, swanResShiftFile); final File zipOutput = new File(m_outputDir, ISimulation1D2DConstants.SIM_SWAN_TRIANGLE_FILE + ".zip"); //$NON-NLS-1$ final List<File> lListFilesToZip = new ArrayList<>(); lListFilesToZip.add(new File(swanResFile.getURL().toURI())); lListFilesToZip.add(new File(swanResShiftFile.getURL().toURI())); lListFilesToZip.add(new File(swanResOutTabFile.getURL().toURI())); if (m_controlModel.getINITialValuesSWAN() == 3) { final FileObject swanResHotFile = m_resultDirSWAN .getChild(ISimulation1D2DConstants.SIM_SWAN_HOT_FILE); lListFilesToZip.add(new File(swanResHotFile.getURL().toURI())); } ZipUtilities.zip(zipOutput, lListFilesToZip.toArray(new File[lListFilesToZip.size()]), new File(m_resultDirSWAN.getURL().toURI())); swanResFile.close(); swanResShiftFile.close(); swanResOutTabFile.close(); } catch (final Exception e) { e.printStackTrace(); } } else { // swan mat file should be unpacked for using in within JMatIO-Reader, so we put the uncompressed version in // to the working directory. ZipUtilities.unzip(new File(m_resultDirSWAN.getURL().toURI()), new File(m_outputDir.toURI())); m_resultDirSWAN = m_vfsManager.resolveFile(m_outputDir.toURI().toURL().toExternalForm()); } }
From source file:org.kalypso.kalypsomodel1d2d.sim.SwanResultProcessor.java
public IStatus execute() { try {//from w ww. j av a 2s . c o m if (m_swanResultDir.getName().getBaseName().endsWith("zip")) //$NON-NLS-1$ { // swan mat file should be unpacked for using in within JMatIO-Reader, so we put the uncompressed version in // to the working directory. ZipUtilities.unzip(new File(m_swanResultDir.getURL().toURI()), new File(m_outputDir.toURI())); // FIXME: why is the result dir changed here? // TODO: hm, maybe this was intended to process the unpacked result, so we should not return? m_swanResultDir = VFSUtilities.getNewManager() .resolveFile(m_outputDir.toURI().toURL().toExternalForm()); return Status.OK_STATUS; } final FileObject swanResFile = m_swanResultDir.getChild(ISimulation1D2DConstants.SIM_SWAN_TRIANGLE_FILE + "." + ISimulation1D2DConstants.SIM_SWAN_MAT_RESULT_EXT); //$NON-NLS-1$ final FileObject swanResShiftFile = m_swanResultDir .getChild(ISimulation1D2DConstants.SIM_SWAN_COORD_SHIFT_FILE); final FileObject swanResOutTabFile = m_swanResultDir .getChild(ISimulation1D2DConstants.SIM_SWAN_TRIANGLE_FILE + "_out.tab"); //$NON-NLS-1$ processSWANTabFile(swanResOutTabFile, swanResShiftFile); final File zipOutput = new File(m_outputDir, ISimulation1D2DConstants.SIM_SWAN_TRIANGLE_FILE + ".zip"); //$NON-NLS-1$ final List<File> lListFilesToZip = new ArrayList<>(); lListFilesToZip.add(new File(swanResFile.getURL().toURI())); lListFilesToZip.add(new File(swanResShiftFile.getURL().toURI())); lListFilesToZip.add(new File(swanResOutTabFile.getURL().toURI())); if (m_controlModel.getINITialValuesSWAN() == 3) { final FileObject swanResHotFile = m_swanResultDir .getChild(ISimulation1D2DConstants.SIM_SWAN_HOT_FILE); lListFilesToZip.add(new File(swanResHotFile.getURL().toURI())); } ZipUtilities.zip(zipOutput, lListFilesToZip.toArray(new File[lListFilesToZip.size()]), new File(m_swanResultDir.getURL().toURI())); return Status.OK_STATUS; } catch (final IOException e) { // FIXME: This is not real error handling! e.printStackTrace(); return StatusUtilities.statusFromThrowable(e); } catch (final URISyntaxException e) { // FIXME: This is not real error handling! // TODO Auto-generated catch block e.printStackTrace(); return StatusUtilities.statusFromThrowable(e); } }
From source file:org.kalypso.project.database.common.utils.PlanerClientFileSystemManager.java
private boolean isFtpProtocol(final FileObject baseFile, final String uri) throws FileSystemException { if (baseFile != null) { final URL url = baseFile.getURL(); if (url.getProtocol().toLowerCase().startsWith("ftp")) //$NON-NLS-1$ return true; }//from www . j av a 2 s. c o m return isFtpProtocol(uri); }
From source file:org.kalypso.service.wps.client.NonBlockingWPSRequest.java
/** * Starts the simulation.// www. j ava 2 s . c o m * * @param monitor * The progress monitor. */ public IStatus run(IProgressMonitor monitor) { // TODO: clear old results: No not here! We have to introduce additional operation to the service // So the client can tell the server to release any resources. /* Monitor. */ monitor = SubMonitor.convert(monitor, Messages.getString("org.kalypso.service.wps.client.NonBlockingWPSRequest.4"), 200); //$NON-NLS-1$ KalypsoServiceWPSDebug.DEBUG.printf("Checking for service URL ...\n"); //$NON-NLS-1$ /* Check, if we have a service endpoint. */ if (m_serviceEndpoint == null) { KalypsoServiceWPSDebug.DEBUG.printf("No URL to the service is given.\n"); //$NON-NLS-1$ return StatusUtilities.statusFromThrowable( new WPSException(Messages.getString("org.kalypso.service.wps.client.NonBlockingWPSRequest.3"))); //$NON-NLS-1$ } /* Send the request. */ ExecuteResponseType executeResponse; final CodeType simulationIdentifier = WPS040ObjectFactoryUtilities.buildCodeType("", m_identifier); //$NON-NLS-1$ try { // decide between local and remote invocation if (WPSRequest.SERVICE_LOCAL.equals(m_serviceEndpoint)) { FileObject resultFile = null; try { /* Execute the simulation via a manager, so that more than one simulation can be run at the same time. */ final Execute execute = WPS040ObjectFactoryUtilities.buildExecute(simulationIdentifier, m_dataInputs, m_outputDefinitions, true, true); final WPSSimulationManager manager = WPSSimulationManager.getInstance(); final ExecuteMediator executeMediator = new ExecuteMediator(execute); final WPSSimulationInfo info = manager.startSimulation(executeMediator); m_jobId = info.getId(); /* Prepare the execute response. */ final FileObject resultDir = manager.getResultDir(info.getId()); resultFile = resultDir.resolveFile("executeResponse.xml"); //$NON-NLS-1$ final String statusLocation = WPSUtilities .convertInternalToClient(resultFile.getURL().toExternalForm()); final StatusType status = WPS040ObjectFactoryUtilities.buildStatusType("Process accepted.", //$NON-NLS-1$ true); executeResponse = WPS040ObjectFactoryUtilities.buildExecuteResponseType(simulationIdentifier, status, m_dataInputs, m_outputDefinitions, null, statusLocation, WPSUtilities.WPS_VERSION.V040.toString()); } catch (final IOException e) { throw new CoreException(StatusUtilities.statusFromThrowable(e)); } catch (final SimulationException e) { throw new CoreException(StatusUtilities.statusFromThrowable(e)); } catch (final OWSException e) { throw new CoreException(StatusUtilities.statusFromThrowable(e)); } finally { if (resultFile != null) try { resultFile.close(); } catch (final FileSystemException e) { // gobble } } } else { executeResponse = WPSUtilities.callExecute(m_serviceEndpoint, m_identifier, m_dataInputs, m_outputDefinitions); } } catch (final CoreException e) { return e.getStatus(); } final StatusType status = executeResponse.getStatus(); final ProcessFailedType processFailed = status.getProcessFailed(); if (processFailed != null) { final String errorString = WPSUtilities.createErrorString(processFailed.getExceptionReport()); return StatusUtilities.createErrorStatus(errorString); } /* If the user aborted the job. */ monitor.worked(100); if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } /* Retrieve the path to the status file of the process. */ m_statusLocation = executeResponse.getStatusLocation(); /* Finish. */ monitor.worked(100); return Status.OK_STATUS; }