Example usage for org.apache.commons.io FilenameUtils getName

List of usage examples for org.apache.commons.io FilenameUtils getName

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils getName.

Prototype

public static String getName(String filename) 

Source Link

Document

Gets the name minus the path from a full filename.

Usage

From source file:au.org.ala.delta.intkey.model.StartupUtils.java

/**
 * Save a copy of a dataset that was opened from a remote location
 * //ww w.  ja  v  a  2s. com
 * @param context
 *            Intkey context
 * @param saveDir
 *            Directory in which to save a copy of the dataset
 * @return A copy of the JNLP-style dataset startup file to use to open the
 *         saved copy of the dataset.
 * @throws IOException
 *             If saving to disk failed.
 */
public static File saveRemoteDataset(IntkeyContext context, File saveDir) throws IOException {
    StartupFileData startupFileData = context.getStartupFileData();
    File datasetZip = startupFileData.getDataFileLocalCopy();

    // Copy the zipped dataset as downloaded from the web
    // FileUtils.copyFileToDirectory(datasetZip, saveDir);

    // Copy the zipped dataset as downloaded from the web
    // Use utility method to avoid overwriting existing files with the same
    // name
    File copyZipFile = Utils.getSaveFileForDirectory(saveDir, datasetZip.getName());
    FileUtils.copyFile(datasetZip, copyZipFile);

    // Write a new .ink file
    // Use utility method to avoid overwriting existing files with the same
    // name
    File newInkFile = Utils.getSaveFileForDirectory(saveDir,
            FilenameUtils.getName(startupFileData.getInkFileLocation().getFile()));

    FileWriter fw = new FileWriter(newInkFile);
    BufferedWriter bufFW = new BufferedWriter(fw);

    bufFW.append(INIT_FILE_INK_FILE_KEYWORD);
    bufFW.append("=");
    bufFW.append(newInkFile.toURI().toURL().toString());
    bufFW.append("\n");

    bufFW.append(INIT_FILE_DATA_FILE_KEYWORD);
    bufFW.append("=");
    bufFW.append(copyZipFile.toURI().toURL().toString());
    bufFW.append("\n");

    bufFW.append(INIT_FILE_INITIALIZATION_FILE_KEYWORD);
    bufFW.append("=");
    bufFW.append(startupFileData.getInitializationFileLocation());
    bufFW.append("\n");

    String imagePath = startupFileData.getImagePath();
    if (imagePath != null) {
        bufFW.append(INIT_FILE_IMAGE_PATH_KEYWORD);
        bufFW.append("=");
        bufFW.append(imagePath);
        bufFW.append("\n");
    }

    String infoPath = startupFileData.getInfoPath();
    if (infoPath != null) {
        bufFW.append(INIT_FILE_INFO_PATH_KEYWORD);
        bufFW.append("=");
        bufFW.append(infoPath);
        bufFW.append("\n");
    }

    bufFW.flush();
    bufFW.close();

    return newInkFile;
}

From source file:com.qq.tars.service.PatchService.java

@Transactional(rollbackFor = Exception.class)
public ServerPatch addServerPatch(String application, String moduleName, String tgz, String comment) {
    String md5 = md5(tgz);//from w  w w .j  a  v a2  s  . com
    Preconditions.checkNotNull(md5);

    ServerPatch patch = new ServerPatch();
    patch.setServer(String.format("%s.%s", application, moduleName));
    patch.setTgz(FilenameUtils.getName(tgz));
    patch.setMd5(md5);
    patch.setUpdateText(comment);
    patch.setPosttime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));

    patchMapper.insertServerPatch(patch);
    log.info("id={}, server={}, tgz={}, md5={}, update_text={}", patch.getId(), patch.getServer(),
            patch.getTgz(), patch.getMd5(), patch.getUpdateText());
    return patch;
}

From source file:com.iisigroup.cap.component.impl.FileDownloadResult.java

public FileDownloadResult(Request request, String file, String outputName, String contentType) {
    this._request = request;
    this._file = file;
    this._outputName = CapString.isEmpty(outputName) ? FilenameUtils.getName(_file) : outputName;
    this._contentType = contentType;
}

From source file:com.themodernway.server.core.file.FileUtils.java

public static final String name(String path) {
    if (null != (path = normalize(path))) {
        return FilenameUtils.getName(path);
    }//from   w  w w .  j  a  v a2 s .c  o m
    return path;
}

From source file:com.splunk.shuttl.archiver.listers.ArchivedIndexesLister.java

/**
 * @return {@link List} of indexes that are archived in a
 *         {@link ArchiveFileSystem}//w  ww. j  a  va2s  .c  om
 */
public List<String> listIndexes() {
    URI indexesHome = pathResolver.getIndexesHome();
    List<URI> indexUris = listIndexesUrisOnArchiveFileSystem(indexesHome);
    List<String> indexes = new ArrayList<String>();
    for (URI uri : indexUris)
        indexes.add(FilenameUtils.getName(uri.getPath()));
    return indexes;
}

From source file:com.cat.ic.listener.impl.OutputFileListenerMVNO.java

@BeforeStep
public void createOutputNameFromInput(StepExecution stepExecution) {
    ExecutionContext executionContext = stepExecution.getExecutionContext();
    String inputName = stepExecution.getStepName().replace(":", "-");

    if (executionContext.containsKey(inputKeyName)) {
        inputName = executionContext.getString(inputKeyName);
    }/*w  w  w. j a va  2 s  .c  om*/
    if (!executionContext.containsKey(outputKeyName)) {
        executionContext.putString(outputKeyName, path + FilenameUtils.getName(inputName) + ".mvno");
    }
    log.info("[" + executionContext.getString(outputKeyName) + "]");
}

From source file:com.thoughtworks.go.agent.common.util.JarUtil.java

public static List<File> extractFilesInLibDirAndReturnFiles(File aJarFile, Predicate<JarEntry> extractFilter,
        File outputTmpDir) {//from w ww  .  j av a2  s .co m
    List<File> newClassPath = new ArrayList<>();
    try (JarFile jarFile = new JarFile(aJarFile)) {

        List<File> extractedJars = jarFile.stream().filter(extractFilter).map(jarEntry -> {
            String jarFileBaseName = FilenameUtils.getName(jarEntry.getName());
            File targetFile = new File(outputTmpDir, jarFileBaseName);
            return extractJarEntry(jarFile, jarEntry, targetFile);
        }).collect(Collectors.toList());

        // add deps in dir specified by `libDirManifestKey`
        newClassPath.addAll(extractedJars);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return newClassPath;
}

From source file:com.xiaomi.linden.common.util.FileChangeWatcher.java

@Override
public void run() {
    try {/*from w  w  w.  j av  a 2  s  .c om*/
        watcher = FileSystems.getDefault().newWatchService();
        Path path = new File(absolutePath).toPath().getParent();
        String fileWatched = FilenameUtils.getName(absolutePath);
        path.register(watcher, new WatchEvent.Kind[] { StandardWatchEventKinds.ENTRY_MODIFY },
                SensitivityWatchEventModifier.HIGH);
        LOGGER.info("File watcher start to watch {}", absolutePath);

        while (isAlive()) {
            try {
                Thread.sleep(interval);
                WatchKey key = watcher.poll(1000l, TimeUnit.MILLISECONDS);
                if (key == null) {
                    continue;
                }

                List<WatchEvent<?>> events = key.pollEvents();
                for (WatchEvent<?> event : events) {
                    if (event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) {
                        String file = event.context().toString();
                        if (fileWatched.equals(file)) {
                            doOnChange();
                        }
                    }
                }

                if (!key.reset()) {
                    LOGGER.info("File watcher key not valid.");
                }
            } catch (InterruptedException e) {
                LOGGER.error("File watcher thread exit!");
                break;
            }
        }
    } catch (Throwable e) {
        LOGGER.error("File watcher error {}", Throwables.getStackTraceAsString(e));
    }
}

From source file:com.sangupta.jerry.util.ZipUtils.java

/**
 * Read a given file from the ZIP file and store it in a temporary file. The
 * temporary file is set to be deleted on exit of application.
 * /*w ww .  jav  a 2  s  .  com*/
 * @param zipFile
 *            the zip file from which the file needs to be read
 * 
 * @param fileName
 *            the name of the file that needs to be extracted
 * 
 * @return the {@link File} handle for the extracted file in the temp
 *         directory
 * 
 * @throws IllegalArgumentException
 *             if the zipFile is <code>null</code> or the fileName is
 *             <code>null</code> or empty.
 */
public static File readFileFromZip(File zipFile, String fileName) throws FileNotFoundException, IOException {
    if (zipFile == null) {
        throw new IllegalArgumentException("zip file to extract from cannot be null");
    }

    if (AssertUtils.isEmpty(fileName)) {
        throw new IllegalArgumentException("the filename to extract cannot be null/empty");
    }

    LOGGER.debug("Reading {} from {}", fileName, zipFile.getAbsolutePath());

    ZipInputStream stream = null;
    BufferedOutputStream outStream = null;
    File tempFile = null;

    try {
        byte[] buf = new byte[1024];
        stream = new ZipInputStream(new FileInputStream(zipFile));
        ZipEntry entry;
        while ((entry = stream.getNextEntry()) != null) {
            String entryName = entry.getName();
            if (entryName.equals(fileName)) {
                tempFile = File.createTempFile(FilenameUtils.getName(entryName),
                        FilenameUtils.getExtension(entryName));
                tempFile.deleteOnExit();

                outStream = new BufferedOutputStream(new FileOutputStream(tempFile));
                int readBytes;
                while ((readBytes = stream.read(buf, 0, 1024)) > -1) {
                    outStream.write(buf, 0, readBytes);
                }

                stream.close();
                outStream.close();

                return tempFile;
            }
        }
    } finally {
        IOUtils.closeQuietly(stream);
        IOUtils.closeQuietly(outStream);
    }

    return tempFile;
}

From source file:fr.ign.cogit.geoxygene.appli.gl.program.GLProgramBuilder.java

static void append(GLProgram program, RenderingMethodDescriptor method) throws Exception {
    for (ShaderRef shader_ref : method.getShadersReferences()) {
        Shader shader = null;//  w w  w.java 2 s .  c om
        try {
            if (shader_ref.location != null) {
                URL location_resolved = null;
                String shader_name = FilenameUtils.getName(shader_ref.location.toString());
                if (shader_ref.location.isAbsolute()) {
                    location_resolved = shader_ref.location.toURL();
                    shader = new Shader(shader_name, shader_ref.type, shader_ref.location.toURL());
                } else {
                    // Is this a relative path?
                    URI mlocation = method.getLocation().toURI();
                    location_resolved = mlocation.resolve(shader_ref.location).toURL();
                    if (!testURLValid(location_resolved)) {
                        location_resolved = Shader.DEFAULT_SHADERS_LOCATION_DIR.toURI()
                                .resolve(shader_ref.location).toURL();
                        if (!testURLValid(location_resolved))
                            location_resolved = null;
                    }
                }
                if (location_resolved != null) {
                    shader = new Shader(shader_name, shader_ref.type, location_resolved);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (shader == null) {
            logger.error("Failed to load the shader " + shader_ref + " for the redering method " + method
                    + ". Rendering with this method may cause unexpected behaviors.");
            throw new Exception("SHADER " + shader_ref.toString() + " at location " + shader_ref.location
                    + " WAS NOT FOUND : failed to build the program " + program.getName());
        }
        shader.addToGLProgram(program);
    }
}