src/net/java/sip/communicator/impl/gui/main/chat/filetransfer/ReceiveFileConversationComponent.java
/**
     * Creates the file to download.
     *
     * @return the file to download.
     */
Creates the file to download.
@return the file to download.
Creates the file to download . @return the file to download .
private File createFile(IncomingFileTransferRequest fileTransferRequest)
    {
        File downloadFile = null;
        File downloadDir = null;
        String incomingFileName = fileTransferRequest.getFileName();
        incomingFileName = incomingFileName
            .replaceAll("[\\\\/:*?\"<>|]", "_");
        try
        {
            downloadDir = GuiActivator.getFileAccessService()
                .getDefaultDownloadDirectory();
            if (!downloadDir.exists())
            {
                if (!downloadDir.mkdirs())
                {
                    logger.error("Could not create the download directory : "
                        + downloadDir.getAbsolutePath());
                }
                if (logger.isDebugEnabled())
                    logger.debug("Download directory created : "
                        + downloadDir.getAbsolutePath());
            }
        }
        catch (IOException e)
        {
            if (logger.isDebugEnabled())
                logger.debug("Unable to find download directory.", e);
        }
        downloadFile = new File(downloadDir, incomingFileName);
        int index = 0;
        int filenameLenght = incomingFileName.lastIndexOf(".");
        if(filenameLenght == -1)
        {
            filenameLenght = incomingFileName.length();
        }
        while (downloadFile.exists())
        {
            String newFileName
             = incomingFileName.substring(0, filenameLenght)
                 + "-" + ++index
                 + incomingFileName.substring(filenameLenght);
            downloadFile = new File(downloadDir, newFileName);
        }
        if (!downloadFile.getName().equals(fileTransferRequest.getFileName()))
        {
            String fileName
                = getFileLabel( downloadFile.getName(),
                                fileTransferRequest.getFileSize());
            fileLabel.setText(fileName);
        }
        return downloadFile;
    }
private File createFile ( IncomingFileTransferRequest fileTransferRequest ) { File downloadFile = null ; File downloadDir = null ; String incomingFileName = fileTransferRequest . getFileName ( ) ; incomingFileName = incomingFileName . replaceAll ( "[\\\\/:*?\"<>|]" , "_" ) ; try { downloadDir = GuiActivator . getFileAccessService ( ) . getDefaultDownloadDirectory ( ) ; if ( ! downloadDir . exists ( ) ) { if ( ! downloadDir . mkdirs ( ) ) { logger . error ( "Could not create the download directory : " + downloadDir . getAbsolutePath ( ) ) ; } if ( logger . isDebugEnabled ( ) ) logger . debug ( "Download directory created : " + downloadDir . getAbsolutePath ( ) ) ; } } catch ( IOException e ) { if ( logger . isDebugEnabled ( ) ) logger . debug ( "Unable to find download directory." , e ) ; } downloadFile = new File ( downloadDir , incomingFileName ) ; int index = 0 ; int filenameLenght = incomingFileName . lastIndexOf ( "." ) ; if ( filenameLenght == - 1 ) { filenameLenght = incomingFileName . length ( ) ; } while ( downloadFile . exists ( ) ) { String newFileName = incomingFileName . substring ( 0 , filenameLenght ) + "-" + ++ index + incomingFileName . substring ( filenameLenght ) ; downloadFile = new File ( downloadDir , newFileName ) ; } if ( ! downloadFile . getName ( ) . equals ( fileTransferRequest . getFileName ( ) ) ) { String fileName = getFileLabel ( downloadFile . getName ( ) , fileTransferRequest . getFileSize ( ) ) ; fileLabel . setText ( fileName ) ; } return downloadFile ; }
Creates the file to download.
Creates the file to download .
// strip characters that are invalid on Windows and maybe other // platforms too // If a file with the given name already exists, add an index to the // file name. // Change the file name to the name we would use on the local file // system.