List of usage examples for java.nio.file FileAlreadyExistsException getMessage
@Override
public String getMessage()
From source file:it.infn.ct.futuregateway.apiserver.APIContextListener.java
@Override public final void contextInitialized(final ServletContextEvent sce) { log.info("Creation of the Hibernate SessionFactory for the context"); try {//from w w w. j a v a 2s .co m entityManagerFactory = Persistence .createEntityManagerFactory("it.infn.ct.futuregateway.apiserver.container"); } catch (Exception ex) { log.warn("Resource 'jdbc/FutureGatewayDB' not accessuible or" + " not properly configured for the application. An" + " alternative resource is created on the fly."); entityManagerFactory = Persistence.createEntityManagerFactory("it.infn.ct.futuregateway.apiserver.app"); } sce.getServletContext().setAttribute(Constants.SESSIONFACTORY, entityManagerFactory); String path = sce.getServletContext().getInitParameter("CacheDir"); if (path == null || path.isEmpty()) { path = sce.getServletContext().getRealPath("/") + ".." + FileSystems.getDefault().getSeparator() + ".." + FileSystems.getDefault().getSeparator() + "FutureGatewayData"; } log.info("Created the cache directory: " + path); sce.getServletContext().setAttribute(Constants.CACHEDIR, path); try { Files.createDirectories(Paths.get(path)); log.info("Cache dir enabled"); } catch (FileAlreadyExistsException faee) { log.debug("Message for '" + path + "':" + faee.getMessage()); log.info("Cache dir enabled"); } catch (Exception e) { log.error("Impossible to initialise the temporary store"); } ExecutorService tpe; try { Context ctx = new InitialContext(); tpe = (ExecutorService) ctx.lookup("java:comp/env/threads/Submitter"); } catch (NamingException ex) { log.warn("Submitter thread not defined in the container. A thread " + "pool is created using provided configuration parameters " + "and defaults values"); int threadPoolSize = Constants.DEFAULTTHREADPOOLSIZE; try { threadPoolSize = Integer .parseInt(sce.getServletContext().getInitParameter("SubmissioneThreadPoolSize")); } catch (NumberFormatException nfe) { log.info("Parameter 'SubmissioneThreadPoolSize' has a wrong" + " value or it is not present. Default value " + "10 is used"); } tpe = ThreadPoolFactory.getThreadPool(threadPoolSize, Constants.MAXTHREADPOOLSIZETIMES * threadPoolSize, Constants.MAXTHREADIDLELIFE); } sce.getServletContext().setAttribute(Constants.SUBMISSIONPOOL, tpe); }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.Converter.java
/** * Saves the html document to a file with .html extension * * @param document JDOM Document representing the HTML * @return written HTML File object/*from ww w . jav a 2 s . c om*/ */ private File saveHtmlFile(Document document) { Path tempFilepath = null; Path tempDirPath = formulaConverter.getTempDirPath(); ClassLoader classLoader = getClass().getClassLoader(); InputStream mainCssIs = classLoader.getResourceAsStream(MAIN_CSS_FILENAME); logger.debug("Copying main.css file to temp dir: " + tempDirPath.toAbsolutePath().toString()); try { Files.copy(mainCssIs, tempDirPath.resolve(MAIN_CSS_FILENAME)); } catch (FileAlreadyExistsException e) { // do nothing } catch (IOException e) { logger.error("could not copy main.css file to temp dir!"); } tempFilepath = tempDirPath.resolve("latex2mobi.html"); logger.debug("tempFile created at: " + tempFilepath.toAbsolutePath().toString()); try { Files.write(tempFilepath, new XMLOutputter().outputString(document).getBytes(Charset.forName("UTF-8"))); if (debugMarkupOutput) { logger.info("Debug markup will be generated."); } } catch (IOException e) { logger.error("Error writing HTML to temp dir!"); logger.error(e.getMessage(), e); } return tempFilepath.toFile(); }
From source file:com.spd.ukraine.lucenewebsearch1.web.IndexingController.java
@PostConstruct public void init() { if (IS_DIRECTORY_IN_DISK) { String userDirectory = System.getProperty("user.dir");// + "/lucene"; System.out.println("userDirectory " + userDirectory); Path userPath = Paths.get(userDirectory); Path rootPath = userPath.getRoot(); String workingDirectory = rootPath.toString() .concat(System.getProperty("file.separator").equals("/") ? userPath.subpath(0, 2).toString() + "/" : "\\Users\\sf\\") .concat("luceneindex"); System.out.println("workingDirectory " + workingDirectory); indexDir = new File(workingDirectory); try {/*from ww w. jav a2 s. c o m*/ Files.createDirectory(Paths.get(workingDirectory)); } catch (FileAlreadyExistsException ex) { System.out.println("FileAlreadyExistsException"); } catch (IOException ex) { // System.out.println("IOException: " + ex.getMessage()); ex.printStackTrace(); } if (null == indexDir) { return; } try { directory = FSDirectory.open(indexDir); } catch (IOException ex) { System.out.println("IOException: " + ex.getMessage()); } } else { directory = new RAMDirectory(); } analyzer = new StandardAnalyzer(Version.LUCENE_43);//new StandardAnalyzer(); IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43, analyzer); try { indexWriter = new IndexWriter(directory, config); } catch (IOException ex) { // ex.printStackTrace(); // return; } }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.Converter.java
/** * This will save the HTML markup + css file to a specified folder * * @param tempFilepath the temp folder where * @return/*from ww w . ja va 2s .c o m*/ */ private Path exportMarkup(Path tempFilepath) { Path resultPath; if (outputPath != null) { resultPath = outputPath; } else { resultPath = workingDirectory; } Path markupDir = resultPath.resolve(title + "-markup"); try { try { Files.createDirectory(markupDir); } catch (FileAlreadyExistsException e) { // do nothing } Path tempDirPath = tempFilepath.getParent(); File tempDir = tempDirPath.toFile(); // Copy all files from temp folder to the markup output folder String[] files = tempDir.list(FileFileFilter.FILE); for (int i = 0; i < files.length; i++) { Files.copy(tempDirPath.resolve(files[i]), markupDir.resolve(files[i]), StandardCopyOption.REPLACE_EXISTING); } logger.info("Exported markup to folder: " + markupDir.toAbsolutePath().toString()); } catch (IOException e) { logger.error("Error saving markup files: " + e.getMessage(), e); return null; } return markupDir; }
From source file:edu.lternet.pasta.datapackagemanager.DataPackageManagerResource.java
private void createDataFileLink(File entityFile, String dataToken) throws Exception { String msg = null;/*from w ww .j av a2 s . com*/ /* * Create a link from the path of the data entity for * this revision to the path of the data entity for the * prior revision. */ String dataTokenPathStr = String.format("%s/%s", this.tmpDir, dataToken); FileSystem fileSystem = FileSystems.getDefault(); String entityPathStr = entityFile.getAbsolutePath(); java.nio.file.Path entityPath = fileSystem.getPath(entityPathStr); java.nio.file.Path dataTokenPath = fileSystem.getPath(dataTokenPathStr); String createLinkMsg = String.format("Creating link from %s to %s", dataTokenPathStr, entityPathStr); logger.warn(createLinkMsg); try { if (SystemUtils.IS_OS_WINDOWS) { Files.createLink(dataTokenPath, entityPath); } else { Files.createSymbolicLink(dataTokenPath, entityPath); } } catch (FileAlreadyExistsException e) { // this is okay, just issue a warning msg = String.format("Failed to create link from %s to %s: %s", dataTokenPathStr, entityPathStr, e.getMessage()); logger.warn(msg); } catch (Exception e) { msg = String.format("Error creating link from %s to %s: %s", dataTokenPathStr, entityPathStr, e.getMessage()); logger.error(msg); throw (e); } }