use of dev.dworks.apps.anexplorer.network.NetworkFile in project AnExplorer by 1hakr.
the class NetworkStorageProvider method queryChildDocuments.
@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException {
final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
final NetworkFile parent = getFileForDocId(parentDocumentId);
final NetworkConnection connection = getNetworkConnection(parentDocumentId);
try {
connection.getConnectedClient().changeWorkingDirectory(parent.getPath());
for (FTPFile file : connection.getConnectedClient().listFiles()) {
includeFile(result, null, new NetworkFile(parent, file));
}
} catch (IOException e) {
CrashReportingManager.logException(e);
}
return result;
}
use of dev.dworks.apps.anexplorer.network.NetworkFile in project AnExplorer by 1hakr.
the class NetworkStorageProvider method getFileForDocId.
/**
* Translate your custom URI scheme into a File object.
*
* @param docId the document ID representing the desired file
* @return a File represented by the given document ID
* @throws java.io.FileNotFoundException
*/
private NetworkFile getFileForDocId(String docId) throws FileNotFoundException {
final int splitIndex = docId.indexOf(':', 1);
final String tag = docId.substring(0, splitIndex);
final String path = docId.substring(splitIndex + 1);
NetworkConnection root;
synchronized (mRootsLock) {
root = mRoots.get(tag);
}
if (root == null) {
throw new FileNotFoundException("No root for " + tag);
}
NetworkFile target = root.file;
if (target == null) {
return null;
}
target = new NetworkFile(target.getAbsolutePath() + path, tag);
return target;
}
use of dev.dworks.apps.anexplorer.network.NetworkFile in project AnExplorer by 1hakr.
the class NetworkStorageProvider method createDocument.
@Override
public String createDocument(String documentId, String mimeType, String displayName) throws FileNotFoundException {
NetworkFile parent = getFileForDocId(documentId);
NetworkFile file = new NetworkFile(parent.getPath() + displayName, "");
final NetworkConnection connection = getNetworkConnection(documentId);
try {
connection.getConnectedClient().createDirectories(file.getPath());
} catch (IOException e) {
throw new FileNotFoundException("Failed to create document with name " + displayName + " and documentId " + documentId);
}
return getDocIdForFile(file);
}
use of dev.dworks.apps.anexplorer.network.NetworkFile in project AnExplorer by 1hakr.
the class NetworkStorageProvider method deleteDocument.
@Override
public void deleteDocument(String documentId) throws FileNotFoundException {
NetworkFile file = getFileForDocId(documentId);
final NetworkConnection connection = getNetworkConnection(documentId);
try {
connection.getConnectedClient().deleteFile(file.getPath());
} catch (IOException e) {
throw new FileNotFoundException("Failed to delete document with id " + documentId);
}
}
use of dev.dworks.apps.anexplorer.network.NetworkFile in project AnExplorer by 1hakr.
the class NetworkStorageProvider method openDocument.
@Override
public ParcelFileDescriptor openDocument(final String documentId, final String mode, CancellationSignal signal) throws FileNotFoundException {
final NetworkFile file = getFileForDocId(documentId);
final NetworkConnection connection = getNetworkConnection(documentId);
try {
final boolean isWrite = (mode.indexOf('w') != -1);
if (isWrite) {
return null;
} else {
Uri ftpUri = connection.toUri(file);
URL url = new URL(ftpUri.toString());
URLConnection conn = url.openConnection();
InputStream inputStream = conn.getInputStream();
if (null != inputStream) {
return ParcelFileDescriptorUtil.pipeFrom(inputStream);
}
}
return null;
} catch (Exception e) {
CrashReportingManager.logException(e);
throw new FileNotFoundException("Failed to open document with id " + documentId + " and mode " + mode);
}
}
Aggregations