本文整理汇总了Java中android.system.Os.close方法的典型用法代码示例。如果您正苦于以下问题:Java Os.close方法的具体用法?Java Os.close怎么用?Java Os.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.system.Os
的用法示例。
在下文中一共展示了Os.close方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stop
import android.system.Os; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void stop() {
try {
if (mInterruptFd != null) {
Os.close(mInterruptFd);
}
if (mBlockFd != null) {
Os.close(mBlockFd);
}
if (this.descriptor != null) {
this.descriptor.close();
this.descriptor = null;
}
} catch (Exception ignored) {
}
}
示例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: run
import android.system.Os; //导入方法依赖的package包/类
@Override
public void run() {
final byte[] temp = new byte[8192];
try {
while (read(mServer, temp, 0, MSG_LENGTH) == MSG_LENGTH) {
final int cmd = FileUtils.peekInt(temp, 0, ByteOrder.BIG_ENDIAN);
if (cmd == CMD_WRITE) {
// Shuttle data into local file
int len = FileUtils.peekInt(temp, 4, ByteOrder.BIG_ENDIAN);
while (len > 0) {
int n = read(mServer, temp, 0, Math.min(temp.length, len));
if (n == -1) {
throw new IOException(
"Unexpected EOF; still expected " + len + " bytes");
}
write(mTarget, temp, 0, n);
len -= n;
}
} else if (cmd == CMD_FSYNC) {
// Sync and echo back to confirm
Os.fsync(mTarget);
write(mServer, temp, 0, MSG_LENGTH);
} else if (cmd == CMD_CLOSE) {
// Close and echo back to confirm
Os.fsync(mTarget);
Os.close(mTarget);
mClosed = true;
write(mServer, temp, 0, MSG_LENGTH);
break;
}
}
} catch (ErrnoException | IOException e) {
Log.wtf(TAG, "Failed during bridge", e);
} finally {
forceClose();
}
}
示例4: closeQuietly
import android.system.Os; //导入方法依赖的package包/类
public static void closeQuietly(FileDescriptor fd) {
if (fd != null && fd.valid()) {
try {
Os.close(fd);
} catch (ErrnoException e) {
e.printStackTrace();
}
}
}
示例5: closeOrWarn
import android.system.Os; //导入方法依赖的package包/类
public static FileDescriptor closeOrWarn(FileDescriptor fd, String tag, String message) {
try {
if (fd != null)
Os.close(fd);
} catch (ErrnoException e) {
Log.e(tag, "closeOrWarn: " + message, e);
} finally {
return null;
}
}
示例6: closeDescriptor
import android.system.Os; //导入方法依赖的package包/类
@TargetApi(21)
static void closeDescriptor(FileDescriptor descriptor) {
if (descriptor != null)
try { Os.close(descriptor); } catch (Exception ignore) { /* TODO */ }
}