List of usage examples for org.apache.commons.vfs FileSystemException getLocalizedMessage
public String getLocalizedMessage()
From source file:jfs.sync.vfs.JFSVFSFile.java
/** * @see JFSFile#getLength()/*from w w w .jav a2 s . c o m*/ */ public long getLength() { if (file == null || isDirectory()) { return 0; } try { return file.getContent().getSize(); } catch (FileSystemException e) { JFSLog.getErr().getStream().println(e.getLocalizedMessage()); return 0; } }
From source file:jfs.sync.vfs.JFSVFSFile.java
/** * @see JFSFile#isDirectory()/* ww w . jav a2s . com*/ */ public boolean isDirectory() { if (file == null) { return false; } try { return file.getType().equals(FileType.FOLDER); } catch (FileSystemException e) { JFSLog.getErr().getStream().println(e.getLocalizedMessage()); return false; } }
From source file:jfs.sync.vfs.JFSVFSFile.java
/** * @see JFSFile#getInputStream()//w w w .j a va2 s .c o m */ protected InputStream getInputStream() { if (file == null) { return null; } try { return file.getContent().getInputStream(); } catch (FileSystemException e) { JFSLog.getErr().getStream().println(e.getLocalizedMessage()); return null; } }
From source file:jfs.sync.vfs.JFSVFSFile.java
/** * @see JFSFile#setLastModified(long)/*from www . ja v a 2s . c om*/ */ public boolean setLastModified(long time) { if (file == null) { return false; } try { file.getContent().setLastModifiedTime(time); return true; } catch (FileSystemException e) { JFSLog.getErr().getStream().println(e.getLocalizedMessage()); return false; } }
From source file:jfs.sync.vfs.JFSVFSFile.java
/** * @see JFSFile#postCopyTgt(JFSFile)//from w w w. j a v a 2s. c o m */ protected boolean postCopyTgt(JFSFile srcFile) { try { if (!srcFile.isDirectory()) { file.getContent().setLastModifiedTime(srcFile.getLastModified()); } file.refresh(); return true; } catch (FileSystemException e) { JFSLog.getErr().getStream().println(e.getLocalizedMessage()); return false; } }
From source file:jfs.sync.vfs.JFSVFSFile.java
/** * @see JFSFile#mkdir()/*from w w w . j av a 2 s .c om*/ */ public boolean mkdir() { if (file == null) { return false; } try { file.createFolder(); file.refresh(); return true; } catch (FileSystemException e) { JFSLog.getErr().getStream().println(e.getLocalizedMessage()); return false; } }
From source file:jfs.sync.vfs.JFSVFSFile.java
/** * @see JFSFile#getList()/*from w w w. j ava 2 s . c o m*/ */ public JFSFile[] getList() { if (file == null) { return new JFSVFSFile[0]; } try { if (list == null) { FileObject[] files = file.getChildren(); if (files != null) { list = new JFSVFSFile[files.length]; for (int i = 0; i < files.length; i++) { list[i] = new JFSVFSFile(fileProducer, files[i], getRelativePath() + "/" + files[i].getName().getBaseName()); } } else { list = new JFSVFSFile[0]; } } } catch (FileSystemException e) { JFSLog.getErr().getStream().println(e.getLocalizedMessage()); list = new JFSVFSFile[0]; } return list; }
From source file:org.apache.ivy.plugins.repository.vfs.VfsRepository.java
private StandardFileSystemManager createVFSManager() throws IOException { StandardFileSystemManager result = null; try {/* w ww. j av a 2 s .co m*/ /* * The DefaultFileSystemManager gets its configuration from the jakarta-vfs-common * implementation which includes the res and tmp schemes which are of no use to use * here. Using StandardFileSystemManager lets us specify which schemes to support as * well as providing a mechanism to change this support without recompilation. */ result = new StandardFileSystemManager() { protected void configurePlugins() throws FileSystemException { // disable automatic loading potential unsupported extensions } }; result.setConfiguration(getClass().getResource(IVY_VFS_CONFIG)); result.init(); // Generate and print a list of available schemes Message.verbose("Available VFS schemes..."); String[] schemes = result.getSchemes(); Arrays.sort(schemes); for (int i = 0; i < schemes.length; i++) { Message.verbose("VFS Supported Scheme: " + schemes[i]); } } catch (FileSystemException e) { /* * If our attempt to initialize a VFS Repository fails we log the failure but continue * on. Given that an Ivy instance may involve numerous different repository types, it * seems overly cautious to throw a runtime exception on the initialization failure of * just one repository type. */ Message.error("Unable to initialize VFS repository manager!"); Message.error(e.getLocalizedMessage()); IOException error = new IOException(e.getLocalizedMessage()); error.initCause(e); throw error; } return result; }
From source file:org.apache.ivy.plugins.repository.vfs.VfsResource.java
private void init() { if (!init) {// w w w . ja v a 2 s .c om try { resourceImpl = fsManager.resolveFile(vfsURI); content = resourceImpl.getContent(); exists = resourceImpl.exists(); lastModified = content.getLastModifiedTime(); contentLength = content.getSize(); } catch (FileSystemException e) { Message.debug(e); Message.verbose(e.getLocalizedMessage()); exists = false; lastModified = 0; contentLength = 0; } init = true; } }
From source file:org.kalypso.dwd.servlet.dwdfilecopy.DWDCopyTask.java
@Override public void run() { FileObject newFile = null;//from www .j a v a 2 s . c o m try { /* Check for the file or the base file (this could be a directory). */ m_fo = m_fsManager.resolveFile(m_URI); if (m_fo.getType() != FileType.FOLDER) { System.out.println("The URI " + m_URI + " is no folder."); return; } /* Get all elements in this directory. */ m_list = m_fo.getChildren(); if (m_list.length == 0) { DWDFileCopyServlet.LOG.warning("There are no files in the Source:" + m_fo.getName().toString()); return; } /* Find the newest file. */ newFile = getNewestFile(); if (newFile == null) return; DWDFileCopyServlet.LOG.info("Newest file: " + newFile.getName().getBaseName().toString()); } catch (FileSystemException e) { DWDFileCopyServlet.LOG.warning("Error resolving the URI: " + e.getLocalizedMessage()); return; } finally { } // looping twice over this code in the case an exception // occurs, we try it again... for (int i = 0; i < 2; i++) { FileOutputStream os = null; InputStream is = null; try { final Date newestDate = getDateFromRaster(newFile, m_dateFormat); final Date destFileDate = getDateFromRasterContent(m_destFile); DWDFileCopyServlet.LOG.info("Date of newest file: " + newestDate); DWDFileCopyServlet.LOG.info("Date of destination file: " + destFileDate); // if dest file either does not exist or is not up to date, overwrite with current DWD forecast if (destFileDate == null || newestDate.after(destFileDate)) { /* Copy the newest file. */ DWDFileCopyServlet.LOG.info("Copying ..."); final File dwdDest; if (m_destUpdate) dwdDest = new File(m_destFile.getParentFile(), newFile.getName().getBaseName()); else dwdDest = m_destFile; DWDFileCopyServlet.LOG.info("Copying DWD-File \"" + newFile.getName().getBaseName() + "\" to: " + dwdDest.getAbsolutePath()); os = new FileOutputStream(dwdDest); is = newFile.getContent().getInputStream(); /* The copy operation. */ IOUtils.copy(is, os); os.close(); is.close(); // update file contents if (m_destUpdate) { DWDFileCopyServlet.LOG.info("Updating " + m_destFile.getName() + " from " + dwdDest); DWDRasterHelper.updateDWDFileContents(dwdDest, m_destFile, m_dateFormat); m_destFile.setLastModified(newFile.getContent().getLastModifiedTime()); final boolean deleted = dwdDest.delete(); if (!deleted) DWDFileCopyServlet.LOG .warning("Could not delete temp DWD-File \"" + dwdDest.getName() + "\""); } } // delete source file if flag is set if (m_srcDel) { try { /* Delete the old files. */ DWDFileCopyServlet.LOG.info("Deleting " + newFile.getName().getBaseName()); final boolean deleted = newFile.delete(); if (!deleted) DWDFileCopyServlet.LOG.warning( "Could not delete DWD-File \"" + newFile.getName().getBaseName() + "\""); } catch (final IOException e) { DWDFileCopyServlet.LOG .warning("Could not delete DWD-File \"" + newFile.getName().getBaseName() + "\""); if (m_debug) e.printStackTrace(); } } // no exception, so end loop here return; } catch (final IOException e) { DWDFileCopyServlet.LOG.warning("Could not copy DWD-File \"" + newFile.getName().getBaseName() + "\" to folder: " + m_destFile.getAbsolutePath() + " due to: " + e.getLocalizedMessage()); if (m_debug) e.printStackTrace(); } catch (final DWDException e) { DWDFileCopyServlet.LOG.warning("DWD-File could not be updated: " + e.getLocalizedMessage()); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); } try { // make some pause before continuing Thread.sleep(500); } catch (final InterruptedException ignored) { // empty } } }