List of usage examples for org.apache.commons.io FileUtils toFile
public static File toFile(URL url)
URL
to a File
. From source file:org.kalypso.calculation.plc.postprocessing.PLCPreprocessingSimulation.java
private void doWspmModel(final ISimulationDataProvider inputProvider, final File statusQuoFolder) throws SimulationException, IOException { if (!inputProvider.hasID(INPUT_WSPM_MODEL)) return;//from w w w . j a va 2 s . c o m final File actualWspmModel = FileUtils.toFile((URL) inputProvider.getInputForID(INPUT_WSPM_MODEL)); FileUtils.copyDirectoryToDirectory(actualWspmModel, statusQuoFolder); }
From source file:org.kalypso.calculation.plc.postprocessing.PLCPreprocessingSimulation.java
private void do1D2DModel(final ISimulationDataProvider inputProvider, final File statusQuoFolder) throws SimulationException, IOException { if (!inputProvider.hasID(INPUT_1D2D_MODEL)) return;//w ww. ja v a 2s.c o m final File actual1d2dCalcUnitFolder = FileUtils.toFile((URL) inputProvider.getInputForID(INPUT_1D2D_MODEL)); // FileUtils.moveDirectory( actual1d2dCalcUnitFolder, statusQuoFolder ) ); FileUtils.copyDirectory(actual1d2dCalcUnitFolder, statusQuoFolder); }
From source file:org.kalypso.calculation.plc.postprocessing.PLCPreprocessingSimulation.java
/** * move flood outputs to status quo/*from w w w. ja v a2 s.co m*/ */ private void doFloodModel(final ISimulationDataProvider inputProvider, final File statusQuoFolder) throws SimulationException, IOException { if (!inputProvider.hasID(INPUT_FLOOD_MODEL)) return; final File actualFloodModel = FileUtils.toFile((URL) inputProvider.getInputForID(INPUT_FLOOD_MODEL)); FileUtils.copyFileToDirectory(actualFloodModel, new File(statusQuoFolder, "models")); //$NON-NLS-1$ final File actualFloodResults = FileUtils .toFile((URL) inputProvider.getInputForID(INPUT_FLOOD_RESULT_FOLDER)); final File statusQuoFloodResults = new File(statusQuoFolder, "events"); //$NON-NLS-1$ FileUtils.moveDirectory(actualFloodResults, statusQuoFloodResults); }
From source file:org.kalypso.calculation.plc.postprocessing.PLCPreprocessingSimulation.java
/** * move risk outputs to status quo// w w w . j a v a 2 s . co m */ private void doRiskModel(final ISimulationDataProvider inputProvider, final File statusQuoFolder) throws SimulationException, IOException { if (!inputProvider.hasID(INPUT_RISK_MODEL)) return; final File actualRasterModel = FileUtils.toFile((URL) inputProvider.getInputForID(INPUT_RISK_MODEL)); FileUtils.copyFileToDirectory(actualRasterModel, statusQuoFolder); final File actualRasterFolderOutput = FileUtils .toFile((URL) inputProvider.getInputForID(INPUT_RISK_RESULT_FOLDER)); final File statusQuoRasterFolderOutput = new File(statusQuoFolder, "raster/output"); //$NON-NLS-1$ FileUtils.moveDirectory(actualRasterFolderOutput, statusQuoRasterFolderOutput); }
From source file:org.kalypso.commons.java.net.UrlUtilities.java
/** * Tires to find a 'lastModified' timestamp from an {@link URL}. *//* ww w .j a va 2 s. c o m*/ public static Date lastModified(final URL location) { if (location == null) return null; try { final URLConnection connection = location.openConnection(); connection.connect(); final long lastModified = connection.getLastModified(); // BUGFIX: some URLConnection implementations (such as eclipse resource-protokoll) // do not return lastModified correctly. If we have such a case, we try some more... if (lastModified != 0) return new Date(lastModified); final File file = FileUtils.toFile(location); if (file != null) return new Date(file.lastModified()); final IPath path = ResourceUtilities.findPathFromURL(location); if (path == null) return null; final File resourceFile = ResourceUtilities.makeFileFromPath(path); return new Date(resourceFile.lastModified()); } catch (final IOException e) { // ignore, some resources cannot be checked at all } return null; }
From source file:org.kalypso.commons.java.net.UrlUtilities.java
public static long getContentLength(final URL url) throws IOException { final File file = FileUtils.toFile(url); if (file != null) return file.length(); final File platformFile = ResourceUtilities.findJavaFileFromURL(url); if (platformFile != null) return platformFile.length(); final URLConnection connection = url.openConnection(); return connection.getContentLength(); }
From source file:org.kalypso.gml.processes.constDelaunay.ConstraintDelaunayHelper.java
public static File findTriangleExe() { // check system path final String triangleName = "triangle.exe"; //$NON-NLS-1$ final File onPath = FileUtilities.findExecutableOnPath(triangleName); if (onPath != null) return onPath; // check Kalypso/bin folder final Location installLocation = Platform.getInstallLocation(); final File installDir = FileUtils.toFile(installLocation.getURL()); final File binDir = new File(installDir, "bin"); //$NON-NLS-1$ final File inBin = new File(binDir, triangleName); if (inBin.isFile()) return inBin; // not found/*from w w w. j av a 2s . c o m*/ return null; }
From source file:org.kalypso.gml.ui.coverage.CoverageManagementHelper.java
/** * Returns an existing grid file.<br> *//*from w w w. j ava2s . c o m*/ private static File toJavaFile(final URL url) { /* Tries to find a file from the given url. */ File fileFromUrl = ResourceUtilities.findJavaFileFromURL(url); if (fileFromUrl == null) fileFromUrl = FileUtils.toFile(url); return fileFromUrl; }
From source file:org.kalypso.grid.BinaryGeoGrid.java
/** * Opens an existing grid for read-only access.<br> * Dispose the grid after it is no more needed in order to release the given resource. * /*from w w w. j a v a2 s .com*/ * @param writeable * If <code>true</code>, the grid is opened for writing and a {@link IWriteableGeoGrid} is returned. */ public static BinaryGeoGrid openGrid(final URL url, final Coordinate origin, final Coordinate offsetX, final Coordinate offsetY, final String sourceCRS, final boolean writeable) throws IOException { /* Tries to find a file from the given url. */ File fileFromUrl = ResourceUtilities.findJavaFileFromURL(url); File binFile = null; if (fileFromUrl == null) fileFromUrl = FileUtils.toFile(url); if (fileFromUrl == null) { /* * If url cannot be converted to a file, write its contents to a temporary file which will be deleted after the * grid gets disposed. */ fileFromUrl = File.createTempFile("local", ".bin"); fileFromUrl.deleteOnExit(); FileUtils.copyURLToFile(url, fileFromUrl); binFile = fileFromUrl; // set in order to delete on dispose } FileChannel channel; if (writeable) channel = FileChannel.open(fileFromUrl.toPath(), StandardOpenOption.WRITE, StandardOpenOption.READ); else channel = FileChannel.open(fileFromUrl.toPath(), StandardOpenOption.READ); return new BinaryGeoGrid(channel, binFile, origin, offsetX, offsetY, sourceCRS); }
From source file:org.kalypso.grid.BinaryGeoGridReader.java
public BinaryGeoGridReader(final IGeoGrid inputGrid, final URL pUrl) throws IOException { super(inputGrid); File fileFromUrl = ResourceUtilities.findJavaFileFromURL(pUrl); /* Tries to find a file from the given url. */ if (fileFromUrl == null) fileFromUrl = FileUtils.toFile(pUrl); m_gridStream = new BufferedInputStream(new FileInputStream(fileFromUrl)); // skip header /* Read header */ m_gridStream.skip(12);//from www . j av a 2s . c o m final byte[] lScaleBuff = new byte[4]; read(lScaleBuff, 1); m_scale = ByteUtils.readBEInt(lScaleBuff, 0); try { m_linesTotal = getSizeY(); m_lineLen = getSizeX() * 4; } catch (final GeoGridException e) { e.printStackTrace(); } // block_size is set to "optimal" size of the buffer from start on m_linesInBlock = BLOCK_SIZE / m_lineLen; if (m_linesInBlock >= m_linesTotal) m_linesInBlock = m_linesTotal; if (m_linesInBlock == 0) m_linesInBlock = 1; BLOCK_SIZE = m_linesInBlock * m_lineLen; m_blockData = new byte[BLOCK_SIZE]; readNextBlock(); m_blockStart = 0; m_blockEnd = m_linesInBlock - 1; }