use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class CompareFoldersAction method performAction.
@Override
public void performAction() {
FileTable leftTable = mainFrame.getLeftPanel().getFileTable();
FileTable rightTable = mainFrame.getRightPanel().getFileTable();
FileTableModel leftTableModel = leftTable.getFileTableModel();
FileTableModel rightTableModel = rightTable.getFileTableModel();
int nbFilesLeft = leftTableModel.getFileCount();
int nbFilesRight = rightTableModel.getFileCount();
int fileIndex;
String tempFileName;
AbstractFile tempFile;
for (int i = 0; i < nbFilesLeft; i++) {
tempFile = leftTableModel.getFileAt(i);
if (tempFile.isDirectory())
continue;
tempFileName = tempFile.getName();
fileIndex = -1;
for (int j = 0; j < nbFilesRight; j++) if (rightTableModel.getFileAt(j).getName().equals(tempFileName)) {
fileIndex = j;
break;
}
if (fileIndex == -1 || rightTableModel.getFileAt(fileIndex).getDate() < tempFile.getDate()) {
leftTableModel.setFileMarked(tempFile, true);
leftTable.repaint();
}
}
for (int i = 0; i < nbFilesRight; i++) {
tempFile = rightTableModel.getFileAt(i);
if (tempFile.isDirectory())
continue;
tempFileName = tempFile.getName();
fileIndex = -1;
for (int j = 0; j < nbFilesLeft; j++) if (leftTableModel.getFileAt(j).getName().equals(tempFileName)) {
fileIndex = j;
break;
}
if (fileIndex == -1 || leftTableModel.getFileAt(fileIndex).getDate() < tempFile.getDate()) {
rightTableModel.setFileMarked(tempFile, true);
rightTable.repaint();
}
}
// Notify registered listeners that currently marked files have changed on the file tables
leftTable.fireMarkedFilesChangedEvent();
rightTable.fireMarkedFilesChangedEvent();
}
use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class GoToParentInBothPanelsAction method performAction.
// - Action code ---------------------------------------------------------------------
// -----------------------------------------------------------------------------------
/**
* Opens both the active and inactive folder panel's parent directories.
*/
@Override
public void performAction() {
Thread openThread;
AbstractFile parent;
// If the current panel has a parent file, navigate to it.
if ((parent = mainFrame.getActivePanel().getCurrentFolder().getParent()) != null) {
openThread = mainFrame.getActivePanel().tryChangeCurrentFolder(parent);
// to it.
if ((parent = mainFrame.getInactivePanel().getCurrentFolder().getParent()) != null) {
if (openThread != null) {
while (openThread.isAlive()) {
try {
openThread.join();
} catch (InterruptedException e) {
}
}
}
mainFrame.getInactivePanel().tryChangeCurrentFolder(parent);
}
}
}
use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class VSphereFile method ls.
@Override
public AbstractFile[] ls() throws IOException, UnsupportedFileOperationException {
List<GuestFileInfo> fileInfos = new ArrayList<GuestFileInfo>();
int index = 0;
VsphereConnHandler connHandler = null;
try {
connHandler = getConnHandler();
ManagedObjectReference fileManager = getFileManager(connHandler);
boolean haveRemaining;
do {
GuestListFileInfo res = connHandler.getClient().getVimPort().listFilesInGuest(fileManager, vm, credentials, getPathInVm(), index, null, null);
haveRemaining = (res.getRemaining() != 0);
fileInfos.addAll(res.getFiles());
index = fileInfos.size();
} while (haveRemaining);
String parentPath = PathUtils.removeTrailingSeparator(fileURL.getPath()) + SEPARATOR;
Collection<AbstractFile> res = new ArrayList<AbstractFile>();
for (GuestFileInfo f : fileInfos) {
final String name = getFileName(f.getPath());
if (name.equals(".") || name.equals("..")) {
continue;
}
FileURL childURL = (FileURL) fileURL.clone();
childURL.setPath(parentPath + name);
AbstractFile newFile = new VSphereFile(childURL, this, f);
res.add(newFile);
}
return res.toArray(new AbstractFile[0]);
} catch (FileFaultFaultMsg e) {
translateandLogException(e);
} catch (GuestOperationsFaultFaultMsg e) {
translateandLogException(e);
} catch (InvalidStateFaultMsg e) {
translateandLogException(e);
} catch (RuntimeFaultFaultMsg e) {
translateandLogException(e);
} catch (TaskInProgressFaultMsg e) {
translateandLogException(e);
} catch (InvalidPropertyFaultMsg e) {
translateandLogException(e);
} catch (URISyntaxException e) {
translateandLogException(e);
} finally {
releaseConnHandler(connHandler);
}
// we never get here..
return null;
}
use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class S3File method listObjects.
protected AbstractFile[] listObjects(String bucketName, String prefix, S3File parent) throws IOException {
try {
StorageObjectsChunk chunk = service.listObjectsChunked(bucketName, prefix, "/", Constants.DEFAULT_OBJECT_LIST_CHUNK_SIZE, null, true);
StorageObject[] objects = chunk.getObjects();
String[] commonPrefixes = chunk.getCommonPrefixes();
if (objects.length == 0 && !prefix.equals("")) {
// This happens only when the directory does not exist
throw new IOException();
}
AbstractFile[] children = new AbstractFile[objects.length + commonPrefixes.length];
FileURL childURL;
int i = 0;
String objectKey;
for (StorageObject object : objects) {
// Discard the object corresponding to the prefix itself
objectKey = object.getKey();
if (objectKey.equals(prefix))
continue;
childURL = (FileURL) fileURL.clone();
childURL.setPath(bucketName + "/" + objectKey);
Map<String, Object> parameters = new HashMap<>();
parameters.put("service", service);
parameters.put("object", object);
children[i] = FileFactory.getFile(childURL, parent, parameters);
i++;
}
org.jets3t.service.model.S3Object directoryObject;
for (String commonPrefix : commonPrefixes) {
childURL = (FileURL) fileURL.clone();
childURL.setPath(bucketName + "/" + commonPrefix);
directoryObject = new org.jets3t.service.model.S3Object(commonPrefix);
// Common prefixes are not objects per se, and therefore do not have a date, content-length nor owner.
directoryObject.setLastModifiedDate(new Date(System.currentTimeMillis()));
directoryObject.setContentLength(0);
Map<String, Object> parameters = new HashMap<>();
parameters.put("service", service);
parameters.put("object", directoryObject);
children[i] = FileFactory.getFile(childURL, parent, parameters);
i++;
}
// to know in advance whether the prefix will appear in the results or not.
if (i < children.length) {
AbstractFile[] childrenTrimmed = new AbstractFile[i];
System.arraycopy(children, 0, childrenTrimmed, 0, i);
return childrenTrimmed;
}
return children;
} catch (ServiceException e) {
throw getIOException(e);
}
}
use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class SFTPFile method ls.
@SuppressWarnings("unchecked")
@Override
public AbstractFile[] ls() throws IOException {
List<LsEntry> files = new ArrayList<LsEntry>();
try (SFTPConnectionHandler connHandler = (SFTPConnectionHandler) ConnectionPool.getConnectionHandler(connHandlerFactory, fileURL, true)) {
// Makes sure the connection is started, if not starts it
connHandler.checkConnection();
files = connHandler.channelSftp.ls(absPath);
} catch (Exception e) {
LOGGER.error("failed to ls %s", getURL());
}
int nbFiles = files.size();
// File doesn't exist, return an empty file array
if (nbFiles == 0)
return new AbstractFile[] {};
AbstractFile[] children = new AbstractFile[nbFiles];
FileURL childURL;
String filename;
int fileCount = 0;
String parentPath = fileURL.getPath();
if (!parentPath.endsWith(SEPARATOR))
parentPath += SEPARATOR;
// Fill AbstractFile array and discard '.' and '..' files
for (LsEntry file : files) {
filename = file.getFilename();
// Discard '.' and '..' files, dunno why these are returned
if (filename.equals(".") || filename.equals(".."))
continue;
childURL = (FileURL) fileURL.clone();
childURL.setPath(parentPath + filename);
children[fileCount++] = FileFactory.getFile(childURL, this, Collections.singletonMap("attributes", new SFTPFileAttributes(childURL, file.getAttrs())));
}
// Create new array of the exact file count
if (fileCount < nbFiles) {
AbstractFile[] newChildren = new AbstractFile[fileCount];
System.arraycopy(children, 0, newChildren, 0, fileCount);
return newChildren;
}
return children;
}
Aggregations