Search in sources :

Example 71 with FileNotFoundException

use of java.io.FileNotFoundException in project platform_frameworks_base by android.

the class StubProvider method dispatchCreateDocumentWithFlags.

private Bundle dispatchCreateDocumentWithFlags(Bundle extras) {
    String rootId = extras.getString(EXTRA_PARENT_ID);
    String mimeType = extras.getString(Document.COLUMN_MIME_TYPE);
    String name = extras.getString(Document.COLUMN_DISPLAY_NAME);
    List<String> streamTypes = extras.getStringArrayList(EXTRA_STREAM_TYPES);
    int flags = extras.getInt(EXTRA_FLAGS);
    Bundle out = new Bundle();
    String documentId = null;
    try {
        documentId = createDocument(rootId, mimeType, name, flags, streamTypes);
        Uri uri = DocumentsContract.buildDocumentUri(mAuthority, documentId);
        out.putParcelable(DocumentsContract.EXTRA_URI, uri);
    } catch (FileNotFoundException e) {
        Log.d(TAG, "Creating document with flags failed" + name);
    }
    return out;
}
Also used : Bundle(android.os.Bundle) FileNotFoundException(java.io.FileNotFoundException) Uri(android.net.Uri) Point(android.graphics.Point)

Example 72 with FileNotFoundException

use of java.io.FileNotFoundException in project platform_frameworks_base by android.

the class StubProvider method createFile.

private File createFile(StubDocument parent, String mimeType, String displayName) throws FileNotFoundException {
    if (parent == null) {
        throw new IllegalArgumentException("Can't create file " + displayName + " in null parent.");
    }
    if (!parent.file.isDirectory()) {
        throw new IllegalArgumentException("Can't create file " + displayName + " inside non-directory parent " + parent.file.getName());
    }
    final File file = new File(parent.file, displayName);
    if (file.exists()) {
        throw new FileNotFoundException("Duplicate file names not supported for " + file);
    }
    if (mimeType.equals(Document.MIME_TYPE_DIR)) {
        if (!file.mkdirs()) {
            throw new FileNotFoundException("Failed to create directory(s): " + file);
        }
        Log.i(TAG, "Created new directory: " + file);
    } else {
        boolean created = false;
        try {
            created = file.createNewFile();
        } catch (IOException e) {
            // We'll throw an FNF exception later :)
            Log.e(TAG, "createNewFile operation failed for file: " + file, e);
        }
        if (!created) {
            throw new FileNotFoundException("createNewFile operation failed for: " + file);
        }
        Log.i(TAG, "Created new file: " + file);
    }
    return file;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File)

Example 73 with FileNotFoundException

use of java.io.FileNotFoundException in project platform_frameworks_base by android.

the class StubProvider method deleteDocument.

@Override
public void deleteDocument(String documentId) throws FileNotFoundException {
    final StubDocument document = mStorage.get(documentId);
    final long fileSize = document.file.length();
    if (document == null || !document.file.delete())
        throw new FileNotFoundException();
    synchronized (mWriteLock) {
        document.rootInfo.size -= fileSize;
        mStorage.remove(documentId);
    }
    Log.d(TAG, "Document deleted: " + documentId);
    notifyParentChanged(document.parentId);
    getContext().getContentResolver().notifyChange(DocumentsContract.buildDocumentUri(mAuthority, document.documentId), null, false);
}
Also used : FileNotFoundException(java.io.FileNotFoundException)

Example 74 with FileNotFoundException

use of java.io.FileNotFoundException in project platform_frameworks_base by android.

the class StubProvider method createVirtualFile.

@VisibleForTesting
public Uri createVirtualFile(String rootId, String path, String mimeType, List<String> streamTypes, byte[] content) throws FileNotFoundException, IOException {
    final File file = createFile(rootId, path, mimeType, content);
    final StubDocument parent = mStorage.get(getDocumentIdForFile(file.getParentFile()));
    if (parent == null) {
        throw new FileNotFoundException("Parent not found.");
    }
    final StubDocument document = StubDocument.createVirtualDocument(file, mimeType, streamTypes, parent);
    mStorage.put(document.documentId, document);
    return DocumentsContract.buildDocumentUri(mAuthority, document.documentId);
}
Also used : FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 75 with FileNotFoundException

use of java.io.FileNotFoundException in project platform_frameworks_base by android.

the class PrintSpoolerService method writePrintJobData.

public void writePrintJobData(final ParcelFileDescriptor fd, final PrintJobId printJobId) {
    final PrintJobInfo printJob;
    synchronized (mLock) {
        printJob = getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY);
    }
    new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {
            FileInputStream in = null;
            FileOutputStream out = null;
            try {
                if (printJob != null) {
                    File file = generateFileForPrintJob(PrintSpoolerService.this, printJobId);
                    in = new FileInputStream(file);
                    out = new FileOutputStream(fd.getFileDescriptor());
                }
                final byte[] buffer = new byte[8192];
                while (true) {
                    final int readByteCount = in.read(buffer);
                    if (readByteCount < 0) {
                        return null;
                    }
                    out.write(buffer, 0, readByteCount);
                }
            } catch (FileNotFoundException fnfe) {
                Log.e(LOG_TAG, "Error writing print job data!", fnfe);
            } catch (IOException ioe) {
                Log.e(LOG_TAG, "Error writing print job data!", ioe);
            } finally {
                IoUtils.closeQuietly(in);
                IoUtils.closeQuietly(out);
                IoUtils.closeQuietly(fd);
            }
            Log.i(LOG_TAG, "[END WRITE]");
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
}
Also used : PrintJobInfo(android.print.PrintJobInfo) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) AtomicFile(android.util.AtomicFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)3572 IOException (java.io.IOException)2027 File (java.io.File)1415 FileInputStream (java.io.FileInputStream)906 InputStream (java.io.InputStream)535 FileOutputStream (java.io.FileOutputStream)522 BufferedReader (java.io.BufferedReader)301 FileReader (java.io.FileReader)267 ArrayList (java.util.ArrayList)232 Path (org.apache.hadoop.fs.Path)224 Test (org.junit.Test)212 InputStreamReader (java.io.InputStreamReader)193 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)189 XmlPullParser (org.xmlpull.v1.XmlPullParser)166 BufferedInputStream (java.io.BufferedInputStream)154 URL (java.net.URL)139 ParcelFileDescriptor (android.os.ParcelFileDescriptor)131 FileStatus (org.apache.hadoop.fs.FileStatus)131 Properties (java.util.Properties)129 HashMap (java.util.HashMap)120