本文整理汇总了Java中android.system.Os.open方法的典型用法代码示例。如果您正苦于以下问题:Java Os.open方法的具体用法?Java Os.open怎么用?Java Os.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.system.Os
的用法示例。
在下文中一共展示了Os.open方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openReadInternal
import android.system.Os; //导入方法依赖的package包/类
private ParcelFileDescriptor openReadInternal(String name) throws IOException {
assertPreparedAndNotSealed("openRead");
try {
if (!FileUtils.isValidExtFilename(name)) {
throw new IllegalArgumentException("Invalid name: " + name);
}
final File target = new File(resolveStageDir(), name);
final FileDescriptor targetFd = Os.open(target.getAbsolutePath(), O_RDONLY, 0);
return ParcelFileDescriptor.dup(targetFd);
} catch (ErrnoException e) {
throw new IOException(e);
}
}
示例2: copyFile
import android.system.Os; //导入方法依赖的package包/类
private void copyFile() throws IOException, ErrnoException {
try (InputStream in = assetManager.open(assetNameBuilder.toString(), AssetManager.ACCESS_BUFFER))
{
final FileDescriptor fd = Os.open(
directoryNameBuilder.toString(),
OsConstants.O_CREAT | OsConstants.O_TRUNC | OsConstants.O_WRONLY,
OsConstants.S_IROTH | OsConstants.S_IWUSR);
try (OutputStream out = new FileOutputStream(fd)) {
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
} finally {
Os.close(fd);
}
}
}
示例3: openWriteInternal
import android.system.Os; //导入方法依赖的package包/类
private ParcelFileDescriptor openWriteInternal(String name, long offsetBytes, long lengthBytes)
throws IOException {
// Quick sanity check of state, and allocate a pipe for ourselves. We
// then do heavy disk allocation outside the lock, but this open pipe
// will block any attempted install transitions.
final FileBridge bridge;
synchronized (mLock) {
assertPreparedAndNotSealed("openWrite");
bridge = new FileBridge();
mBridges.add(bridge);
}
try {
final File target = new File(resolveStageDir(), name);
// TODO: this should delegate to DCS so the system process avoids
// holding open FDs into containers.
final FileDescriptor targetFd = Os.open(target.getAbsolutePath(),
O_CREAT | O_WRONLY, 0644);
// If caller specified a total length, allocate it for them. Free up
// cache space to grow, if needed.
if (lengthBytes > 0) {
Os.posix_fallocate(targetFd, 0, lengthBytes);
}
if (offsetBytes > 0) {
Os.lseek(targetFd, offsetBytes, OsConstants.SEEK_SET);
}
bridge.setTargetFile(targetFd);
bridge.start();
return ParcelFileDescriptor.dup(bridge.getClientSocket());
} catch (ErrnoException e) {
throw new IOException(e);
}
}