List of usage examples for java.io File toString
public String toString()
From source file:org.appverse.web.framework.backend.ecm.filesystem.services.integration.impl.live.FileSystemDocumentService.java
@Override public void move(String pathOrigin, String documentNameOrigin, String pathDestination, String documentNameDestination) throws Exception { File originFile = new File(pathOrigin + "/" + documentNameOrigin); // Create destination structure if necessary File destinationFolder = new File(pathDestination); if (!destinationFolder.exists()) { if (!destinationFolder.mkdirs()) { throw new Exception("Error creating folder structure to path: " + destinationFolder.toString()); }// w w w .j a va 2 s .co m } // Move the file File targetFile = new File(destinationFolder, documentNameDestination); try { java.nio.file.Files.move(originFile.toPath(), targetFile.toPath(), StandardCopyOption.ATOMIC_MOVE); } catch (Exception e) { throw new Exception( "Error moving temporary file: " + originFile.toString() + "to: " + targetFile.toString()); } }
From source file:net.doubledoordev.backend.server.FileManager.java
public String stripServer(File file) { if (file.equals(serverFolder)) return serverFolder.getName(); return file.toString().substring(serverFolder.toString().length() + 1).replace('\\', '/'); }
From source file:cern.jarrace.controller.io.JarReaderTest.java
@Test(expected = IOException.class) public void canFailWhenJarDoesNotExist() throws Exception { File tmpFile = File.createTempFile("test", null); boolean delete = tmpFile.delete(); if (!delete) { throw new IllegalStateException("Failed to delete temporary file " + tmpFile); }//from w w w . j a v a2s. co m when(mockedContainer.getContainerPath()).thenReturn(tmpFile.toString()); JarReader.ofContainer(mockedContainer, Function.identity()); }
From source file:com.netspective.sparx.fileupload.FileUploadFilter.java
/** * This method is called by the server before the filter goes into service, * and here it determines the file upload directory. * * @param <b>config</b> The filter config passed by the servlet engine *//*from w w w. j a v a 2 s . c o m*/ public void init(FilterConfig config) throws ServletException { String tryDirectoryNames = config.getInitParameter(FILTERPARAM_UPLOAD_DIRS); // comma-separated list of directories to try if (tryDirectoryNames != null) { // find the first available directory either as a resource or a physical directory String[] tryDirectories = TextUtils.getInstance().split(tryDirectoryNames, ",", true); for (int i = 0; i < tryDirectories.length; i++) { String tryDirectory = tryDirectories[i]; try { // first try the directory as a servlet resource java.net.URL uploadDirURL = config.getServletContext().getResource(tryDirectory); if (uploadDirURL != null && uploadDirURL.getFile() != null) { uploadDir = uploadDirURL.getFile(); break; } File f = new File(tryDirectory); if (f.exists()) { uploadDir = f.getAbsolutePath(); break; } } catch (java.net.MalformedURLException ex) { throw new ServletException(ex.getMessage()); } } } // If upload directory parameter is null, assign a temp directory if (uploadDir == null) { File tempdir = (File) config.getServletContext().getAttribute("javax.servlet.context.tempdir"); if (tempdir != null) { uploadDir = tempdir.toString(); } else { throw new ServletException("Error in FileUploadFilter : No upload " + "directory found: set an uploadDir init " + "parameter or ensure the " + "javax.servlet.context.tempdir directory " + "is valid"); } } uploadPrefix = config.getInitParameter(FILTERPARAM_UPLOADED_FILES_PREFIX); if (uploadPrefix == null) uploadPrefix = FILTERPARAMVALUE_DEFAULT_UPLOADED_FILES_PREFIX; log.info("uploadPrefix is: " + uploadPrefix); uploadFileArg = config.getInitParameter(FILTERPARAM_UPLOADED_FILES_REQUEST_ATTR_NAME); if (uploadFileArg == null) uploadFileArg = FILTERPARAMVALUE_DEFAULT_UPLOADED_FILES_REQUEST_ATTR_NAME; log.info("uploadFileArg is: " + uploadFileArg); }
From source file:org.bee.tl.ext.spring.BeetlGroupUtilConfiguration.java
public void init() { group = new GroupTemplate(new File(root)); group.config(statementStart, statementEnd, placeholderStart, placeholderEnd); if (tempFolder != null) { group.setTempFolder(tempFolder); } else {/* w w w . j av a 2s .com*/ File target = new File(webPath + File.separator + "WEB-INF", ".temp"); target.mkdirs(); tempFolder = target.toString(); group.setTempFolder(target.toString()); } if (nativeCall) group.enableNativeCall(); if (optimize) { group.enableOptimize(); logger.info("Beetl??:" + tempFolder); } if (check != 0) group.enableChecker(check); if (this.isDirectByteOutput()) { group.enableDirectOutputByte(); } group.setCharset(charset); group.enableHtmlTagSupport("#"); initOther(); }
From source file:de.unidue.ltl.flextag.features.ngram.LuceneNgramUnitTest.java
private void runMetaCollection(File luceneFolder) throws Exception { Object[] parameters = new Object[] { LuceneUniGramMetaCollector.PARAM_UNIQUE_EXTRACTOR_NAME, EXTRACTOR_NAME, TokenContext.PARAM_SOURCE_LOCATION, luceneFolder.toString(), LuceneUniGramMetaCollector.PARAM_TARGET_LOCATION, luceneFolder.toString() }; List<Object> parameterList = new ArrayList<Object>(Arrays.asList(parameters)); CollectionReaderDescription reader = CollectionReaderFactory.createReaderDescription( TestReaderSingleLabel.class, TestReaderSingleLabel.PARAM_LANGUAGE, "en", TestReaderSingleLabel.PARAM_SOURCE_LOCATION, "src/test/resources/text/input.txt"); AnalysisEngineDescription segmenter = AnalysisEngineFactory .createEngineDescription(BreakIteratorSegmenter.class); AnalysisEngineDescription metaCollector = AnalysisEngineFactory .createEngineDescription(LuceneUniGramMetaCollector.class, parameterList.toArray()); // run meta collector SimplePipeline.runPipeline(reader, segmenter, metaCollector); }
From source file:net.centro.rtb.monitoringcenter.MonitoringCenter.java
protected static void reloadConfig() { if (!configured.get() || initialConfig.getConfigFile() == null) { return;/*from ww w . jav a 2 s.co m*/ } File effectiveConfigFile = new File(ConfigFileUtil.getEffectiveConfigFileFullPath(initialConfig)); MonitoringCenterConfig newConfig = null; try { newConfig = Configurator.configFile(effectiveConfigFile).build(); } catch (Exception e) { logger.error("Error while reloading MonitoringCenter config from {}", effectiveConfigFile.toString(), e); if (InterruptedException.class.isInstance(e)) { Thread.currentThread().interrupt(); } return; } // Update metric collection, if needed MetricCollectionConfig newMetricCollectionConfig = newConfig.getMetricCollectionConfig(); if (newMetricCollectionConfig != null) { // If it's null, something is wrong, so keep old values MetricCollectionConfig oldMetricCollectionConfig = currentConfig.getMetricCollectionConfig(); if (newMetricCollectionConfig.getEnableSystemMetrics()) { if (oldMetricCollectionConfig == null || !oldMetricCollectionConfig.getEnableSystemMetrics()) { systemMetricSet = new SystemMetricSet(); metricRegistry.register(SYSTEM_METRIC_NAMESPACE, systemMetricSet); } } else { if (oldMetricCollectionConfig != null && oldMetricCollectionConfig.getEnableSystemMetrics()) { if (systemMetricSet != null) { metricRegistry.removeMatching(new MetricFilter() { @Override public boolean matches(String name, Metric metric) { return name.startsWith(SYSTEM_METRIC_NAMESPACE + MetricNamingUtil.SEPARATOR); } }); systemMetricSet.shutdown(); systemMetricSet = null; } } } if (newMetricCollectionConfig.getEnableTomcatMetrics()) { if (oldMetricCollectionConfig == null || !oldMetricCollectionConfig.getEnableTomcatMetrics()) { tomcatMetricSet = new TomcatMetricSet(); metricRegistry.register(TOMCAT_METRIC_NAMESPACE, tomcatMetricSet); } } else { if (oldMetricCollectionConfig != null && oldMetricCollectionConfig.getEnableTomcatMetrics()) { if (tomcatMetricSet != null) { metricRegistry.removeMatching(new MetricFilter() { @Override public boolean matches(String name, Metric metric) { return name.startsWith(TOMCAT_METRIC_NAMESPACE + MetricNamingUtil.SEPARATOR); } }); tomcatMetricSet.shutdown(); tomcatMetricSet = null; } } } } // Reload GraphiteReporter GraphiteReporterConfig oldGraphiteReporterConfig = null; if (currentConfig.getMetricReportingConfig() != null) { oldGraphiteReporterConfig = currentConfig.getMetricReportingConfig().getGraphiteReporterConfig(); } GraphiteReporterConfig newGraphiteReporterConfig = null; if (newConfig.getMetricReportingConfig() != null) { newGraphiteReporterConfig = newConfig.getMetricReportingConfig().getGraphiteReporterConfig(); } if (graphiteReporter != null && (oldGraphiteReporterConfig != null && oldGraphiteReporterConfig.getEnableReporter())) { if (newGraphiteReporterConfig == null || !newGraphiteReporterConfig.equals(oldGraphiteReporterConfig)) { graphiteReporter.stop(); graphiteReporter = null; if (newGraphiteReporterConfig != null && newGraphiteReporterConfig.getEnableReporter()) { initGraphiteReporter(newGraphiteReporterConfig); logger.info("GraphiteReporter has been updated: {}", newGraphiteReporterConfig.toString()); } else { logger.info("GraphiteReporter has been turned off"); } } } else { if (newGraphiteReporterConfig != null && newGraphiteReporterConfig.getEnableReporter()) { initGraphiteReporter(newGraphiteReporterConfig); logger.info("Started GraphiteReporter: {}", newGraphiteReporterConfig.toString()); } } currentConfig = newConfig; }
From source file:com.symbian.driver.plugins.comms.stat.StatTransfer.java
public List<File> dir(File aDir) { LOGGER.info("Listing folder " + aDir.toString()); JStatResult lResult = null;// w w w . j ava 2 s . c om String lDir = aDir.toString().replaceAll("/", "\\"); List<File> lFilesList = new LinkedList<File>(); try { lResult = iStatProxy.getStat().listFiles(lDir); if (lResult.getReturnedValue() == 13 && lResult.getReceivedData() != null && !lResult.getReceivedData().equalsIgnoreCase("")) { String lReceivedData = lResult.getReceivedData(); String[] lReceivedDataSplit = lReceivedData.split("\r\n"); for (String lLine : lReceivedDataSplit) { //Stat dir returns something like // private,16,21/12/2007 12:00,0 // System,16,21/12/2007 12:00,0 // BtPlatformPluginConfigurator.dat,32,21/12/2007 12:00,8 // statoutput.log,32,21/12/2007 12:02,2180 String[] lFields = lLine.split(","); String lFileName = lFields[0]; lFilesList.add(new File(lDir, lFileName)); } return lFilesList; } } catch (TimeLimitExceededException lTimeLimitExceededException) { LOGGER.log(Level.SEVERE, "Time limit exeeded", lTimeLimitExceededException); } catch (JStatException lJStatException) { LOGGER.log(Level.SEVERE, "STAT exception", lJStatException); } LOGGER.log(Level.SEVERE, "Failed to list file/folder " + aDir + ((lResult != null) ? " : " + lResult.toString() : "")); return lFilesList; }
From source file:fr.logfiletoes.ElasticSearchTest.java
@Test public void wildfly() throws IOException, InterruptedException { File data = Files.createTempDirectory("it_es_data-").toFile(); Settings settings = ImmutableSettings.settingsBuilder().put("path.data", data.toString()) .put("cluster.name", "IT-0001").build(); Node node = NodeBuilder.nodeBuilder().local(true).settings(settings).build(); Client client = node.client();//from w w w .j a v a 2s.c o m node.start(); Config config = new Config("./src/test/resources/config-wildfly-one.json"); List<Unit> units = config.getUnits(); assertEquals(1, units.size()); units.get(0).start(); // Wait store log Thread.sleep(3000); // Search log SearchResponse response = client.prepareSearch("logdetest").setSearchType(SearchType.DEFAULT) .setQuery(QueryBuilders.matchQuery("message", "Configured system properties")).setSize(1000) .addSort("@timestamp", SortOrder.ASC).execute().actionGet(); if (LOG.isLoggable(Level.FINEST)) { for (SearchHit hit : response.getHits().getHits()) { LOG.finest("-----------------"); hit.getSource().forEach((key, value) -> { LOG.log(Level.FINEST, "{0} = {1}", new Object[] { key, value }); }); } } // Get information need to test String expected = response.getHits().getHits()[0].getSource().get("message").toString(); assertEquals(stacktrace, expected); // wait request Thread.sleep(10000); // Close tailer units.get(0).stop(); // Close ElasticSearch node.close(); // Clean data directory FileUtils.forceDelete(data); }
From source file:fr.logfiletoes.ElasticSearchTest.java
@Test public void fail2ban() throws IOException, InterruptedException { File data = Files.createTempDirectory("it_es_data-").toFile(); Settings settings = ImmutableSettings.settingsBuilder().put("path.data", data.toString()) .put("cluster.name", "IT-0002").build(); Node node = NodeBuilder.nodeBuilder().local(true).settings(settings).build(); Client client = node.client();/* w ww . j a v a 2 s .c om*/ node.start(); Config config = new Config("./src/test/resources/fail2ban.json"); List<Unit> units = config.getUnits(); assertEquals(1, units.size()); units.get(0).start(); // Wait store log Thread.sleep(3000); // Search log SearchResponse response = client.prepareSearch("system").setSearchType(SearchType.DEFAULT) .setQuery(QueryBuilders.matchQuery("message", "58.218.204.248")).setSize(1000) .addSort("@timestamp", SortOrder.ASC).execute().actionGet(); if (LOG.isLoggable(Level.FINEST)) { for (SearchHit hit : response.getHits().getHits()) { LOG.finest("-----------------"); hit.getSource().forEach((key, value) -> { LOG.log(Level.FINEST, "{0} = {1}", new Object[] { key, value }); }); } } // Get information need to test assertEquals(6, response.getHits().getHits().length); assertEquals("Found 58.218.204.248", response.getHits().getHits()[0].getSource().get("message").toString()); assertEquals("Ban 58.218.204.248", response.getHits().getHits()[5].getSource().get("message").toString()); // wait request Thread.sleep(10000); // Close tailer units.get(0).stop(); // Close ElasticSearch node.close(); // Clean data directory FileUtils.forceDelete(data); }