List of usage examples for org.apache.commons.io FilenameUtils getName
public static String getName(String filename)
From source file:com.enonic.cms.web.webdav.SimpleDavServlet.java
private boolean isHidden(final HttpServletRequest request) { final String uri = request.getRequestURI(); final String name = FilenameUtils.getName(uri); return this.configuration.isHidden(name); }
From source file:com.wipro.ats.bdre.filemon.QueuedFileUploader.java
private static void executeRegisterFiles(FileCopyInfo fileCopying) { try {/* ww w.j a v a2 s .c o m*/ String subProcessId = fileCopying.getSubProcessId(); String serverId = fileCopying.getServerId(); String path = fileCopying.getDstLocation() + "/" + FilenameUtils.getName(fileCopying.getFileName()); String fileHash = fileCopying.getFileHash(); String fileSize = String.valueOf(fileCopying.getFileSize()); long timeStamp = fileCopying.getTimeStamp(); Date dt = new Date(timeStamp); String strDate = sdf.format(dt); String[] params = { "-p", subProcessId, "-sId", serverId, "-path", path, "-fs", fileSize, "-fh", fileHash, "-cTS", strDate, "-bid", "0" }; LOGGER.debug("executeRegisterFiles Invoked for " + path); new RegisterFile().execute(params); } catch (Exception err) { LOGGER.error("Error execute register files ", err); throw new BDREException(err); } }
From source file:com.bt.download.android.gui.transfers.PeerHttpDownload.java
PeerHttpDownload(TransferManager manager, Peer peer, FileDescriptor fd) { this.manager = manager; this.peer = peer; this.fd = fd; this.dateCreated = new Date(); this.savePath = new File(SystemPaths.getSaveDirectory(fd.fileType), cleanFileName(FilenameUtils.getName(fd.filePath))); status = STATUS_DOWNLOADING;/* www.java 2s. com*/ File savePathRoot = this.savePath.getParentFile(); if (savePathRoot == null) { this.status = STATUS_SAVE_DIR_ERROR; } if (!savePathRoot.isDirectory() && !savePathRoot.mkdirs()) { this.status = STATUS_SAVE_DIR_ERROR; } }
From source file:com.hortonworks.amstore.view.StoreApplicationService.java
public String getPackageFilepath() { if (package_uri != null) { String targetPath = "/tmp"; String filename = FilenameUtils.getName(package_uri); // Remove any leftover uri characters filename = filename.split("\\?")[0]; return targetPath + "/" + filename; } else//from w w w .j a v a 2s. c o m return null; }
From source file:com.haulmont.cuba.core.sys.LogControlImpl.java
@Override public String getTail(String fileName) throws LogControlException { // security check, supported only valid file names fileName = FilenameUtils.getName(fileName); StringBuilder sb = new StringBuilder(); RandomAccessFile randomAccessFile = null; try {/*from w w w . j a va2 s. c o m*/ File logFile = new File(logDir, fileName); if (!logFile.exists()) throw new LogFileNotFoundException(fileName); randomAccessFile = new RandomAccessFile(logFile, "r"); long lengthFile = randomAccessFile.length(); if (lengthFile >= LOG_TAIL_AMOUNT_BYTES) { randomAccessFile.seek(lengthFile - LOG_TAIL_AMOUNT_BYTES); skipFirstLine(randomAccessFile); } while (randomAccessFile.read() != -1) { randomAccessFile.seek(randomAccessFile.getFilePointer() - 1); String line = readUtf8Line(randomAccessFile); if (line != null) { sb.append(line).append("\n"); } } } catch (IOException e) { log.error("Error reading log file", e); throw new LogControlException("Error reading log file: " + fileName); } finally { if (randomAccessFile != null) { try { randomAccessFile.close(); } catch (IOException ignored) { } } } return sb.toString(); }
From source file:com.mindquarry.desktop.client.dialog.conflict.AddConflictDialog.java
@Override protected void createLowerDialogArea(Composite composite) { Composite subComposite = new Composite(composite, SWT.NONE); subComposite.setLayout(new GridLayout(2, false)); Button button1 = makeRadioButton(subComposite, I18N.getString("Rename file and upload it using a new name:"), //$NON-NLS-1$ Action.RENAME);/*from w w w . j av a 2 s . co m*/ button1.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { newNameField.setEnabled(true); } }); newNameField = createNewNameField(subComposite, FilenameUtils.getName(conflict.getStatus().getPath())); newNameField.setFocus(); // no replace available because it is a dangerous, unrecoverable action /* * Button button2 = makeRadioButton(subComposite, * //M.getString("Overwrite the file on the server with your * local version"), //$NON-NLS-1$ //Action.REPLACE); * M.getString("Overwrite your local file with the one from the * server"), //$NON-NLS-1$ Action.REPLACE); * button2.addListener(SWT.Selection, new Listener() { public void * handleEvent(Event event) { newNameField.setEnabled(false); * okButton.setEnabled(true); } }); */ }
From source file:com.gitpitch.services.ImageService.java
public String buildTagOffline(String md) { try {//from w w w. j av a 2s. c o m String imageTagUrl = tagLink(md); String imageTagName = FilenameUtils.getName(imageTagUrl); String offlineTagUrl = IMG_OFFLINE_DIR + imageTagName; return md.replace(imageTagUrl, offlineTagUrl); } catch (Exception tex) { } return md; }
From source file:de.uzk.hki.da.format.PublishCLIConversionStrategy.java
@Override public List<Event> convertFile(ConversionInstruction ci) throws FileNotFoundException { if (pkg == null) throw new IllegalStateException("Package not set"); List<Event> results = new ArrayList<Event>(); for (String audience : audiences) { String audience_lc = audience.toLowerCase(); String repName = "dip/" + audience_lc; Path.make(object.getDataPath(), repName, ci.getTarget_folder()).toFile().mkdirs(); String[] commandAsArray = assemble(ci, repName); if (!cliConnector.execute(commandAsArray)) throw new RuntimeException("convert did not succeed"); String targetSuffix = ci.getConversion_routine().getTarget_suffix(); if (targetSuffix.equals("*")) targetSuffix = FilenameUtils.getExtension(ci.getSource_file().toRegularFile().getAbsolutePath()); DAFile result = new DAFile(pkg, repName, ci.getTarget_folder() + "/" + FilenameUtils.removeExtension(Matcher.quoteReplacement( FilenameUtils.getName(ci.getSource_file().toRegularFile().getAbsolutePath()))) + "." + targetSuffix); Event e = new Event(); e.setType("CONVERT"); e.setDetail(Utilities.createString(commandAsArray)); e.setSource_file(ci.getSource_file()); e.setTarget_file(result);// w w w . j a v a 2s . c o m e.setDate(new Date()); results.add(e); } return results; }
From source file:cms.service.impl.UploadServiceImpl.java
public String reName(String fileName) { if ((fileName != null) && (fileName.trim().length() > 0)) { fileName = FilenameUtils.getName(fileName); // ??//from w ww .j av a 2 s. c o m HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();// ? format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);// ? try { fileName = PinyinHelper.toHanyuPinyinString(fileName, format, ""); } catch (BadHanyuPinyinOutputFormatCombination e) { e.printStackTrace(); } Date Mytime = new Date(); // ???? // fileName = // "love"+String.format("%tH%tM",Mytime.getTime(),Mytime.getTime())+"."+uploadContentType.split("/")[1].toString(); fileName = "love" + String.format("%tH%tM%tS", Mytime.getTime(), Mytime.getTime(), Mytime.getTime()) + fileName; } //System.out.println("fileName:"+fileName); return fileName; }
From source file:edu.iastate.airl.semtus.server.UploadServiceController.java
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // process only multipart requests if (ServletFileUpload.isMultipartContent(req)) { // Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request try {/*from www . j ava 2 s . com*/ List<FileItem> items = upload.parseRequest(req); for (FileItem item : items) { // process only file upload - discard other form item types if (item.isFormField()) continue; String fileName = item.getName(); // get only the file name not whole path if (fileName != null) { fileName = FilenameUtils.getName(fileName); } File uploadedFile = new File(Utils.UPLOAD_DIRECTORY, fileName); // first clean-up the folder; we want no clutter on the server :-) String[] ls = new File(Utils.UPLOAD_DIRECTORY).list(); for (int idx = 0; idx < ls.length; idx++) { File file = new File(Utils.UPLOAD_DIRECTORY, ls[idx]); file.delete(); } if (uploadedFile.createNewFile()) { item.write(uploadedFile); resp.setStatus(HttpServletResponse.SC_CREATED); resp.getWriter().print("The file was created successfully."); resp.flushBuffer(); } else { throw new IOException("The file already exists in repository."); } } } catch (Exception e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occurred while creating the file : " + e.getMessage()); } } else { resp.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "Request contents type is not supported by the servlet."); } }