List of usage examples for java.io File getAbsoluteFile
public File getAbsoluteFile()
From source file:be.ibridge.kettle.core.LogWriter.java
public static final Log4jFileAppender createFileAppender(String filename, boolean exact) throws KettleException { try {//from w ww . j a v a 2 s . c om File file; if (!exact) { file = File.createTempFile(filename + ".", ".log"); file.deleteOnExit(); } else { file = new File(filename); } File realFile = file.getAbsoluteFile(); Log4jFileAppender appender = new Log4jFileAppender(realFile); appender.setLayout(new Log4jKettleLayout(true)); appender.setName(LogWriter.createFileAppenderName(filename, exact)); return appender; } catch (IOException e) { throw new KettleFileException("Unable to add Kettle file appender to Log4J", e); } }
From source file:com.appleframework.jmx.connector.framework.ConnectorRegistry.java
@SuppressWarnings("deprecation") private static ConnectorRegistry create(ApplicationConfig config) throws Exception { Map<String, String> paramValues = config.getParamValues(); String appId = config.getApplicationId(); String connectorId = (String) paramValues.get("connectorId"); File file1 = new File(CoreUtils.getConnectorDir() + File.separatorChar + connectorId); URL[] urls = new URL[] { file1.toURL() }; ClassLoader cl = ClassLoaderRepository.getClassLoader(urls, true); //URLClassLoader cl = new URLClassLoader(urls, // ConnectorMBeanRegistry.class.getClassLoader()); Registry.MODELER_MANIFEST = MBEANS_DESCRIPTOR; URL res = cl.getResource(MBEANS_DESCRIPTOR); logger.info("Application ID : " + appId); logger.info("Connector Archive: " + file1.getAbsoluteFile()); logger.info("MBean Descriptor : " + res.toString()); //Thread.currentThread().setContextClassLoader(cl); //Registry.setUseContextClassLoader(true); ConnectorRegistry registry = new ConnectorRegistry(); registry.loadMetadata(cl);/*from w w w .j av a2s . co m*/ String[] mbeans = registry.findManagedBeans(); MBeanServer server = MBeanServerFactory.newMBeanServer(DOMAIN_CONNECTOR); for (int i = 0; i < mbeans.length; i++) { ManagedBean managed = registry.findManagedBean(mbeans[i]); String clsName = managed.getType(); String domain = managed.getDomain(); if (domain == null) { domain = DOMAIN_CONNECTOR; } Class<?> cls = Class.forName(clsName, true, cl); Object objMBean = null; // Use the factory method when it is defined. Method[] methods = cls.getMethods(); for (Method method : methods) { if (method.getName().equals(FACTORY_METHOD) && Modifier.isStatic(method.getModifiers())) { objMBean = method.invoke(null); logger.info("Create MBean using factory method."); break; } } if (objMBean == null) { objMBean = cls.newInstance(); } // Call the initialize method if the MBean extends ConnectorSupport class if (objMBean instanceof ConnectorSupport) { Method method = cls.getMethod("initialize", new Class[] { Map.class }); Map<String, String> props = config.getParamValues(); method.invoke(objMBean, new Object[] { props }); } ModelMBean mm = managed.createMBean(objMBean); String beanObjName = domain + ":name=" + mbeans[i]; server.registerMBean(mm, new ObjectName(beanObjName)); } registry.setMBeanServer(server); entries.put(appId, registry); return registry; }
From source file:com.opendoorlogistics.core.gis.map.background.MapsforgeTileFactory.java
private static XmlRenderTheme getRenderTheme(String xmlRenderThemeFilename) { if (Strings.isEmpty(xmlRenderThemeFilename) == false) { File renderThemeFile = RelativeFiles.validateRelativeFiles(xmlRenderThemeFilename, AppConstants.ODL_CONFIG_DIR); if (renderThemeFile != null) { try { return new ExternalRenderTheme(renderThemeFile.getAbsoluteFile()); } catch (Exception e) { // just return the default theme }//from w ww. j a va 2s . com } } return InternalRenderTheme.OSMARENDER; }
From source file:de.tbuchloh.kiskis.persistence.PersistenceManager.java
/** * @return all files without a representing attachment object. *///from w w w.j a v a 2 s. c o m private static Collection<File> getOrphanedAttachmentFiles(TPMDocument doc) { final Set<File> knownFiles = new HashSet<File>(); for (final Attachment a : doc.getAttachments()) { final File attFile = createAttachmentFile(a); knownFiles.add(attFile.getAbsoluteFile()); } final Collection<File> listFiles = new HashSet<File>(); for (final File f : listAttachments(doc)) { listFiles.add(f.getAbsoluteFile()); } listFiles.removeAll(knownFiles); return listFiles; }
From source file:com.whty.transform.common.utils.TransformUtils.java
public static boolean pdfTopdf(String docpath) { File pdfPath = new File(SysConf.getString("path.output") + docpath + "/pdf/"); if (!pdfPath.exists()) { pdfPath.mkdirs();/* w w w. j ava 2s . c om*/ } // pdf? try { PdfReader reader = new PdfReader(SysConf.getString("path.input") + docpath); com.itextpdf.text.Document document = new com.itextpdf.text.Document(reader.getPageSize(1)); PdfCopy copy = new PdfCopy(document, new FileOutputStream(pdfPath.getAbsoluteFile() + "/" + transFileName + ".pdf")); document.open(); for (int i = 1; i <= reader.getNumberOfPages(); i++) { document.newPage(); PdfImportedPage page = copy.getImportedPage(reader, i); copy.addPage(page); } document.close(); return true; } catch (IOException e) { LOGGER.error(e.getMessage(), e); } catch (DocumentException e) { LOGGER.error(e.getMessage(), e); } return false; }
From source file:adams.core.io.ZipUtils.java
/** * Lists the files stored in the ZIP file. * * @param input the ZIP file to obtain the file list from * @param listDirs whether to include directories in the list * @return the stored files/*from w ww . j ava 2s . c om*/ */ public static List<File> listFiles(File input, boolean listDirs) { List<File> result; ZipFile zipfile; Enumeration<ZipArchiveEntry> enm; ZipArchiveEntry entry; result = new ArrayList<>(); zipfile = null; try { zipfile = new ZipFile(input.getAbsoluteFile()); enm = zipfile.getEntries(); while (enm.hasMoreElements()) { entry = enm.nextElement(); // extract if (entry.isDirectory()) { if (listDirs) result.add(new File(entry.getName())); } else { result.add(new File(entry.getName())); } } } catch (Exception e) { e.printStackTrace(); } finally { if (zipfile != null) { try { zipfile.close(); } catch (Exception e) { // ignored } } } return result; }
From source file:com.piketec.jenkins.plugins.tpt.Utils.java
/** * Builds a absolute path from the workspace directory and the given path. * <ul>//from w ww .jav a 2 s. c o m * <li>If both are <code>null</code>, the current working directory will returned - hopefully it * is inside the workspace.</li> * <li>If the workspace is <code>null</code>, the path will returned.</li> * <li>If the path is <code>null</code>, the workspace will returned.</li> * <li>If the path is absolute, the path will returned.</li> * <li>If the path is relative, the path will append to the workspace and returned.</li> * </ul> * * @param workspaceDir * Current workspace for the build. * @param path * Relative or absolute path. * @return A absolute path, but it can be a nonexisting file system object or not a directory. */ public static File getAbsolutePath(File workspaceDir, File path) { File absPath = workspaceDir; if (path == null) { absPath = (workspaceDir == null) ? new File("") : workspaceDir; } else { if (path.isAbsolute()) { absPath = path; } else { absPath = (workspaceDir == null) ? path : new File(workspaceDir, path.toString()); } } return absPath.isAbsolute() ? absPath : absPath.getAbsoluteFile(); }
From source file:nbayes_mr.NBAYES_MR.java
public static void splitter(String fname) { String filePath = new File("").getAbsolutePath(); Integer count = 0;/*ww w. j a va 2 s.c om*/ try { Scanner s = new Scanner(new File(fname)); while (s.hasNext()) { count++; s.next(); } Integer cnt5 = count / 5; System.out.println(count); System.out.println(cnt5); Scanner sc = new Scanner(new File(fname)); File file1 = new File("/home/hduser/data1.txt"); File file2 = new File("/home/hduser/data2.txt"); File file3 = new File("/home/hduser/data3.txt"); File file4 = new File("/home/hduser/data4.txt"); File file5 = new File("/home/hduser/data5.txt"); file1.createNewFile(); file2.createNewFile(); file3.createNewFile(); file4.createNewFile(); file5.createNewFile(); FileWriter fw1 = new FileWriter(file1.getAbsoluteFile()); BufferedWriter bw1 = new BufferedWriter(fw1); FileWriter fw2 = new FileWriter(file2.getAbsoluteFile()); BufferedWriter bw2 = new BufferedWriter(fw2); FileWriter fw3 = new FileWriter(file3.getAbsoluteFile()); BufferedWriter bw3 = new BufferedWriter(fw3); FileWriter fw4 = new FileWriter(file4.getAbsoluteFile()); BufferedWriter bw4 = new BufferedWriter(fw4); FileWriter fw5 = new FileWriter(file5.getAbsoluteFile()); BufferedWriter bw5 = new BufferedWriter(fw5); for (int i = 0; i < cnt5; i++) { String l = sc.next(); bw1.write(l + "\n"); } for (int i = cnt5; i < 2 * cnt5; i++) { bw2.write(sc.next() + "\n"); } for (int i = 2 * cnt5; i < 3 * cnt5; i++) { bw3.write(sc.next() + "\n"); } for (int i = 3 * cnt5; i < 4 * cnt5; i++) { bw4.write(sc.next() + "\n"); } for (int i = 4 * cnt5; i < count; i++) { bw5.write(sc.next() + "\n"); } bw1.close(); bw2.close(); bw3.close(); bw4.close(); bw5.close(); sc.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:Main.java
public static boolean copyFile(File src, File tar) throws Exception { if (src.isFile()) { InputStream is = new FileInputStream(src); OutputStream op = new FileOutputStream(tar); BufferedInputStream bis = new BufferedInputStream(is); BufferedOutputStream bos = new BufferedOutputStream(op); byte[] bt = new byte[1024 * 8]; int len = bis.read(bt); while (len != -1) { bos.write(bt, 0, len);//from w ww . j a va 2 s .co m len = bis.read(bt); } bis.close(); bos.close(); } if (src.isDirectory()) { File[] f = src.listFiles(); tar.mkdir(); for (int i = 0; i < f.length; i++) { copyFile(f[i].getAbsoluteFile(), new File(tar.getAbsoluteFile() + File.separator + f[i].getName())); } } return true; }
From source file:com.linkedin.pinot.core.startree.StarTreeSerDe.java
/** * Utility method to convert star tree from on-heap to off-heap format: * <p>- If star tree does not exist, or if actual version is the same as * expected version, then no action is taken. </p> * * <p>- If actual version is on-heap and expected version is off-heap, then conversion from * on-heap to off-heap is performed. Both on-heap and off-heap formats are also backed up.</p> * * <p>- If actual version is off-heap and expected version is on-heap, then on-heap is restored from * backup version, if available, no-op otherwise. Note, there is no off-heap to on-heap * conversion as of now.</p>/*from w ww . j a v a2 s . c om*/ * * @param indexDir * @param starTreeVersionToLoad * @throws IOException * @throws ClassNotFoundException */ public static void convertStarTreeFormatIfNeeded(File indexDir, StarTreeFormatVersion starTreeVersionToLoad) throws IOException, ClassNotFoundException { File starTreeFile = new File(indexDir, V1Constants.STAR_TREE_INDEX_FILE); // If the star-tree file does not exist, this is not a star tree index, nothing to do here. if (!starTreeFile.exists()) { LOGGER.debug("Skipping Star Tree format conversion, as no star tree file exists for {}", starTreeFile.getAbsoluteFile()); return; } StarTreeFormatVersion actualVersion = getStarTreeVersion(starTreeFile); if (actualVersion == StarTreeFormatVersion.ON_HEAP && starTreeVersionToLoad == StarTreeFormatVersion.OFF_HEAP) { LOGGER.info("Converting Star Tree from on-heap to off-heap format for {}", starTreeFile.getAbsolutePath()); File starTreeOffHeapFile = new File(indexDir, V1Constants.STAR_TREE_OFF_HEAP_INDEX_FILE); if (starTreeOffHeapFile.exists()) { LOGGER.info("Replacing star tree on-heap format with off-heap format for {}", starTreeFile.getAbsolutePath()); FileUtils.copyFile(starTreeOffHeapFile, starTreeFile); } else { StarTreeInterf starTreeOnHeap = fromFile(starTreeFile, ReadMode.heap); // OnHeap only supports HEAP mode. try { writeTreeOffHeapFormat(starTreeOnHeap, starTreeOffHeapFile); FileUtils.copyFile(starTreeFile, new File(indexDir, V1Constants.STAR_TREE_ON_HEAP_INDEX_FILE)); FileUtils.copyFile(starTreeOffHeapFile, starTreeFile); } catch (Exception e) { LOGGER.warn("Exception caught while convert star tree on-heap to off-heap format for {}", starTreeFile.getAbsolutePath(), e); } } } else if (actualVersion == StarTreeFormatVersion.OFF_HEAP && starTreeVersionToLoad == StarTreeFormatVersion.ON_HEAP) { File starTreeOnHeapFile = new File(indexDir, V1Constants.STAR_TREE_ON_HEAP_INDEX_FILE); if (starTreeOnHeapFile.exists()) { try { FileUtils.copyFile(starTreeFile, new File(indexDir, V1Constants.STAR_TREE_OFF_HEAP_INDEX_FILE)); FileUtils.copyFile(starTreeOnHeapFile, starTreeFile); } catch (Exception e) { LOGGER.warn("Exception caught while converting star tree off-heap to on-heap for {}", starTreeFile.getAbsolutePath(), e); } } else { LOGGER.info( "Could not replace star tree format off-heap to on-heap as {} does not exist, will load off-heap format", starTreeOnHeapFile.getAbsolutePath()); } } }