当前位置: 首页>>代码示例>>Java>>正文


Java IoUtils.close方法代码示例

本文整理汇总了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?
    }
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:41,代码来源:File.java

示例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);
    }
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:19,代码来源:FileInputStreamTest.java

示例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;
                }
            }
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:17,代码来源:ProcessManager.java

示例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);
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:30,代码来源:FileOutputStream.java

示例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);
                }
            }
        }
    }
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:16,代码来源:SelectorImpl.java

示例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();
        }
    }
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:16,代码来源:FileInputStream.java

示例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);
    }
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:17,代码来源:RandomAccessFile.java

示例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
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:21,代码来源:FileInputStream.java

示例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);
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:18,代码来源:RandomAccessFile.java

示例10: close

import libcore.io.IoUtils; //导入方法依赖的package包/类
public void close() throws IOException {
    IoUtils.close(fd);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:4,代码来源:PipeImpl.java


注:本文中的libcore.io.IoUtils.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。