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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations