List of usage examples for org.apache.commons.io FilenameUtils indexOfLastSeparator
public static int indexOfLastSeparator(String filename)
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); } }