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:in.raster.oviyam.servlet.LanguageServlet.java
/** * Processes requests for both HTTP/*from w w w .ja v a 2 s . com*/ * <code>GET</code> and * <code>POST</code> methods. * * @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 { PrintWriter out = response.getWriter(); try { String option = request.getParameter("option"); File tempDir = (File) getServletContext().getAttribute("javax.servlet.context.tempdir"); LanguageHandler langHandler = new LanguageHandler(tempDir.getParent()); /*String warName = request.getContextPath().substring(1); String tmpDirPath = tempDir.getAbsolutePath(); tmpDirPath = tmpDirPath.substring(0, tmpDirPath.indexOf(warName)); LanguageHandler langHandler = new LanguageHandler(tmpDirPath);*/ if (option.equals("set")) { String language = request.getParameter("language"); // Language lang = new Language(); //lang.setLanguage(language); langHandler.updateLanguage(language); out.println("Success"); } else if (option.equals("getall")) { response.setContentType("application/json"); JSONArray langArray = new JSONArray(langHandler.getLanguage()); out.println(langArray); } else { out.println(langHandler.getCurrentLanguage()); } } finally { out.close(); } }
From source file:Control.HandleAddFoodMenu.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w. ja va2 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"); HttpSession session = request.getSession(); Food temp = new Food(); try (PrintWriter out = response.getWriter()) { LinkedList<String> names = new LinkedList<>(); /* TODO output your page here. You may use following sample code. */ String path = getClass().getResource("/").getPath(); String[] tempS = null; 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; } path = Paths.tempPath; String name; String sepName = Tools.CurrentTime(); if (ServletFileUpload.isMultipartContent(request)) { List<?> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); Iterator iter = multiparts.iterator(); int index = 0; tempS = new String[multiparts.size() - 1]; while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (!item.isFormField()) { name = new File(item.getName()).getName(); names.add(name); String FilePath = path + Paths.foodImagePath + sepName + name; item.write(new File(FilePath)); } else { String test = item.getFieldName(); tempS[index++] = item.getString(); } } index = 0; temp.categoryid = Integer.parseInt(tempS[index++]); temp.ID = tempS[index++]; temp.name = tempS[index++]; temp.price = Double.parseDouble(tempS[index++]); temp.pieces = Integer.parseInt(tempS[index++]); temp.description = tempS[index++]; temp.restid = Integer.parseInt(tempS[index++]); temp.resID = tempS[index++]; temp.rename = tempS[index++]; } if (Food.checkExisted(temp.ID, temp.name)) { response.sendRedirect("./Admin/AddMenu.jsp?index=1" + "&id=" + temp.restid + "&restid=" + temp.resID + "&name=" + temp.rename); } else { if (Food.addNewFood(temp)) { int id = Food.getFoodID(temp.ID); boolean flag = true; for (String s : names) { if (Image.addImage(s, Paths.foodImagePathStore + sepName + s, id)) { } else { flag = false; break; } } if (flag) { response.sendRedirect("./Admin/AddMenu.jsp?index=2" + "&id=" + temp.restid + "&restid=" + temp.resID + "&name=" + temp.rename); } else { response.sendRedirect("./Admin/AddMenu.jsp?index=4" + "&id=" + temp.restid + "&restid=" + temp.resID + "&name=" + temp.rename); } } else { response.sendRedirect("./Admin/AddMenu.jsp?index=3" + "&id=" + temp.restid + "&restid=" + temp.resID + "&name=" + temp.rename); } } } catch (Exception e) { response.sendRedirect("./Admin/AddMenu.jsp?index=0" + "&id=" + temp.restid + "&restid=" + temp.resID + "&name=" + temp.rename); } }
From source file:com.cip.crane.agent.utils.TaskHelper.java
public void deployTask(String fileName, String localFileName) throws FileNotFoundException, IOException, ArchiveException { File localFile = new File(localFileName); if (!localFile.exists()) { localFile.getParentFile().mkdirs(); localFile.createNewFile();//from w w w . jav a 2s . c o m } // readFileFromHdfs(fileName, localFileName); readFileFromHttp(fileName, localFileName); File inputFile = new File(localFileName); extractFile(localFileName, inputFile.getParent()); }
From source file:com.cubeia.games.poker.war.service.WarServerService.java
/** * Takes a relative to the cwd (current work dir, poker-uar) path and * creates the absolute path to the war file. * <p>/*www.j ava 2 s. c o m*/ * TODO: this needs to be changed to use either java or firebase mechanics * to determine cwd and the war location in a more elegant (ideally * generic) way. * * @param war the relative path to the war * @return the absolute path to the war */ public String getWarPath(String war) { File file; String sarRoot; try { file = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); sarRoot = file.getParent(); } catch (URISyntaxException ex) { log.debug(null, ex); sarRoot = ""; } String libDir = FilenameUtils.concat(sarRoot, "META-INF/lib"); String warPath = FilenameUtils.concat(libDir, war); log.debug("warPath : " + warPath); return warPath; }
From source file:org.hoteia.qalingo.app.business.job.email.AbstractEmailItemProcessor.java
public Email process(CommonProcessIndicatorItemWrapper<Long, Email> wrapper) throws Exception { Email email = wrapper.getItem();//from www . j a v a 2 s .c om Blob emailcontent = email.getEmailContent(); InputStream is = emailcontent.getBinaryStream(); ObjectInputStream oip = new ObjectInputStream(is); Object object = oip.readObject(); MimeMessagePreparatorImpl mimeMessagePreparator = (MimeMessagePreparatorImpl) object; oip.close(); is.close(); try { // SANITY CHECK if (email.getStatus().equals(Email.EMAIl_STATUS_PENDING)) { if (mimeMessagePreparator.isMirroringActivated()) { String filePathToSave = mimeMessagePreparator.getMirroringFilePath(); File file = new File(filePathToSave); // SANITY CHECK : create folders String absoluteFolderPath = file.getParent(); File absolutePathFile = new File(absoluteFolderPath); if (!absolutePathFile.exists()) { absolutePathFile.mkdirs(); } if (!file.exists()) { FileOutputStream fileOutputStream = new FileOutputStream(file); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, Constants.UTF8); Writer out = new BufferedWriter(outputStreamWriter); if (StringUtils.isNotEmpty(mimeMessagePreparator.getHtmlContent())) { out.write(mimeMessagePreparator.getHtmlContent()); } else { out.write(mimeMessagePreparator.getPlainTextContent()); } try { if (out != null) { out.close(); } } catch (IOException e) { logger.debug("Cannot close the file", e); } } else { logger.debug("File already exists : " + filePathToSave); } } mailSender.send(mimeMessagePreparator); email.setStatus(Email.EMAIl_STATUS_SENDED); } else { logger.warn("Batch try to send email was already sended!"); } } catch (Exception e) { logger.error("Fail to send email! Exception is save in database, id:" + email.getId()); email.setStatus(Email.EMAIl_STATUS_ERROR); emailService.handleEmailException(email, e); } return email; }
From source file:interpolation.InteractiveRegression.java
public InteractiveRegression(final ArrayList<Pair<Integer, Double>> mts, final int degree, final File file) { this.mts = mts; this.inputfile = file; this.inputdirectory = file.getParent(); this.degree = degree; this.degree = (int) computeValueFromScrollbarPosition(this.degreeInt, MAX_SLIDER, MIN_DEGREE, MAX_DEGREE); }
From source file:com.yifanlu.PSXperiaTool.Extractor.CrashBandicootExtractor.java
public void extractApk() throws IOException, URISyntaxException { Logger.info("Starting extraction with PSXPeria Extractor version %s", PSXperiaTool.VERSION); verifyFiles();/* w w w . j av a2 s. com*/ processConfig(); decodeValues(); FileFilter filterCompiledRes = new FileFilter() { public boolean accept(File file) { if (file.getParent() == null || file.getParentFile().getParent() == null) return true; File parent = file.getParentFile(); return (!parent.getName().equals("res")) && (!parent.getParentFile().getName().equals("res")); } }; nextStep("Extracting APK"); extractZip(mApkFile, mOutputDir, filterCompiledRes); extractZpaks(); cleanUp(); moveResourceFiles(); patchStrings(); patchEmulator(); nextStep("Done."); }
From source file:com.dycody.android.idealnote.async.upgrade.UpgradeProcessor.java
/** * Upgrades all the old audio attachments to the new format 3gpp to avoid to exchange them for videos *///from w ww .j a v a2s . c om private void onUpgradeTo480() { final DbHelper dbHelper = DbHelper.getInstance(); for (Attachment attachment : dbHelper.getAllAttachments()) { if ("audio/3gp".equals(attachment.getMime_type()) || "audio/3gpp".equals(attachment.getMime_type())) { // File renaming File from = new File(attachment.getUriPath()); FilenameUtils.getExtension(from.getName()); File to = new File(from.getParent(), from.getName() .replace(FilenameUtils.getExtension(from.getName()), Constants.MIME_TYPE_AUDIO_EXT)); from.renameTo(to); // Note's attachment update attachment.setUri(Uri.fromFile(to)); attachment.setMime_type(Constants.MIME_TYPE_AUDIO); dbHelper.updateAttachment(attachment); } } }
From source file:de.uni_koblenz.jgralab.gretl.GReTLRunner.java
public void exec(String[] args) throws GraphIOException, IOException { CommandLine cli = oh.parse(args);//from w w w. j a va 2 s .c o m if (cli.hasOption('d')) { Transformation.DEBUG_EXECUTION = true; Transformation.DEBUG_REVERSE_EDGES = cli.hasOption('r'); } String schema, graphclass; if (cli.hasOption('s')) { schema = cli.getOptionValue('s'); } else { schema = "foo.bar.BazSchema"; } if (cli.hasOption('g')) { graphclass = cli.getOptionValue('g'); } else { graphclass = "BazGraph"; } Schema targetSchema = getExistingSchema(schema); Context c; if (targetSchema != null) { c = new Context(targetSchema); } else { c = new Context(schema, graphclass); } if (cli.getArgs().length == 0) { if (cli.hasOption('u') || cli.hasOption('i')) { System.err.println("Options -u and -i cannot be used if no source graph is given."); oh.printHelpAndExit(1); } Graph outGraph = executeTransformation(c, new File(cli.getOptionValue('t'))); String outFileName = null; if (cli.hasOption('o')) { outFileName = cli.getOptionValue('o'); } else { outFileName = "target_graph.tg"; } saveTargetGraph(outGraph, outFileName, cli); } else { for (String in : cli.getArgs()) { Graph inGraph = GraphIO.loadGraphFromFile(in, ImplementationType.GENERIC, new ConsoleProgressFunction("Loading")); if (cli.hasOption('u')) { c = new Context(inGraph.getSchema()); } else if (cli.hasOption('i')) { c = new Context(inGraph.getSchema()); c.setTargetGraph(inGraph); } c.setSourceGraph(inGraph); Graph outGraph = executeTransformation(c, new File(cli.getOptionValue('t'))); String outFileName = null; if (cli.hasOption('o') && (cli.getArgs().length == 1)) { outFileName = cli.getOptionValue('o'); } else { File inFile = new File(in); outFileName = inFile.getParent() + File.separator + "target_" + inFile.getName(); } saveTargetGraph(outGraph, outFileName, cli); } } System.out.println("Fini."); }
From source file:dpfmanager.shell.interfaces.gui.component.show.ShowController.java
public void showComboTextArea(String folderPath, String extension) { int count = 0; // Clear comboBox getView().clearComboBox();/*from w ww.j a va 2s . c o m*/ // Check if summary File summary = new File(folderPath); if (summary.isFile()) { getView().setCurrentReportParams(summary.getParent(), extension); getView().addComboChild(summary.getName().replace("." + extension, ""), true); count++; } // Add all individuals File folder = new File(folderPath); if (folder.isFile()) { folder = folder.getParentFile(); } getView().setCurrentReportParams(folder.getPath(), extension); IOFileFilter filter = customFilter(extension); IOFileFilter filterDir = customFilterDir(folder.getPath()); Collection<File> childs = FileUtils.listFiles(folder, filter, filterDir); for (File child : childs) { String onlyName = child.getName().replace("." + extension, ""); if (count == 0) { getView().addComboChild(onlyName, true); } else { getView().addComboChild(onlyName, false); } count++; } // Show nodes getView().showTextArea(); if (count > 1) { getView().showComboBox(); } }