List of usage examples for java.io File getParentFile
public File getParentFile()
null
if this pathname does not name a parent directory. From source file:mobile.service.core.ClientLogService.java
/** * //from ww w . j av a 2 s. co m * * @param from ??, * @param sourceFile length>0 * @param description ??,? */ public static void uploadLog(final String from, File sourceFile, final String description) { if (sourceFile == null || StringUtils.isBlank(from)) { throw new IllegalArgumentException("illegal param. sourceFile = " + sourceFile + ", from = " + from); } if (sourceFile.length() <= 0) { throw new IllegalArgumentException("sourceFile.length() <= 0"); } String absDestFilePath = JPAUtil.indieTransaction(new IndieTransactionFunc<String>() { @Override public String call(EntityManager em) { // ? DateTime now = new DateTime(); MobileClientLog log = new MobileClientLog(); log.setCreateTime(now.toDate()); log.setDescription(description); log.setDevice(from); JPA.em().persist(log); String destFileName = now.toString("yyyyMMdd-HHmmss") + "-" + log.getId() + ".log"; String absDestFilePath = FileService.getMobileAbsUploadPath() + "clientLog/" + destFileName; String relDestFilePath = FileService.getMobileRelUploadPath() + "clientLog/" + destFileName; log.setLogFileUrl(relDestFilePath); JPA.em().merge(log); return absDestFilePath; } }); File destFile = new File(absDestFilePath); if (!destFile.getParentFile().exists()) { destFile.getParentFile().mkdirs(); } FileService.copyFile(sourceFile.getAbsolutePath(), absDestFilePath); }
From source file:ar.com.fdvs.dj.test.ReportExporter.java
public static void exportReportXls(JasperPrint jp, String path) throws JRException, FileNotFoundException { JRXlsExporter exporter = new JRXlsExporter(); File outputFile = new File(path); File parentFile = outputFile.getParentFile(); if (parentFile != null) parentFile.mkdirs();//from w ww .j a va 2 s. co m FileOutputStream fos = new FileOutputStream(outputFile); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fos); exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE); exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE); exporter.setParameter(JRXlsExporterParameter.IS_IGNORE_GRAPHICS, Boolean.FALSE); exporter.exportReport(); logger.debug("XLS Report exported: " + path); }
From source file:com.kixeye.chassis.bootstrap.TestUtils.java
public static OutputStream createFile(String path) { try {/*from ww w. ja va 2s . co m*/ Path p = Paths.get(SystemPropertyUtils.resolvePlaceholders(path)); if (Files.exists(p)) { Files.delete(p); } File file = new File(path); if (!file.getParentFile().exists()) { if (!file.getParentFile().mkdirs()) { throw new RuntimeException("Unable to create parent file(s) " + file.getParent()); } } return Files.newOutputStream(p); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.bluexml.side.clazz.alfresco.reverse.reverser.Reverser.java
public static void executeReverse(Collection<File> alfrescoModels, File sideModelRepo, List<IFile> sideModels, boolean verbose) throws Exception { ReverseScheduler rs = new ReverseScheduler(alfrescoModels, verbose); rs.schedule();/* ww w . j ava 2s .c o m*/ Map<Integer, List<Model>> tree = rs.getTree(); // reverse according to scheduled order (import dependencies tree) ReverseModel rm = new ReverseModel(verbose); // load and register EObject from existing SIDE models rm.loadSIDEModels(sideModels); // execute reverse for (Map.Entry<Integer, List<Model>> ent : tree.entrySet()) { for (Model model : ent.getValue()) { EObject sideO = rm.reverse(model); String name = model.getName(); String modelName = ReverseHelper.extractLocalNameFromAlfQName(name); String modelPrefix = ReverseHelper.extractPrefixFromAlfQName(name); File file = new File(sideModelRepo, modelPrefix + StringUtils.capitalize(modelName) + ".dt"); file.getParentFile().mkdirs(); file.createNewFile(); System.out.println("save model :" + file); EResourceUtils.saveModel(file, sideO); } } List<Object> notReverted = rm.getNotReverted(); if (notReverted.size() > 0) { List<String> errorRepport = new ArrayList<String>(); for (Object object : notReverted) { Class c = (Class) object; errorRepport.add(c.getName()); } System.err.println("Fail to reverse Overrides for :" + errorRepport); } }
From source file:io.hawkcd.agent.AgentConfiguration.java
private static void createConfigFile(File configFile) { configFile.getParentFile().mkdir(); InputStream inputStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(ConfigConstants.AGENT_CONFIG_FILE_NAME); try {/* www .j ava 2 s . c o m*/ FileUtils.copyInputStreamToFile(inputStream, configFile); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean save(String fileName, Bitmap bitmap) { if (fileName == null || bitmap == null) { return false; }//from w ww .j ava 2 s .c om boolean savedSuccessfully = false; OutputStream os = null; File imageFile = new File(fileName); File tmpFile = new File(imageFile.getAbsolutePath() + ".tmp"); try { if (!imageFile.getParentFile().exists()) { imageFile.getParentFile().mkdirs(); } os = new BufferedOutputStream(new FileOutputStream(tmpFile)); savedSuccessfully = bitmap.compress(Bitmap.CompressFormat.PNG, 100, os); } catch (Exception e) { e.printStackTrace(); } finally { if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } if (savedSuccessfully && tmpFile != null && !tmpFile.renameTo(imageFile)) { savedSuccessfully = false; } if (!savedSuccessfully) { tmpFile.delete(); } } return savedSuccessfully; }
From source file:ar.com.fdvs.dj.test.ReportExporter.java
public static void exportReportPlainXls(JasperPrint jp, String path) throws JRException, FileNotFoundException { // JRXlsExporter exporter = new JRXlsExporter(); JExcelApiExporter exporter = new JExcelApiExporter(); File outputFile = new File(path); File parentFile = outputFile.getParentFile(); if (parentFile != null) parentFile.mkdirs();/* w w w .j av a2 s . c o m*/ FileOutputStream fos = new FileOutputStream(outputFile); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fos); exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE); exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE); exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE); exporter.exportReport(); logger.debug("Report exported: " + path); }
From source file:com.android.tradefed.util.ZipUtil2.java
/** * Utility method to extract entire contents of zip file into given directory * * @param zipFile the {@link ZipFile} to extract * @param destDir the local dir to extract file to * @throws IOException if failed to extract file *//*w w w . j a v a2 s .c om*/ public static void extractZip(ZipFile zipFile, File destDir) throws IOException { Enumeration<? extends ZipArchiveEntry> entries = zipFile.getEntries(); while (entries.hasMoreElements()) { ZipArchiveEntry entry = entries.nextElement(); File childFile = new File(destDir, entry.getName()); childFile.getParentFile().mkdirs(); if (entry.isDirectory()) { childFile.mkdirs(); applyUnixModeIfNecessary(entry, childFile); continue; } else { FileUtil.writeToFile(zipFile.getInputStream(entry), childFile); applyUnixModeIfNecessary(entry, childFile); } } }
From source file:net.landora.video.info.file.FileHasher.java
public static void checkDirectory(File dir) throws IOException { for (File file : dir.listFiles()) { if (file.isHidden()) { continue; }/*from w w w . j av a2 s . c om*/ if (file.isDirectory()) { checkDirectory(file); } else { String extension = ExtensionUtils.getExtension(file); if (!ExtensionUtils.isVideoExtension(extension)) { continue; } FileInfo info = FileInfoManager.getInstance().getFileInfo(file); VideoMetadata md = MetadataProvidersManager.getInstance().getMetadata(info); if (md == null) { continue; } file = file.getCanonicalFile(); String filename = getOutputFilename(md) + "." + extension; File outputFile = new File(getOutputFolder(md), filename); outputFile.getParentFile().mkdirs(); outputFile = outputFile.getCanonicalFile(); if (!outputFile.equals(file)) { if (outputFile.exists()) { } else { FileUtils.moveFile(file, outputFile); } } } } }
From source file:azkaban.soloserver.AzkabanSingleServer.java
/** * To enable "run out of the box for testing". *//*from ww w .j av a 2 s . com*/ private static String[] prepareDefaultConf() throws IOException { final File templateFolder = new File("test/local-conf-templates"); final File localConfFolder = new File("local/conf"); if (!localConfFolder.exists()) { FileUtils.copyDirectory(templateFolder, localConfFolder.getParentFile()); log.info("Copied local conf templates from " + templateFolder.getAbsolutePath()); } log.info("Using conf at " + localConfFolder.getAbsolutePath()); return new String[] { "-conf", "local/conf" }; }