Search in sources :

Example 1 with NetworkFile

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;
}
Also used : NetworkConnection(dev.dworks.apps.anexplorer.network.NetworkConnection) FTPFile(org.apache.commons.net.ftp.FTPFile) IOException(java.io.IOException) NetworkFile(dev.dworks.apps.anexplorer.network.NetworkFile) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 2 with NetworkFile

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;
}
Also used : NetworkConnection(dev.dworks.apps.anexplorer.network.NetworkConnection) FileNotFoundException(java.io.FileNotFoundException) NetworkFile(dev.dworks.apps.anexplorer.network.NetworkFile)

Example 3 with NetworkFile

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);
}
Also used : NetworkConnection(dev.dworks.apps.anexplorer.network.NetworkConnection) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) NetworkFile(dev.dworks.apps.anexplorer.network.NetworkFile)

Example 4 with NetworkFile

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);
    }
}
Also used : NetworkConnection(dev.dworks.apps.anexplorer.network.NetworkConnection) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) NetworkFile(dev.dworks.apps.anexplorer.network.NetworkFile)

Example 5 with NetworkFile

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);
    }
}
Also used : InputStream(java.io.InputStream) NetworkConnection(dev.dworks.apps.anexplorer.network.NetworkConnection) FileNotFoundException(java.io.FileNotFoundException) NetworkFile(dev.dworks.apps.anexplorer.network.NetworkFile) Uri(android.net.Uri) URL(java.net.URL) URLConnection(java.net.URLConnection) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

NetworkConnection (dev.dworks.apps.anexplorer.network.NetworkConnection)5 NetworkFile (dev.dworks.apps.anexplorer.network.NetworkFile)5 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 Uri (android.net.Uri)1 MatrixCursor (dev.dworks.apps.anexplorer.cursor.MatrixCursor)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 FTPFile (org.apache.commons.net.ftp.FTPFile)1