List of usage examples for org.apache.commons.vfs2 FileObject isContentOpen
boolean isContentOpen();
From source file:org.jahia.modules.external.vfs.VFSDataSource.java
@Override public void move(String oldPath, String newPath) throws RepositoryException { if (oldPath.equals(newPath)) { return;//w w w .ja v a 2 s .c om } try { FileObject origin = getFile(oldPath); if (origin.isContentOpen()) { origin.close(); } FileObject destination = getFile(newPath); if (destination.exists() && destination.isContentOpen()) { destination.close(); } origin.moveTo(destination); } catch (FileSystemException e) { throw new RepositoryException(oldPath, e); } }
From source file:org.kalypso.kalypsomodel1d2d.sim.ResultManager.java
private void processSWANTabFile(final FileObject swanResOutTabFile, final FileObject swanResShiftFile) { final GM_Position lShiftPosition = SWANDataConverterHelper.readCoordinateShiftValues(swanResShiftFile); if (lShiftPosition == null) { return;//from w ww .j a va2 s .c o m } try { if (swanResOutTabFile.isContentOpen()) { swanResOutTabFile.close(); } final FileObject swanResOutTabFileBackUp = swanResOutTabFile.getParent() .resolveFile(swanResOutTabFile.getName().getBaseName() + ".bck"); //$NON-NLS-1$ swanResOutTabFile.moveTo(swanResOutTabFileBackUp); // int lIntLinesCounter = 0; final OutputStream lOutStream = swanResOutTabFile.getContent().getOutputStream(); final DataInputStream lInDataStream = new DataInputStream( swanResOutTabFileBackUp.getContent().getInputStream()); BufferedReader streamReader = new BufferedReader(new InputStreamReader(lInDataStream)); final Formatter lFormatter = new Formatter(lOutStream, Charset.defaultCharset().name(), Locale.US); while (lInDataStream.available() != 0) { final String lStrTmpLine = streamReader.readLine().trim(); // ++lIntLinesCounter; if (lStrTmpLine.startsWith("%")) { //$NON-NLS-1$ lFormatter.format("%s\n", lStrTmpLine); //$NON-NLS-1$ continue; } final StringTokenizer lStrTokenizer = new StringTokenizer(lStrTmpLine, " "); //$NON-NLS-1$ int lIntTokenCounter = 0; String lStrNewLine = ""; //$NON-NLS-1$ while (lStrTokenizer.hasMoreTokens()) { final String lStrToken = lStrTokenizer.nextToken(); if (lIntTokenCounter == 1) { lStrNewLine += String.format(Locale.US, "%.5f\t", //$NON-NLS-1$ NumberUtils.parseQuietDouble(lStrToken) + lShiftPosition.getX()); } else if (lIntTokenCounter == 2) { lStrNewLine += String.format(Locale.US, "%.5f\t", //$NON-NLS-1$ NumberUtils.parseQuietDouble(lStrToken) + lShiftPosition.getY()); } else { lStrNewLine += lStrToken + "\t"; //$NON-NLS-1$ } lIntTokenCounter++; } lFormatter.format("%s\n", lStrNewLine); //$NON-NLS-1$ } lFormatter.close(); lInDataStream.close(); lOutStream.close(); } catch (final Exception e) { return; } return; }
From source file:org.kalypso.kalypsomodel1d2d.sim.SwanResultProcessor.java
private void processSWANTabFile(final FileObject swanResOutTabFile, final FileObject swanResShiftFile) { final GM_Position lShiftPosition = SWANDataConverterHelper.readCoordinateShiftValues(swanResShiftFile); if (lShiftPosition == null) return;/* ww w . j a va2 s . c o m*/ try { // FIXME: why?! should never happen...! if (swanResOutTabFile.isContentOpen()) swanResOutTabFile.close(); final FileObject swanResOutTabFileBackUp = swanResOutTabFile.getParent() .resolveFile(swanResOutTabFile.getName().getBaseName() + ".bck"); //$NON-NLS-1$ swanResOutTabFile.moveTo(swanResOutTabFileBackUp); final OutputStream lOutStream = swanResOutTabFile.getContent().getOutputStream(); final Formatter lFormatter = new Formatter(lOutStream, Charset.defaultCharset().name(), Locale.US); final BufferedReader lInDataStream = new BufferedReader( new InputStreamReader(swanResOutTabFileBackUp.getContent().getInputStream())); while (lInDataStream.ready()) { final String lStrTmpLine = lInDataStream.readLine().trim(); if (lStrTmpLine.startsWith("%")) //$NON-NLS-1$ { lFormatter.format("%s\n", lStrTmpLine); //$NON-NLS-1$ continue; } final StringTokenizer lStrTokenizer = new StringTokenizer(lStrTmpLine, " "); //$NON-NLS-1$ int lIntTokenCounter = 0; String lStrNewLine = ""; //$NON-NLS-1$ while (lStrTokenizer.hasMoreTokens()) { final String lStrToken = lStrTokenizer.nextToken(); if (lIntTokenCounter == 1) { lStrNewLine += String.format(Locale.US, "%.5f\t", //$NON-NLS-1$ NumberUtils.parseQuietDouble(lStrToken) + lShiftPosition.getX()); } else if (lIntTokenCounter == 2) { lStrNewLine += String.format(Locale.US, "%.5f\t", //$NON-NLS-1$ NumberUtils.parseQuietDouble(lStrToken) + lShiftPosition.getY()); } else { lStrNewLine += lStrToken + "\t"; //$NON-NLS-1$ } lIntTokenCounter++; } lFormatter.format("%s\n", lStrNewLine); //$NON-NLS-1$ } // FIXME: not closed in a save way! lFormatter.close(); lInDataStream.close(); lOutStream.close(); } catch (final Exception e) { // FIXME: this is no way to handle an error ! } }