Package com.mucommander.commons.file

Examples of com.mucommander.commons.file.AbstractFile


    /**
     * Opens the currently selected file in the active folder panel.
     */
    @Override
    public void performAction() {
        AbstractFile file;

        // Retrieves the currently selected file, aborts if none.
        // Note: a CachedFile instance is retrieved to avoid blocking the event thread.
        if((file = mainFrame.getActiveTable().getSelectedFile(true, true)) == null)
            return;
View Full Code Here


     * Trash folder was found, creates the standard GNOME user Trash folder and returns it.
     *
     * @return the user Trash folder, <code>null</code> if no user trash folder could be found or created
     */
     private static AbstractFile getTrashFolder() {
        AbstractFile userHome = LocalFile.getUserHome();

        AbstractFile primaryTrashDir = userHome.getChildSilently(".local/share/Trash/");   // new distro's trash path
        AbstractFile secondaryTrashDir;                                                    // standard path defined in specification
        if(isTrashFolder(primaryTrashDir)) {
            return primaryTrashDir;
        }
        else if(isTrashFolder(secondaryTrashDir=userHome.getChildSilently("Trash/"))) {
            return secondaryTrashDir;
View Full Code Here

        String fileInfoContent;
        String trashFileName;
        boolean retVal = true;     // overall return value (if everything went OK or at least one file wasn't moved properly
       
        for(int i=0; i<nbFiles; i++) {
            AbstractFile fileToDelete = queuedFiles.get(i);
            // generate content of info file and new filename
            try {
                fileInfoContent = getFileInfoContent(fileToDelete);
                trashFileName = getUniqueFilename(fileToDelete);
            } catch (IOException ex) {
              LOGGER.debug("Failed to create filename for new trash item: " + fileToDelete.getName(), ex);
               
                // continue with other file (do not move file, because info file cannot be properly created
                continue;
            }

            AbstractFile infoFile = null;
            OutputStreamWriter infoWriter = null;
            try {
                // create info file
                infoFile = TRASH_INFO_SUBFOLDER.getChild(trashFileName + ".trashinfo");
                infoWriter = new OutputStreamWriter(infoFile.getOutputStream());
                infoWriter.write(fileInfoContent);
            } catch (IOException ex) {
                retVal = false;
                LOGGER.debug("Failed to create trash info file: " + trashFileName, ex);

                // continue with other file (do not move file, because info file wasn't properly created)
                continue;
            }
            finally {
                if(infoWriter!=null) {
                    try {
                        infoWriter.close();
                    }
                    catch(IOException e) {
                        // Not much else to do
                    }
                }
            }
           
            try {
                // rename original file
                fileToDelete.renameTo(TRASH_FILES_SUBFOLDER.getChild(trashFileName));
            } catch (IOException ex) {
                try {
                    // remove info file
                    infoFile.delete();

                } catch (IOException ex1) {
                    // simply ignore
                }
               
View Full Code Here

            // Important: symlinks must *not* be followed -- following symlinks could have disastrous effects.
            if(!file.isSymlink()) {
                do {    // Loop for retry
                    // Delete each file in this folder
                    try {
                        AbstractFile subFiles[] = file.ls();
                        for(int i=0; i<subFiles.length && getState()!=INTERRUPTED; i++) {
                            // Notify job that we're starting to process this file (needed for recursive calls to processFile)
                            nextFile(subFiles[i]);
                            processFile(subFiles[i], null);
                        }
View Full Code Here

    protected boolean processFile(AbstractFile file, Object recurseParams) {
        if(getState()==INTERRUPTED)
            return false;
       
        // Create destination AbstractFile instance
        AbstractFile destFile = createDestinationFile(baseDestFolder, file.getName());
        if (destFile == null)
            return false;

        destFile = checkForCollision(sourceFile, baseDestFolder, destFile, false);
        if (destFile == null)
            return false;
       
        OutputStream out = null;
        try {
      out = destFile.getOutputStream();
     
      try {
        long written = StreamUtils.copyStream(origFileStream, out, BufferPool.getDefaultBufferSize(), partSize);
        sizeLeft -= written;
      } catch (FileTransferException e) {
        if (e.getReason() == FileTransferException.WRITING_DESTINATION) {
          // out of disk space - ask a user for a new disk
          recalculateCRC = true;    // recalculate CRC (DigestInputStream doesn't support mark() and reset())
          out.close();
          out = null;
          sizeLeft -= e.getBytesWritten();
          showErrorDialog(ActionProperties.getActionLabel(SplitFileAction.Descriptor.ACTION_ID),
              Translator.get("split_file_dialog.insert_new_media"),
              new String[]{OK_TEXT, CANCEL_TEXT},
              new int[]{OK_ACTION, CANCEL_ACTION});
          if (getState()==INTERRUPTED) {
            return false;
          }
          // create new output file if necessary
          if ((sizeLeft>0) && (getCurrentFileIndex() == getNbFiles()-1)) {
            setNbFiles(getNbFiles() + 1);
            addDummyFile(getNbFiles(), sizeLeft);
          }
        } else {
          throw e;
        }
      }
     
          // Preserve source file's date
            if(destFile.isFileOperationSupported(FileOperation.CHANGE_DATE)) {
                try {
                    destFile.changeDate(sourceFile.getDate());
                }
                catch (IOException e) {
                    LOGGER.debug("failed to change date of "+destFile, e);
                    // Fail silently
                }
            }

          // Preserve source file's permissions: preserve only the permissions bits that are supported by the source
            // file and use default permissions for the rest of them.
            if(destFile.isFileOperationSupported(FileOperation.CHANGE_PERMISSION)) {
                try {
                    // use #importPermissions(AbstractFile, int) to avoid isDirectory test
                    destFile.importPermissions(sourceFile, FilePermissions.DEFAULT_FILE_PERMISSIONS);
                }
                catch (IOException e) {
                    LOGGER.debug("failed to import "+sourceFile+" permissions into "+destFile, e);
                    // Fail silently
                }
            }
    }
        catch (IOException e) {
            LOGGER.debug("Caught exception", e);

            showErrorDialog(errorDialogTitle,
                    Translator.get("error_while_transferring", destFile.getName()),
                    new String[]{CANCEL_TEXT},
                    new int[]{CANCEL_ACTION}
                    );
      return false;
     
View Full Code Here

          setText(location = b.getLocation());
          tryToInterpretEnteredString = false;
        }

        // Look for a volume whose name is the entered string (case insensitive)
        AbstractFile volumes[] = LocalFile.getVolumes();
        for(int i=0; tryToInterpretEnteredString && i<volumes.length; i++) {
            if(volumes[i].getName().equalsIgnoreCase(location)) {
                // Change the current folder to the volume folder
              setText(location = volumes[i].getAbsolutePath());
              tryToInterpretEnteredString = false;
View Full Code Here

            sourceChecksum = AbstractFile.calculateChecksum(origFileStream, MessageDigest.getInstance("CRC32"));
            origFileStream.close();
                } else {
                    sourceChecksum = ((ChecksumInputStream)origFileStream).getChecksumString();
                }
          AbstractFile crcFile = baseDestFolder.getDirectChild(crcFileName);
          OutputStream crcStream = crcFile.getOutputStream();
          String line = sourceFile.getName() + " " + sourceChecksum;
          crcStream.write(line.getBytes("utf-8"));
          crcStream.close();
        } catch (Exception e) {
                    LOGGER.debug("Caught exception", e);
View Full Code Here

        JPanel fileDetailsPanel = new JPanel(new BorderLayout());

        Icon icon;
        boolean isSingleFile = files.size()==1;
        AbstractFile singleFile = isSingleFile?files.elementAt(0):null;
        if(isSingleFile) {
            icon = FileIcons.getFileIcon(singleFile, ICON_DIMENSION);
        }
        else {
            ImageIcon imageIcon = IconManager.getIcon(IconManager.COMMON_ICON_SET, "many_files.png");
            icon = IconManager.getScaledIcon(imageIcon, (float)ICON_DIMENSION.getWidth()/imageIcon.getIconWidth());
        }

        JLabel iconLabel = new JLabel(icon);
        iconLabel.setVerticalAlignment(JLabel.TOP);
        iconLabel.setBorder(new EmptyBorder(0, 0, 0, 8));

        fileDetailsPanel.add(iconLabel, BorderLayout.WEST);

        XAlignedComponentPanel labelPanel = new XAlignedComponentPanel(10);

        // Contents (set later)
        counterLabel = new JLabel("");
        labelPanel.addRow(Translator.get("properties_dialog.contents")+":", counterLabel, 6);

        // Location (set here)
        labelPanel.addRow(Translator.get("location")+":", new FileLabel(files.getBaseFolder(), true), 6);

        // Combined size (set later)
        JPanel sizePanel;
        sizePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        sizePanel.add(sizeLabel = new JLabel(""));
        sizePanel.add(new JLabel(dial = new SpinningDial()));
        labelPanel.addRow(Translator.get("size")+":", sizePanel, 6);

        if(OsFamily.MAC_OS_X.isCurrent() && OsVersion.MAC_OS_X_10_4.isCurrentOrHigher()
        && isSingleFile && singleFile.hasAncestor(LocalFile.class)) {
            String comment = OSXFileUtils.getSpotlightComment(singleFile);
            JLabel commentLabel = new JLabel(Translator.get("comment")+":");
            commentLabel.setAlignmentY(JLabel.TOP_ALIGNMENT);
            commentLabel.setVerticalAlignment(SwingConstants.TOP);
View Full Code Here

    /**
     * Edits the currently selected file.
     */
    @Override
    public synchronized void performAction() {
        AbstractFile file;
        Command      customCommand;

        file = mainFrame.getActiveTable().getSelectedFile(false, true);

        // At this stage, no assumption should be made on the type of file that is allowed to be viewed/edited:
        // viewer/editor implementations will decide whether they allow a particular file or not.
        if(file != null) {
            customCommand = getCustomCommand();


            // If we're using a custom command...
            if(customCommand != null) {
                // If it's local, run the custom editor on it.
                if(file.hasAncestor(LocalFile.class)) {
                    try {ProcessRunner.execute(customCommand.getTokens(file), file);}
                    catch(Exception e) {
                        InformationDialog.showErrorDialog(mainFrame);}
                }
               
View Full Code Here

        // Stop if interrupted
        if(getState()==INTERRUPTED)
            return false;
   
        // Destination folder
        AbstractFile destFolder = recurseParams==null?baseDestFolder:(AbstractFile)recurseParams;
   
        // Is current file at the base folder level ?
        boolean isFileInBaseFolder = files.indexOf(file)!=-1;

        // Determine filename in destination
        String originalName = file.getName();
        String destFileName;
        if(isFileInBaseFolder && newName!=null)
            destFileName = newName;
         else
            destFileName = originalName;
   
        // Create destination AbstractFile instance
        AbstractFile destFile = createDestinationFile(destFolder, destFileName);
        if (destFile == null)
            return false;

        // Do not follow symlink, simply delete it and return
        if(file.isSymlink()) {
            do {    // Loop for retry
                try  {
                    file.delete();
                    return true;
                }
                catch(IOException e) {
                    LOGGER.debug("IOException caught", e);

                    int ret = showErrorDialog(errorDialogTitle, Translator.get("cannot_delete_file", file.getAbsolutePath()));
                    // Retry loops
                    if(ret==RETRY_ACTION)
                        continue;
                    // Cancel, skip or close dialog returns false
                    return false;
                }
            } while(true);
        }

        destFile = checkForCollision(file, destFolder, destFile, renameMode);
        if (destFile == null)
            return false;

        // Let's try to rename the file using AbstractFile#renameTo() whenever possible, as it is more efficient
        // than moving the file manually.
        //
        // Do not attempt to rename the file in the following cases:
        // - destination has to be appended
        // - file schemes do not match (at the time of writing, no filesystem supports mixed scheme renaming)
        // - if the 'rename' operation is not supported
        // Note: we want to avoid calling AbstractFile#renameTo when we know it will fail, as it performs some costly
        // I/O bound checks and ends up throwing an exception which also comes at a cost.
        if(!append && file.getURL().schemeEquals(destFile.getURL()) && file.isFileOperationSupported(FileOperation.RENAME)) {
            try {
                file.renameTo(destFile);
                return true;
            }
            catch(IOException e) {
                // Fail silently: renameTo might fail under normal conditions, for instance for local files which are
                // not located on the same volume.
                LOGGER.debug("Failed to rename "+file+" into "+destFile+" (not necessarily an error)", e);
            }
        }
        // Rename couldn't be used or didn't succeed: move the file manually

        // Move the directory and all its children recursively, by copying files to the destination and then deleting them.
        if(file.isDirectory()) {
            // create the destination folder if it doesn't exist
            if(!(destFile.exists() && destFile.isDirectory())) {
                do {    // Loop for retry
                    try {
                        destFile.mkdir();
                    }
                    catch(IOException e) {
                        int ret = showErrorDialog(errorDialogTitle, Translator.get("cannot_create_folder", destFile.getAbsolutePath()));
                        // Retry loops
                        if(ret==RETRY_ACTION)
                            continue;
                        // Cancel, skip or close dialog returns false
                        return false;
                    }
                    break;
                } while(true);
            }
     
            // move each file in this folder recursively
            do {    // Loop for retry
                try {
                    AbstractFile subFiles[] = file.ls();
                    boolean isFolderEmpty = true;
                    for (AbstractFile subFile : subFiles) {
                        // Return now if the job was interrupted, so that we do not attempt to delete this folder
                        if (getState() == INTERRUPTED)
                            return false;
View Full Code Here

TOP

Related Classes of com.mucommander.commons.file.AbstractFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.