List of usage examples for java.io File getCanonicalFile
public File getCanonicalFile() throws IOException
From source file:com.reprezen.kaizen.oasparser.jsonoverlay.gen.TypeGenerator.java
public void generate(Type type) throws IOException { File javaFile = new File(dir, t("${name}${0}.java", type, suffix)); System.out.println("Generating " + javaFile.getCanonicalFile()); CompilationUnit existing = preserve && javaFile.exists() ? tryParse(javaFile) : null; String declaration = getTypeDeclaration(type, suffix); SimpleJavaGenerator gen = new SimpleJavaGenerator(getPackage(), declaration); if (existing != null) { copyFileComment(gen, existing);/*from w ww .j a v a 2 s.co m*/ addManualMethods(gen, existing); } requireTypes(getImports(type)); addGeneratedMembers(type, gen); requireTypes(Generated.class); resolveImports(type, gen); FileUtils.write(javaFile, gen.format(), Charsets.UTF_8); }
From source file:de.unibremen.informatik.tdki.combo.data.DBLayout.java
public boolean loadProject(File bulkFile, String project) { if (!projectExists(project)) { return false; }// w w w . jav a 2s.co m try { BulkFile f = new BulkFile(bulkFile.getCanonicalFile()); f.open(BulkFile.Open.READ); bulkLoadFromFile(f.getConceptAssertions().getCanonicalPath(), getTableConceptAssertions(project)); bulkLoadFromFile(f.getRoleAssertions().getCanonicalPath(), getTableRoleAssertions(project)); bulkLoadFromFile(f.getSymbols().getCanonicalPath(), getTableSymbols(project)); bulkLoadFromFile(f.getGenRoles().getCanonicalPath(), getTableGenRoles(project)); bulkLoadFromFile(f.getGenConcepts().getCanonicalPath(), getTableGenConcepts(project)); bulkLoadFromFile(f.getQualifiedExistentials().getCanonicalPath(), getTableQualifiedExistentials(project)); bulkLoadFromFile(f.getInclusionAxioms().getCanonicalPath(), getTableTBox(project)); bulkLoadFromFile(f.getRoleInclusions().getCanonicalPath(), getTableRBox(project)); f.close(); } catch (InterruptedException ex) { throw new RuntimeException(ex); } catch (IOException ex) { throw new RuntimeException(ex); } return true; }
From source file:org.qedeq.base.io.IoUtility.java
/** * Determines whether the specified file is a symbolic link rather than an actual file. * See {@link/*from w w w .j av a 2 s . c o m*/ * https://svn.apache.org/repos/asf/commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java}. * @param file File to check. * @return Is the file is a symbolic link? * @throws IOException IO error while checking the file. */ public static boolean isSymbolicLink(final File file) throws IOException { if (file == null) { throw new NullPointerException("File must not be null"); } // is windows file system in use? if (File.separatorChar == '\\') { // we have no symbolic links return false; } File fileInCanonicalDir = null; if (file.getParent() == null) { fileInCanonicalDir = file; } else { File canonicalDir = file.getParentFile().getCanonicalFile(); fileInCanonicalDir = new File(canonicalDir, file.getName()); } if (fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile())) { return false; } return true; }
From source file:org.xwiki.environment.internal.ServletEnvironmentTest.java
@Test public void getPermanentDirectoryWhenSetWithSystemProperty() throws Exception { File expectedPermanentDirectory = new File(System.getProperty("java.io.tmpdir"), "permanent"); System.setProperty("xwiki.data.dir", expectedPermanentDirectory.toString()); try {/* ww w.ja v a 2s .c o m*/ this.environment.setServletContext(mock(ServletContext.class)); assertEquals(expectedPermanentDirectory.getCanonicalFile(), this.environment.getPermanentDirectory().getCanonicalFile()); } finally { System.clearProperty("xwiki.data.dir"); } }
From source file:org.opt4j.config.ModuleAutoFinder.java
/** * Returns all not abstract classes that implement {@link PropertyModule}. * // w w w.j a v a 2 s . com * @return all property modules */ protected Collection<Class<? extends Module>> getAll() { Starter starter = new Starter(); Collection<File> files = starter.addPlugins(); classLoader = ClassLoader.getSystemClassLoader(); String paths = System.getProperty("java.class.path"); StringTokenizer st = new StringTokenizer(paths, ";\n:"); while (st.hasMoreTokens()) { String path = st.nextToken(); File f = new File(path); if (f.exists()) { try { f = f.getCanonicalFile(); files.add(f); } catch (IOException e) { e.printStackTrace(); } } } List<Class<?>> classes = new ArrayList<Class<?>>(); for (File file : files) { if (isJar(file)) { try { classes.addAll(getAllClasses(new ZipFile(file))); } catch (ZipException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (UnsupportedClassVersionError e) { System.err.println(file + " not supported: bad version number"); } } else { classes.addAll(getAllClasses(file)); } } List<Class<? extends Module>> modules = new ArrayList<Class<? extends Module>>(); for (Class<?> clazz : classes) { if (Opt4JModule.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) { Class<? extends Module> module = clazz.asSubclass(Module.class); Ignore i = module.getAnnotation(Ignore.class); if (i == null && !module.isAnonymousClass() && accept.transform(module) && !ignore.transform(module)) { modules.add(module); invokeOut("Add module: " + module.toString()); } } } return modules; }
From source file:org.apache.maven.surefire.its.fixture.MavenLauncher.java
private File simpleExtractResources(Class<?> cl, String resourcePath) { if (!resourcePath.startsWith("/")) { resourcePath = "/" + resourcePath; }/*from w w w. j a v a 2 s . c o m*/ File tempDir = getUnpackDir(); File testDir = new File(tempDir, resourcePath); try { File parentPom = new File(tempDir.getParentFile(), "pom.xml"); if (!parentPom.exists()) { URL resource = cl.getResource("/pom.xml"); FileUtils.copyURLToFile(resource, parentPom); } FileUtils.deleteDirectory(testDir); File file = ResourceExtractor.extractResourceToDestination(cl, resourcePath, tempDir, true); return file.getCanonicalFile(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.dcm4che2.tool.dcmdir.DcmDir.java
public DcmDir(File file) throws IOException { this.file = file.getCanonicalFile(); }
From source file:com.cloudera.learnavro.test.GenerateTestAvro.java
/** * Main method for building all the test data files. *///from w w w . j a va 2 s .c o m public void generateData(File outDir, int numRecords) throws IOException, InstantiationException { // Create the target dir outDir = outDir.getCanonicalFile(); if (outDir.exists()) { throw new IOException("Directory already exists: " + outDir); } outDir.mkdirs(); // // Emit WebPage data. Note the weird "Instantiator" business that appears as if it could be done // via Class.newInstance(). We can't do that here because newInstance() is incompatible with inner // classes. // Schema webCrawlSchema = ReflectData.get().getSchema(WebPage.class); emitSchema(new File(outDir, "webcrawl.schema"), webCrawlSchema); emitData(new File(outDir, "webcrawl.dat"), webCrawlSchema, numRecords, new Instantiator<WebPage>() { public WebPage create() { return new WebPage(); } }); // // Access log // Schema accessLogSchema = ReflectData.get().getSchema(AccessLog.class); emitSchema(new File(outDir, "accesslog.schema"), accessLogSchema); emitData(new File(outDir, "accesslog.dat"), accessLogSchema, numRecords, new Instantiator<AccessLog>() { public AccessLog create() { return new AccessLog(); } }); // // File listing // Schema fileListingSchema = ReflectData.get().getSchema(FileListing.class); emitSchema(new File(outDir, "filelisting.schema"), fileListingSchema); emitData(new File(outDir, "filelisting.dat"), fileListingSchema, numRecords, new Instantiator<FileListing>() { public FileListing create() { return new FileListing(); } }); // // Sensor data // Schema sensorDataSchema = ReflectData.get().getSchema(SensorData.class); emitSchema(new File(outDir, "sensordata.schema"), sensorDataSchema); emitData(new File(outDir, "sensordata.dat"), sensorDataSchema, numRecords, new Instantiator<SensorData>() { public SensorData create() { return new SensorData(); } }); // // Purchases // Schema purchaseSchema = ReflectData.get().getSchema(Purchase.class); emitSchema(new File(outDir, "purchase.schema"), purchaseSchema); emitData(new File(outDir, "purchase.dat"), purchaseSchema, numRecords, new Instantiator<Purchase>() { public Purchase create() { return new Purchase(); } }); }
From source file:edu.harvard.med.screensaver.service.SmtpEmailService.java
private void sendMessage(String subject, String message, InternetAddress from, InternetAddress[] recipients, InternetAddress[] cclist, File attachedFile) throws MessagingException, IOException { log.info("try to send: " + printEmail(subject, message, from, this.replyTos, recipients, cclist, (attachedFile == null ? "" : "" + attachedFile.getCanonicalFile()))); log.info("host: " + host + ", useSMTPS: " + useSmtps); Properties props = new Properties(); String protocol = "smtp"; if (useSmtps) // need smtps to test with gmail {/*from ww w. ja v a 2s.c om*/ props.put("mail.smtps.auth", "true"); protocol = "smtps"; } Session session = Session.getDefaultInstance(props, null); Transport t = session.getTransport(protocol); try { MimeMessage msg = new MimeMessage(session); if (this.replyTos != null) msg.setReplyTo(replyTos); msg.setFrom(from); msg.setSubject(subject); if (attachedFile != null) { setFileAsAttachment(msg, message, attachedFile); } else { msg.setContent(message, "text/plain"); } msg.addRecipients(Message.RecipientType.TO, recipients); if (cclist != null) msg.addRecipients(Message.RecipientType.CC, cclist); t.connect(host, username, password); t.sendMessage(msg, msg.getAllRecipients()); } finally { t.close(); } log.info("sent: " + printEmailHeader(subject, from, this.replyTos, recipients, cclist, (attachedFile == null ? "" : "" + attachedFile.getCanonicalFile()))); }