List of usage examples for java.io File getParent
public String getParent()
null
if this pathname does not name a parent directory. From source file:com.baifendian.swordfish.webserver.service.storage.FileSystemStorageService.java
/** * ?, /*from w w w . j a v a2 s . c om*/ * * @param file * @param destFilename */ @Override public void store(MultipartFile file, String destFilename) { try { if (file.isEmpty()) { throw new StorageException("Failed to store empty file " + file.getOriginalFilename()); } File destFile = new File(destFilename); File destDir = new File(destFile.getParent()); if (!destDir.exists()) { FileUtils.forceMkdir(destDir); } Files.copy(file.getInputStream(), Paths.get(destFilename)); } catch (IOException e) { throw new StorageException("Failed to store file " + file.getOriginalFilename(), e); } }
From source file:azkaban.database.AzkabanDatabaseUpdaterTest.java
@Ignore @Test//from w w w . j av a 2s. c o m public void testMySQLAutoCreate() throws Exception { clearMySQLTestDb(); URL resourceUrl = Resources.getResource("conf/dbtestmysql"); assertNotNull(resourceUrl); File resource = new File(resourceUrl.toURI()); String confDir = resource.getParent(); System.out.println("1.***Now testing check"); AzkabanDatabaseUpdater.main(new String[] { "-c", confDir }); System.out.println("2.***Now testing update"); AzkabanDatabaseUpdater.main(new String[] { "-u", "-c", confDir }); System.out.println("3.***Now testing check again"); AzkabanDatabaseUpdater.main(new String[] { "-c", confDir }); System.out.println("4.***Now testing update again"); AzkabanDatabaseUpdater.main(new String[] { "-c", confDir, "-u" }); System.out.println("5.***Now testing check again"); AzkabanDatabaseUpdater.main(new String[] { "-c", confDir }); }
From source file:com.eywa.impl.app.controllers.session.impl.RenderToolPDF.java
private void render(final DBObject item, final String pdf_path) throws Exception { // render only in not rendered till now if (!StringUtils.hasText(ItemSessionDataFile.getBase64(item))) { final File pdf_file = new File(pdf_path); final String output_root = pdf_file.getParent(); final int imageType = BufferedImage.TYPE_INT_RGB; final int resolution = 96; final int page_number = ItemSessionDataFile.getPageNumber(item); final List<String> files = PDFUtils.toImage(pdf_file, output_root, true, imageType, resolution, page_number, page_number); if (!files.isEmpty()) { final String file_path = files.get(0); final File file = new File(file_path); final ImageSize size = ImageIOUtils.getImageSize(file); ItemSessionDataFile.setFileTempPath(item, file_path); ItemSessionDataFile.setHeight(item, size.getHeight()); ItemSessionDataFile.setWidth(item, size.getWidth()); ItemSessionDataFile.setBase64(item, ImageIOUtils.readBase64(file)); }/*from ww w .j ava 2s. c o m*/ } }
From source file:com.ikanow.aleph2.storm.samples.script.PropertyBasedScriptProvider.java
public void init(String propertiesFileName) { loadProperties(propertiesFileName);//from w ww.j a v a2s .c o m File propFile = new File(propertiesFileName); String parentFolder = propFile.getParent(); for (Iterator<Entry<Object, Object>> it = properties.entrySet().iterator(); it.hasNext();) { Entry<Object, Object> entry = it.next(); if (entry.getKey().toString().equalsIgnoreCase(GLOBAL)) { globalScript = loadScriptFromResource(parentFolder, (String) entry.getValue()); } // if else { String scriptlet = loadScriptFromResource(parentFolder, (String) entry.getValue()); scriptlets.add(scriptlet); } } // for }
From source file:edu.harvard.mcz.imagecapture.ImageCaptureProperties.java
/** Warning: For unit testing only. Do not invoke this method. Always use getPathBelowBase(File aFilename) instead. * // w w w . jav a2s . c o m * @see edu.harvard.mcz.imagecapture.ImageCaptureProperties#getPathBelowBase(File) */ public static String getPathBelowBase(File aFilename, String fileSeparator) { String result = ""; String base = Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE); // this is what we are going to strip off aFilename //String filename = ""; // name of file if aFilename is a file rather than a directory result = aFilename.getPath(); log.debug("Local path to file: " + result); if (aFilename.isFile()) { result = aFilename.getParent(); } if (fileSeparator.equals("\\")) { if (!base.endsWith("\\")) { base = base + "\\"; } // the separator "\" is represented in java as "\\" and in a java regular expression as "\\\\" base = base.replaceAll("\\\\", "\\\\\\\\"); } else { if (!base.endsWith("/")) { base = base + "/"; } if (!result.endsWith("/")) { result = result + "/"; } } log.debug("Base path to remove: " + base); // strip base out of canonical form of aFilename if (base.equals(result)) { result = ""; } else { result = result.replaceFirst(base, ""); } // make sure that path ends with fileSeparator if (!result.endsWith(fileSeparator)) { result = result + fileSeparator; } // if result is only a separator set it to an empty string if (fileSeparator.equals("\\")) { if (result.equals("\\")) { result = ""; } } else { if (result.equals("/")) { result = ""; } } log.debug("Path below basepath: " + result); return result; }
From source file:gov.nih.nci.cacis.mirth.XSLForMirthFormatterTest.java
/** * Tests the xsl formatter// w w w.j ava 2 s . c om * @throws IOException io error thrown, if any * @throws URISyntaxException error thrown, if any */ @Test public void checkFormatter() throws IOException, URISyntaxException { final String origXslFile = getClass().getClassLoader().getResource("sample.xsl").getFile(); final File xslFile = new File(origXslFile); final String xslFileNm = xslFile.getName(); final String outputDir = xslFile.getParent() + "/formatted/"; final String[] args = { outputDir, origXslFile }; XSLForMirthFormatter.main(args); final File actualFrmtdXsl = new File(outputDir + xslFileNm); assertTrue(actualFrmtdXsl.exists()); final String actualFrmtdXslContent = FileUtils.readFileToString(actualFrmtdXsl); assertNotNull(actualFrmtdXslContent); final String expectedFrmtdXsl = getClass().getClassLoader().getResource("sample.formatted").getFile(); final String expectedFrmtdXslContent = FileUtils.readFileToString(new File(expectedFrmtdXsl)); assertNotNull(expectedFrmtdXslContent); assertEquals(expectedFrmtdXslContent, actualFrmtdXslContent); }
From source file:gool.executor.objc.ObjcCompiler.java
@Override public String run(File file, List<File> classPath) throws FileNotFoundException { List<String> params = new ArrayList<String>(); List<String> deps = new ArrayList<String>(); if (classPath != null) { for (File dependency : classPath) { deps.add(dependency.getParent()); }/*from w w w . ja v a 2 s. co m*/ } for (File dependency : getDependencies()) { deps.add(dependency.getParent()); } Map<String, String> env = new HashMap<String, String>(); params.addAll(Arrays.asList("./" + file.getName())); return Command.exec(getOutputDir(), params, env); }
From source file:kjscompiler.Settings.java
public Settings(String path) throws ParseException, FileNotFoundException, IOException { JSONParser parser = new JSONParser(); File file = new File(path); String parent = file.exists() ? file.getParent() : null; File dir = new File(null == parent || parent.isEmpty() ? "." : parent); FileReader fr = new FileReader(file); char[] fileData = new char[(int) file.length()]; fr.read(fileData);/*from w w w . j a v a2 s. c om*/ String content = new String(fileData); JSONObject obj = (JSONObject) parser.parse(content); if (obj.get("basedir") instanceof JSONArray) { this.baseDir = (JSONArray) obj.get("basedir"); } else { JSONArray arr = new JSONArray(); arr.add(obj.get("basedir")); this.baseDir = arr; } this.output = (String) obj.get("output"); this.level = (String) obj.get("level"); this.pattern = (String) obj.get("pattern"); this.wrapper = obj.get("wrapper") != null ? (String) obj.get("wrapper") : ""; this.projectPath = dir.getCanonicalPath(); dir = new File(this.projectPath, this.output); this.output = dir.getCanonicalPath(); fr.close(); }
From source file:com.thruzero.common.core.config.AbstractConfig.java
protected final String getConfigDirectory(final File configFile) { String configDirectory;//from w w w .ja v a 2 s . co m if (configFile.getParent() == null) { configDirectory = "." + EnvironmentHelper.FILE_PATH_SEPARATOR; } else { configDirectory = configFile.getParent() + EnvironmentHelper.FILE_PATH_SEPARATOR; } return configDirectory; }
From source file:Control.HandleTest.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www .j a v a 2 s. c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ String path = getClass().getResource("/").getPath(); if (Paths.path == null) { File file = new File(path + "test.html"); path = file.getParent(); File file1 = new File(path + "test1.html"); path = file1.getParent(); File file2 = new File(path + "test1.html"); path = file2.getParent(); Paths.path = path; } else { path = Paths.path; } String name; if (ServletFileUpload.isMultipartContent(request)) { List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : multiparts) { if (!item.isFormField()) { name = new File(item.getName()).getName(); // temp.logoImage = Paths.logoPath + name; String FilePath = path + Paths.logoPathStore + name; item.write(new File(FilePath)); } } } } catch (Exception e) { } }