本文整理匯總了Java中android.os.ParcelFileDescriptor.AutoCloseOutputStream方法的典型用法代碼示例。如果您正苦於以下問題:Java ParcelFileDescriptor.AutoCloseOutputStream方法的具體用法?Java ParcelFileDescriptor.AutoCloseOutputStream怎麽用?Java ParcelFileDescriptor.AutoCloseOutputStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.os.ParcelFileDescriptor
的用法示例。
在下文中一共展示了ParcelFileDescriptor.AutoCloseOutputStream方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: pipeFrom
import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
public static ParcelFileDescriptor pipeFrom(InputStream inputStream)
throws IOException {
final ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
final OutputStream output = new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]);
new TransferThread(inputStream, output).start();
return pipe[0];
}
示例2: createForParcelFileDescriptor
import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
/**
* Creates a DocumentsArchive instance for opening, browsing and accessing
* documents within the archive passed as a file descriptor.
*
* <p>Note, that this method should be used only if the document does not exist
* on the local storage. A snapshot file will be created, which may be slower
* and consume significant resources, in contrast to using
* {@see createForLocalFile(Context, File, String, char, Uri}.
*
* @param context Context of the provider.
* @param descriptor File descriptor for the archive's contents.
* @param documentId ID of the archive document.
* @param idDelimiter Delimiter for constructing IDs of documents within the archive.
* The delimiter must never be used for IDs of other documents.
* @param Uri notificationUri Uri for notifying that the archive file has changed.
* @see createForLocalFile(Context, File, String, char, Uri)
*/
public static DocumentArchive createForParcelFileDescriptor(
Context context, ParcelFileDescriptor descriptor, String documentId,
char idDelimiter, @Nullable Uri notificationUri)
throws IOException {
File snapshotFile = null;
try {
// Create a copy of the archive, as ZipFile doesn't operate on streams.
// Moreover, ZipInputStream would be inefficient for large files on
// pipes.
snapshotFile = File.createTempFile("android.support.provider.snapshot{",
"}.zip", context.getCacheDir());
try {
final FileOutputStream outputStream =
new ParcelFileDescriptor.AutoCloseOutputStream(
ParcelFileDescriptor.open(
snapshotFile, ParcelFileDescriptor.MODE_WRITE_ONLY));
final ParcelFileDescriptor.AutoCloseInputStream inputStream =
new ParcelFileDescriptor.AutoCloseInputStream(descriptor);
final byte[] buffer = new byte[32 * 1024];
int bytes;
while ((bytes = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytes);
}
outputStream.flush();
return new DocumentArchive(context, snapshotFile, documentId, idDelimiter,
notificationUri);
} catch (Exception e){
CrashReportingManager.logException(e);
return null;
}
} finally {
// On UNIX the file will be still available for processes which opened it, even
// after deleting it. Remove it ASAP, as it won't be used by anyone else.
if (snapshotFile != null) {
snapshotFile.delete();
}
}
}
示例3: NativePipe
import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
public NativePipe() {
try {
ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
inputStream = new ParcelFileDescriptor.AutoCloseInputStream(pipe[0]) {
private boolean closed = false;
@Override
public void close() throws IOException {
if (closed) return;
closed = true;
super.close();
outputStream.close();
}
};
outputStream = new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]) {
private boolean closed = false;
@Override
public void close() throws IOException {
if (closed) return;
closed = true;
super.close();
inputStream.close();
}
};
} catch (IOException e) {
throw new RuntimeException(e);
}
}