List of usage examples for java.io File getAbsoluteFile
public File getAbsoluteFile()
From source file:com.goodformobile.build.mobile.RIMPackageMojoTest.java
@Test public void testExecuteOnBasicLibrary() throws Exception { File projectDirectory = getRelativeFile( "projects/library-project-1-preverified/BlackBerry_App_Descriptor.xml").getParentFile(); File workProjectDirectory = setupCleanCopyOfProject(projectDirectory); RIMPackageMojo mojo = setupMojo();/*from w w w . ja va 2s. c o m*/ MavenProject project = getProject(mojo); project.setArtifactId("library-project-1"); MavenProjectBasicStub projectStub = (MavenProjectBasicStub) project; projectStub.setBaseDir(workProjectDirectory); setupRIMStyleProject(workProjectDirectory, project); setVariableValueToObject(mojo, "systemModule", true); setVariableValueToObject(mojo, "bundleCodsInOutputJar", true); mojo.execute(); // Ensure a jad is generated. File targetDirectory = new File(workProjectDirectory, "target"); File expectedJad = new File(targetDirectory.getAbsoluteFile() + File.separator + "deliverables" + File.separator + "library_project_1.jad"); assertTrue("Unable to find generated jad: " + expectedJad.getAbsolutePath(), expectedJad.exists()); Properties result = PropertyUtils.loadProperties(expectedJad); assertNotNull(result); assertEquals("library-project-1", result.get("MIDlet-Name")); assertEquals("1.0.0", result.get("MIDlet-Version")); assertEquals("MIDP-2.0", result.get("MicroEdition-Profile")); assertEquals("CLDC-1.1", result.get("MicroEdition-Configuration")); assertEquals("BlackBerry Developer", result.get("MIDlet-Vendor")); assertEquals("2", result.get("RIM-Library-Flags")); assertEquals("library-project-1.jar", result.get("MIDlet-Jar-URL")); assertEquals("library_project_1.cod", result.get("RIM-COD-URL")); // Ensure a cod file is generated. File expectedCod = new File(targetDirectory.getAbsoluteFile() + File.separator + "deliverables" + File.separator + "library_project_1.cod"); assertTrue("Unable to find generated cod: " + expectedCod.getAbsolutePath(), expectedCod.exists()); // Ensure a cod file is copied to target File expectedTargetCod = new File(targetDirectory.getAbsoluteFile() + File.separator + "classes" + File.separator + "library_project_1.cod"); assertTrue("Unable to find generated cod: " + expectedTargetCod.getAbsolutePath(), expectedTargetCod.exists()); }
From source file:com.goodformobile.build.mobile.RIMPackageMojoTest.java
@Test public void testExecuteOnBasicLibraryExcludeCods() throws Exception { File projectDirectory = getRelativeFile( "projects/library-project-1-preverified/BlackBerry_App_Descriptor.xml").getParentFile(); File workProjectDirectory = setupCleanCopyOfProject(projectDirectory); RIMPackageMojo mojo = setupMojo();/*from w ww.j av a 2 s .c o m*/ MavenProject project = getProject(mojo); project.setArtifactId("library-project-1"); MavenProjectBasicStub projectStub = (MavenProjectBasicStub) project; projectStub.setBaseDir(workProjectDirectory); setupRIMStyleProject(workProjectDirectory, project); setVariableValueToObject(mojo, "systemModule", true); setVariableValueToObject(mojo, "bundleCodsInOutputJar", false); mojo.execute(); // Ensure a jad is generated. File targetDirectory = new File(workProjectDirectory, "target"); File expectedJad = new File(targetDirectory.getAbsoluteFile() + File.separator + "deliverables" + File.separator + "library_project_1.jad"); assertTrue("Unable to find generated jad: " + expectedJad.getAbsolutePath(), expectedJad.exists()); Properties result = PropertyUtils.loadProperties(expectedJad); assertNotNull(result); assertEquals("library-project-1", result.get("MIDlet-Name")); assertEquals("1.0.0", result.get("MIDlet-Version")); assertEquals("MIDP-2.0", result.get("MicroEdition-Profile")); assertEquals("CLDC-1.1", result.get("MicroEdition-Configuration")); assertEquals("BlackBerry Developer", result.get("MIDlet-Vendor")); assertEquals("2", result.get("RIM-Library-Flags")); assertEquals("library-project-1.jar", result.get("MIDlet-Jar-URL")); assertEquals("library_project_1.cod", result.get("RIM-COD-URL")); // Ensure a cod file is generated. File expectedCod = new File(targetDirectory.getAbsoluteFile() + File.separator + "deliverables" + File.separator + "library_project_1.cod"); assertTrue("Unable to find generated cod: " + expectedCod.getAbsolutePath(), expectedCod.exists()); // Ensure a cod file is not copied to target File expectedTargetCod = new File(targetDirectory.getAbsoluteFile() + File.separator + "classes" + File.separator + "library_project_1.cod"); assertFalse("Found unexpected cod in target directory: " + expectedTargetCod.getAbsolutePath(), expectedTargetCod.exists()); }
From source file:de.knurt.fam.plugin.DefaultPluginResolver.java
private void initPlugins() { File pluginDirectory = new File(FamConnector.me().getPluginDirectory()); if (pluginDirectory.exists() && pluginDirectory.isDirectory() && pluginDirectory.canRead()) { File[] files = pluginDirectory.listFiles(); ClassLoader currentThreadClassLoader = Thread.currentThread().getContextClassLoader(); for (File file : files) { if (file.isFile() && file.getName().toLowerCase().endsWith("jar")) { JarFile jar = null; try { jar = new JarFile(file.getAbsoluteFile().toString()); Enumeration<JarEntry> jarEntries = jar.entries(); while (jarEntries.hasMoreElements()) { JarEntry entry = jarEntries.nextElement(); if (entry.getName().toLowerCase().endsWith("class")) { String className = entry.getName().replaceAll("/", ".").replaceAll("\\.class$", ""); // @SuppressWarnings("resource") // classLoader must not be closed, getting an "IllegalStateException: zip file closed" otherwise URLClassLoader classLoader = new URLClassLoader(new URL[] { file.toURI().toURL() }, currentThreadClassLoader); Class<?> cl = classLoader.loadClass(className); if (this.isPlugin(cl)) { Plugin plugin = (Plugin) cl.newInstance(); this.plugins.add(plugin); }// ww w .j a va2 s . c om } } } catch (IllegalAccessException e) { e.printStackTrace(); FamLog.logException(this.getClass(), e, "failed to load plugin", 201010091426l); } catch (InstantiationException e) { e.printStackTrace(); FamLog.logException(this.getClass(), e, "failed to load plugin", 201010091424l); } catch (ClassNotFoundException e) { e.printStackTrace(); FamLog.logException(this.getClass(), e, "failed to load plugin", 201010091425l); } catch (IOException e) { e.printStackTrace(); FamLog.logException(this.getClass(), e, "failed to load plugin", 201010091351l); } finally { try { jar.close(); } catch (Exception e) { } } } } for (Plugin plugin : this.plugins) { boolean found = false; if (this.implementz(plugin.getClass(), RegisterSubmission.class)) { if (found == true) { throw new PluginConfigurationException("Found more than one RegisterSubmission classes"); // TODO #19 supply a solution Ticket } this.registerSubmission = (RegisterSubmission) plugin; found = true; } } for (Plugin plugin : this.plugins) { plugin.start(); } } // search plugin if (this.registerSubmission == null) { this.registerSubmission = new DefaultRegisterSubmission(); } }
From source file:com.thinkbiganalytics.discovery.parsers.hadoop.SparkFileSchemaParserService.java
private File toFile(InputStream is) throws IOException { File tempFile = File.createTempFile("kylo-spark-parser", ".dat"); try (FileOutputStream fos = new FileOutputStream(tempFile)) { IOUtils.copyLarge(is, fos);/*from www. j av a 2 s . c o m*/ } log.info("Created temporary file {} success? {}", tempFile.getAbsoluteFile().toURI(), tempFile.exists()); return tempFile; }
From source file:com.foilen.smalltools.spring.messagesource.UsageMonitoringMessageSource.java
private void init() { // Check the base folder File basenameFile = new File(basename); logger.info("Base name is {}", basename); File directory = basenameFile.getParentFile(); logger.info("Base directory is {}", directory.getAbsoluteFile()); if (!directory.exists()) { throw new SmallToolsException("Directory: " + directory.getAbsolutePath() + " does not exists"); }//w w w .j a v a 2s . c o m tmpUsed = new File(directory.getAbsolutePath() + File.separatorChar + "_messages_usage.txt"); // Check the files in it String startswith = basenameFile.getName() + "_"; String endswith = ".properties"; for (File file : directory.listFiles( (FilenameFilter) (dir, name) -> name.startsWith(startswith) && name.endsWith(endswith))) { // Create the locale logger.info("Found messages file {}", directory.getAbsoluteFile()); String filename = file.getName(); String localePart = filename.substring(startswith.length(), filename.length() - endswith.length()); Locale locale = new Locale(localePart); logger.info("Locale is {} -> {}", localePart, locale); filePerLocale.put(locale, file); // Load the file Properties properties = new Properties(); try (FileInputStream inputStream = new FileInputStream(file)) { properties.load(new InputStreamReader(inputStream, CharsetTools.UTF_8)); } catch (IOException e) { logger.error("Problem reading the property file {}", file.getAbsoluteFile(), e); throw new SmallToolsException("Problem reading the file", e); } // Check codes and save values Map<String, String> messages = new HashMap<>(); messagesPerLocale.put(locale, messages); for (Object key : properties.keySet()) { String name = (String) key; String value = properties.getProperty(name); allCodesInFiles.add(name); messages.put(name, value); } } // Add missing codes in all the maps (copy one that has it) for (Locale locale : filePerLocale.keySet()) { Set<String> missingCodes = new HashSet<>(); Map<String, String> messagesForCurrentLocale = messagesPerLocale.get(locale); // Get the ones missing missingCodes.addAll(allCodesInFiles); missingCodes.removeAll(messagesForCurrentLocale.keySet()); for (String missingCode : missingCodes) { logger.info("Locale {} was missing code {}", locale, missingCode); String codeValue = findAnyValue(missingCode); messagesForCurrentLocale.put(missingCode, codeValue); } } // Load the already known codes if (tmpUsed.exists()) { for (String line : FileTools.readFileLinesIteration(tmpUsed.getAbsolutePath())) { knownUsedCodes.add(line); } } smoothTrigger = new SmoothTrigger(() -> { synchronized (lock) { logger.info("Begin saving locale files"); // Go through each locale for (Entry<Locale, File> entry : filePerLocale.entrySet()) { Map<String, String> messages = messagesPerLocale.get(entry.getKey()); try (PrintWriter printWriter = new PrintWriter(entry.getValue(), CharsetTools.UTF_8.toString())) { // Save the known used (sorted) at the top for (String code : knownUsedCodes.stream().sorted(String.CASE_INSENSITIVE_ORDER) .collect(Collectors.toList())) { printWriter.println(code + "=" + messages.get(code)); } printWriter.println(); // Save the others (sorted) at the bottom Set<String> unknownCodes = new HashSet<>(); unknownCodes.addAll(messages.keySet()); unknownCodes.removeAll(knownUsedCodes); if (!unknownCodes.isEmpty()) { printWriter.println("# Unknown"); printWriter.println(); for (String code : unknownCodes.stream().sorted(String.CASE_INSENSITIVE_ORDER) .collect(Collectors.toList())) { printWriter.println(code + "=" + messages.get(code)); } printWriter.println(); } } catch (Exception e) { logger.error("Could not write the file", e); } } // Save the known FileTools.writeFile(Joiner.on('\n').join( knownUsedCodes.stream().sorted(String.CASE_INSENSITIVE_ORDER).collect(Collectors.toList())), tmpUsed); logger.info("Done saving locale files"); } }) // .setDelayAfterLastTriggerMs(5000) // .setMaxDelayAfterFirstRequestMs(10000) // .setFirstPassThrough(true) // .start(); smoothTrigger.request(); }
From source file:vn.vfossa.webscript.EsignAction.java
@Override public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { try {/*w w w.j a va 2 s .c om*/ logger.setLevel(Level.ALL); String certpass = null, prkeypass = null, field = null; File certificate = null; // Create response json object JSONObject obj = new JSONObject(); obj.put("success", false);// make success false as default obj.put("message", "Failed Request"); // parse request json object JSONObject json = null; Object jsonO = req.parseContent(); if (jsonO instanceof JSONObject && jsonO != null) { json = (JSONObject) jsonO; } // Get data from Request // Get all the field in json object request String params[] = JSONObject.getNames(json); for (int i = 0; i < params.length; i++) { field = params[i]; if (field.indexOf("certpassword") != -1) { certpass = json.getString(field); } else if (field.indexOf("prkeypassword") != -1) { prkeypass = json.getString(field); } else if (field.indexOf("certificate") != -1) { certificate = (File) json.get("certificate"); } } if (!certificate.isFile()) { obj.put("message", "Require Certificate!"); logger.info("This is not a file"); } else if (certpass.length() == 0) { obj.put("message", "Require Certificate Password!"); logger.info("Where is certificate password?"); } else if (prkeypass.length() == 0) { obj.put("message", "Require Privatekey Password!"); logger.info("Where is certificate password?"); } else { obj.put("success", true); obj.put("message", "File is singed"); VnCertificate vncert = new VnCertificate(certificate, certpass, prkeypass); String nodeRefString = req.getParameter("nodeRef"); NodeRef nodeRef = new NodeRef(nodeRefString); byte[] data = getNodeContent(nodeRefer); File signFile = BytesToFile.bytesToFile(data); String fileName = signFile.getName(); if (fileName.isOOXML()) { OOXMLContent ooxmlContent = new OOXMLContent(signFile.getAbsoluteFile()); ooxmlContent.addSignature(vncert.getCert(), vncert.getPrivateKey()); } else if (filenName.isPdf()) { PDFContent pdfContent = new OOXMLContent(signFile.getAbsoluteFile()); pdfContent.addSignature(vncert.getCert(), vncert.getPrivateKey()); } } // build a JSON string and send it back Action mailAction = this.actionService.createAction(MailActionExecuter.NAME); mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "OK"); mailAction.setParameterValue(MailActionExecuter.PARAM_TO, "khanhthinh.45a4@gmail.com"); mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, "OK"); this.actionService.executeAction(mailAction, null); String jsonString = obj.toString(); logger.info(jsonString); System.out.println("I was called!"); res.setContentType("application/json"); res.getWriter().write(jsonString); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.goodformobile.build.mobile.RIMPackageMojoTest.java
@Test public void testResourcesMustBeInResultingCod() throws Exception { File projectDirectory = getRelativeFile("projects/test-app-with-large-resource/pom.xml").getParentFile(); File workProjectDirectory = setupCleanCopyOfProject(projectDirectory); RIMPackageMojo mojo = setupMojo();/*from www .ja v a 2 s . c o m*/ MavenProject project = getProject(mojo); setupProject(workProjectDirectory, project); project.setArtifactId("test-app-with-large-resource"); mojo.execute(); File targetDirectory = new File(workProjectDirectory, "target"); // Ensure a cod file is generated. File expectedCod = new File(targetDirectory.getAbsoluteFile() + File.separator + "deliverables" + File.separator + "test_app_with_large_resource.cod"); assertTrue("Unable to find generated cod: " + expectedCod.getAbsolutePath(), expectedCod.exists()); // Ensure the resulting cod is over 500K assertTrue("Expected cod should be over 500k but is " + expectedCod.length() + " bytes.", expectedCod.length() > 500000); }
From source file:com.sonatype.security.ldap.persist.validation.LdapConfigurationValidationTest.java
@Test public void testValidation() throws Exception { File validationDirectory = new File("target/test-classes/validation"); for (Entry<String, ExpectedResult> entry : expectedResultMap.entrySet()) { File validationFile = new File(validationDirectory, "ldap-" + entry.getKey() + ".xml"); //Assert.assertTrue("File: " + validationFile.getAbsolutePath() + " does not exists", validationFile.exists()); ExpectedResult actualResult = this.runValidation(validationFile.getAbsoluteFile()); Assert.assertEquals("File " + validationFile, entry.getValue(), actualResult); }//from www.j a v a 2 s . co m }
From source file:cz.lbenda.dataman.db.DbConfig.java
/** Save session conf into File * @param file file to which is configuration saved */ public void save(File file) { if (StringUtils.isBlank(FilenameUtils.getExtension(file.getAbsolutePath()))) { file = new File(file.getAbsoluteFile() + ".dtm"); } // Append .dtm extension to file which haven't any extension try (FileWriter fw = new FileWriter(file)) { save(fw);//w ww.ja v a 2 s.c o m } catch (IOException e) { LOG.error("The file is un-writable: " + e.toString(), e); throw new RuntimeException("The file is un-writable: " + e.toString(), e); } }
From source file:com.reelfx.model.PostProcessor.java
public synchronized void saveToComputer(File file) { if (!file.getName().endsWith(ext) && !file.getName().endsWith(".avi")) file = new File(file.getAbsoluteFile() + ext); // extension will probably change for Windows outputFile = file;/*from ww w.j a v a2 s.c om*/ postRecording = false; postData = false; super.start(); }