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

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

Introduction

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

Prototype

public static int indexOfLastSeparator(String filename) 

Source Link

Document

Returns the index of the last directory separator character.

Usage

From source file:se.nbis.sftpsquid.SftpSquid.java

/**
 * Transfer the files//from   w  ww  .  j  a v  a  2  s  .co  m
 */
public void transfer() throws IOException {
    String source = hfs[0].file;
    String destination = hfs[1].file;
    log.debug("transfer(): " + source + " -> " + destination);

    FileMode.Type sourceType = getType(source, sftp_clients[0]);
    FileMode.Type destType = getType(destination, sftp_clients[1]);

    if (sourceType == FileMode.Type.DIRECTORY && destType != sourceType) {
        throw new IOException("Destination has to be a directory");
    }

    List<String> sources = buildTransferList(source, sftp_clients[0]);

    int lastSeparatorInSource = FilenameUtils.indexOfLastSeparator(source);
    if (lastSeparatorInSource == -1) {
        if (sourceType == FileMode.Type.REGULAR) {
            lastSeparatorInSource = 0;
        } else {
            lastSeparatorInSource = source.length();
        }
    }
    log.debug("transfer() lastSeparatorInSource: " + lastSeparatorInSource);

    for (String s : sources) {
        String d = destination;
        if (destType == FileMode.Type.DIRECTORY) {
            d += s.substring(lastSeparatorInSource);
        }

        transferFile(s, d);
    }
}