本文整理汇总了Java中libcore.io.IoUtils.close方法的典型用法代码示例。如果您正苦于以下问题:Java IoUtils.close方法的具体用法?Java IoUtils.close怎么用?Java IoUtils.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libcore.io.IoUtils
的用法示例。
在下文中一共展示了IoUtils.close方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createNewFile
import libcore.io.IoUtils; //导入方法依赖的package包/类
/**
* Creates a new, empty file on the file system according to the path
* information stored in this file. This method returns true if it creates
* a file, false if the file already existed. Note that it returns false
* even if the file is not a file (because it's a directory, say).
*
* <p>This method is not generally useful. For creating temporary files,
* use {@link #createTempFile} instead. For reading/writing files, use {@link FileInputStream},
* {@link FileOutputStream}, or {@link RandomAccessFile}, all of which can create files.
*
* <p>Note that this method does <i>not</i> throw {@code IOException} if the file
* already exists, even if it's not a regular file. Callers should always check the
* return value, and may additionally want to call {@link #isFile}.
*
* @return true if the file has been created, false if it
* already exists.
* @throws IOException if it's not possible to create the file.
*/
public boolean createNewFile() throws IOException {
if (0 == path.length()) {
throw new IOException("No such file or directory");
}
if (isDirectory()) { // true for paths like "dir/..", which can't be files.
throw new IOException("Cannot create: " + path);
}
FileDescriptor fd = null;
try {
// On Android, we don't want default permissions to allow global access.
fd = Libcore.os.open(path, O_RDWR | O_CREAT | O_EXCL, 0600);
return true;
} catch (ErrnoException errnoException) {
if (errnoException.errno == EEXIST) {
// The file already exists.
return false;
}
throw errnoException.rethrowAsIOException();
} finally {
IoUtils.close(fd); // TODO: should we suppress IOExceptions thrown here?
}
}
示例2: run
import libcore.io.IoUtils; //导入方法依赖的package包/类
@Override
public void run() {
try {
FileOutputStream fos = new FileOutputStream(mOutFd);
try {
byte[] buffer = new byte[TOTAL_SIZE];
for (int i = 0; i < buffer.length; ++i) {
buffer[i] = (byte) i;
}
fos.write(buffer);
} finally {
IoUtils.closeQuietly(fos);
IoUtils.close(mOutFd);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例3: close
import libcore.io.IoUtils; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
try {
super.close();
} finally {
synchronized (this) {
if (fd != null && fd.valid()) {
try {
IoUtils.close(fd);
} finally {
fd = null;
}
}
}
}
}
示例4: close
import libcore.io.IoUtils; //导入方法依赖的package包/类
/**
* Closes this stream. This implementation closes the underlying operating
* system resources allocated to represent this stream.
*
* @throws IOException
* if an error occurs attempting to close this stream.
*/
@Override
public void close() throws IOException {
if (fd == null) {
// if fd is null, then the underlying file is not opened, so nothing
// to close
return;
}
if (channel != null) {
synchronized (channel) {
if (channel.isOpen() && fd.descriptor >= 0) {
channel.close();
}
}
}
synchronized (this) {
if (fd.valid() && innerFD) {
IoUtils.close(fd);
}
}
}
示例5: implCloseSelector
import libcore.io.IoUtils; //导入方法依赖的package包/类
@Override protected void implCloseSelector() throws IOException {
wakeup();
synchronized (this) {
synchronized (unmodifiableKeys) {
synchronized (selectedKeys) {
IoUtils.close(wakeupIn);
IoUtils.close(wakeupOut);
doCancel();
for (SelectionKey sk : mutableKeys) {
deregister((AbstractSelectionKey) sk);
}
}
}
}
}
示例6: close
import libcore.io.IoUtils; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
guard.close();
synchronized (this) {
if (channel != null) {
channel.close();
}
if (shouldClose) {
IoUtils.close(fd);
} else {
// An owned fd has been invalidated by IoUtils.close, but
fd = new FileDescriptor();
}
}
}
示例7: close
import libcore.io.IoUtils; //导入方法依赖的package包/类
/**
* Closes this file.
*
* @throws IOException
* if an error occurs while closing this file.
*/
public void close() throws IOException {
guard.close();
synchronized (this) {
if (channel != null && channel.isOpen()) {
channel.close();
channel = null;
}
IoUtils.close(fd);
}
}
示例8: close
import libcore.io.IoUtils; //导入方法依赖的package包/类
/**
* Closes this stream.
*
* @throws IOException
* if an error occurs attempting to close this stream.
*/
@Override
public void close() throws IOException {
// BEGIN android-changed
synchronized (this) {
if (channel != null && channel.isOpen()) {
channel.close();
channel = null;
}
if (fd != null && fd.valid() && innerFD) {
IoUtils.close(fd);
}
}
// END android-changed
}
示例9: close
import libcore.io.IoUtils; //导入方法依赖的package包/类
/**
* Closes this file.
*
* @throws IOException
* if an error occurs while closing this file.
*/
public void close() throws IOException {
synchronized (this) {
if (channel != null && channel.isOpen()) {
channel.close();
channel = null;
}
if (fd != null && fd.valid()) {
IoUtils.close(fd);
}
}
}
示例10: close
import libcore.io.IoUtils; //导入方法依赖的package包/类
public void close() throws IOException {
IoUtils.close(fd);
}