• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java IoUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中libcore.io.IoUtils的典型用法代码示例。如果您正苦于以下问题:Java IoUtils类的具体用法?Java IoUtils怎么用?Java IoUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IoUtils类属于libcore.io包,在下文中一共展示了IoUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getEligiblePackages

import libcore.io.IoUtils; //导入依赖的package包/类
private List<String> getEligiblePackages(Uri contentUri, Activity context) throws IOException {
    List<String> results = new LinkedList<>();

    ParcelFileDescriptor fileDescriptor = context.getContentResolver().openFileDescriptor(contentUri, "r");
    FileInputStream fileInputStream = new FileInputStream(fileDescriptor.getFileDescriptor());
    ZipInputStream inputStream = new ZipInputStream(fileInputStream);

    ZipEntry zipEntry;
    while ((zipEntry = inputStream.getNextEntry()) != null) {
        String zipEntryPath = zipEntry.getName();

        if (zipEntryPath.startsWith(ContentProviderBackupConfigurationBuilder.DEFAULT_FULL_BACKUP_DIRECTORY)) {
            String fileName = new File(zipEntryPath).getName();
            results.add(fileName);
        }

        inputStream.closeEntry();
    }

    IoUtils.closeQuietly(inputStream);
    IoUtils.closeQuietly(fileDescriptor.getFileDescriptor());
    return results;
}
 
开发者ID:stevesoltys,项目名称:backup,代码行数:24,代码来源:RestoreBackupActivityController.java


示例2: test_SSL_do_handshake_client_timeout

import libcore.io.IoUtils; //导入依赖的package包/类
@Test
public void test_SSL_do_handshake_client_timeout() throws Exception {
    // client timeout
    final ServerSocket listener = newServerSocket();
    Socket serverSocket = null;
    try {
        Hooks cHooks = new Hooks();
        Hooks sHooks = new ServerHooks(getServerPrivateKey(), getEncodedServerCertificates());
        Future<TestSSLHandshakeCallbacks> client =
                handshake(listener, 1, true, cHooks, null, null);
        Future<TestSSLHandshakeCallbacks> server =
                handshake(listener, -1, false, sHooks, null, null);
        serverSocket = server.get(TIMEOUT_SECONDS, TimeUnit.SECONDS).getSocket();
        client.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
        fail();
    } catch (ExecutionException expected) {
        assertEquals(SocketTimeoutException.class, expected.getCause().getClass());
    } finally {
        // Manually close peer socket when testing timeout
        IoUtils.closeQuietly(serverSocket);
    }
}
 
开发者ID:google,项目名称:conscrypt,代码行数:23,代码来源:NativeCryptoTest.java


示例3: test_SSL_do_handshake_server_timeout

import libcore.io.IoUtils; //导入依赖的package包/类
@Test
public void test_SSL_do_handshake_server_timeout() throws Exception {
    // server timeout
    final ServerSocket listener = newServerSocket();
    Socket clientSocket = null;
    try {
        Hooks cHooks = new Hooks();
        Hooks sHooks = new ServerHooks(getServerPrivateKey(), getEncodedServerCertificates());
        Future<TestSSLHandshakeCallbacks> client =
                handshake(listener, -1, true, cHooks, null, null);
        Future<TestSSLHandshakeCallbacks> server =
                handshake(listener, 1, false, sHooks, null, null);
        clientSocket = client.get(TIMEOUT_SECONDS, TimeUnit.SECONDS).getSocket();
        server.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
        fail();
    } catch (ExecutionException expected) {
        assertEquals(SocketTimeoutException.class, expected.getCause().getClass());
    } finally {
        // Manually close peer socket when testing timeout
        IoUtils.closeQuietly(clientSocket);
    }
}
 
开发者ID:google,项目名称:conscrypt,代码行数:23,代码来源:NativeCryptoTest.java


示例4: format

import libcore.io.IoUtils; //导入依赖的package包/类
/**
 * Converts a {@link LogRecord} object into a human readable string
 * representation.
 *
 * @param r
 *            the log record to be formatted into a string.
 * @return the formatted string.
 */
@Override
public String format(LogRecord r) {
    StringBuilder sb = new StringBuilder();
    sb.append(MessageFormat.format("{0, date} {0, time} ",
            new Object[] { new Date(r.getMillis()) }));
    sb.append(r.getSourceClassName()).append(" ");
    sb.append(r.getSourceMethodName()).append(System.lineSeparator());
    sb.append(r.getLevel().getName()).append(": ");
    sb.append(formatMessage(r)).append(System.lineSeparator());
    if (r.getThrown() != null) {
        sb.append("Throwable occurred: ");
        Throwable t = r.getThrown();
        PrintWriter pw = null;
        try {
            StringWriter sw = new StringWriter();
            pw = new PrintWriter(sw);
            t.printStackTrace(pw);
            sb.append(sw.toString());
        } finally {
            IoUtils.closeQuietly(pw);
        }
    }
    return sb.toString();
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:33,代码来源:SimpleFormatter.java


示例5: Scanner

import libcore.io.IoUtils; //导入依赖的package包/类
/**
 * Creates a {@code Scanner} with the specified {@code File} as input. The specified charset
 * is applied when reading the file.
 *
 * @param src
 *            the file to be scanned.
 * @param charsetName
 *            the name of the encoding type of the file.
 * @throws FileNotFoundException
 *             if the specified file does not exist.
 * @throws IllegalArgumentException
 *             if the specified coding does not exist.
 */
public Scanner(File src, String charsetName) throws FileNotFoundException {
    if (src == null) {
        throw new NullPointerException("src == null");
    }
    FileInputStream fis = new FileInputStream(src);
    if (charsetName == null) {
        throw new IllegalArgumentException("charsetName == null");
    }

    InputStreamReader streamReader;
    try {
        streamReader = new InputStreamReader(fis, charsetName);
    } catch (UnsupportedEncodingException e) {
        IoUtils.closeQuietly(fis);
        throw new IllegalArgumentException(e.getMessage());
    }
    initialize(streamReader);
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:32,代码来源:Scanner.java


示例6: SelectorImpl

import libcore.io.IoUtils; //导入依赖的package包/类
public SelectorImpl(SelectorProvider selectorProvider) throws IOException {
    super(selectorProvider);

    /*
     * Create a pipe to trigger wakeup. We can't use a NIO pipe because it
     * would be closed if the selecting thread is interrupted. Also
     * configure the pipe so we can fully drain it without blocking.
     */
    try {
        FileDescriptor[] pipeFds = Libcore.os.pipe();
        wakeupIn = pipeFds[0];
        wakeupOut = pipeFds[1];
        IoUtils.setBlocking(wakeupIn, false);
        pollFds.add(new StructPollfd());
        setPollFd(0, wakeupIn, POLLIN, null);
    } catch (ErrnoException errnoException) {
        throw errnoException.rethrowAsIOException();
    }
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:20,代码来源:SelectorImpl.java


示例7: 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


示例8: 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


示例9: 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


示例10: 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


示例11: install

import libcore.io.IoUtils; //导入依赖的package包/类
/***
 * Creates a new HTTP response cache and {@link ResponseCache#setDefault
 * sets it} as the system default cache.
 *
 * @param directory the directory to hold cache data.
 * @param maxSize the maximum size of the cache in bytes.
 * @return the newly-installed cache
 * @throws IOException if {@code directory} cannot be used for this cache.
 *     Most applications should respond to this exception by logging a
 *     warning.
 */
public static HttpResponseCache install(File directory, long maxSize) throws IOException {
    HttpResponseCache installed = getInstalled();
    if (installed != null) {
        // don't close and reopen if an equivalent cache is already installed
        DiskLruCache installedCache = installed.delegate.getCache();
        if (installedCache.getDirectory().equals(directory)
                && installedCache.getMaxSize() == maxSize
                && !installedCache.isClosed()) {
            return installed;
        } else {
            IoUtils.closeQuietly(installed);
        }
    }

    HttpResponseCache result = new HttpResponseCache(directory, maxSize);
    ResponseCache.setDefault(result);
    HttpsURLConnection.setDefaultHostnameVerifier(new DefaultHostnameVerifier());
    if(!calledSetURLStreamHandlerFactory) {
        // The stream handler factory can only be set once, so don't set it again if it's already been set
        // This can happen if the application calls install() then delete() then install() again
        calledSetURLStreamHandlerFactory = true;
        URL.setURLStreamHandlerFactory(new URLStreamHandlerFactoryImpl());
    }
    return result;
}
 
开发者ID:Mobideck,项目名称:appdeck-android,代码行数:37,代码来源:HttpResponseCache.java


示例12: queryDocument

import libcore.io.IoUtils; //导入依赖的package包/类
@Override
public Cursor queryDocument(String docId, String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));

    if (DOC_ID_ROOT.equals(docId)) {
        includeDefaultDocument(result);
    } else {
        // Delegate to real provider
        final long token = Binder.clearCallingIdentity();
        Cursor cursor = null;
        try {
            cursor = mDm.query(new Query().setFilterById(Long.parseLong(docId)));
            copyNotificationUri(result, cursor);
            if (cursor.moveToFirst()) {
                includeTransferFromCursor(result, cursor);
            }
        } finally {
            IoUtils.closeQuietly(cursor);
            Binder.restoreCallingIdentity(token);
        }
    }
    return result;
}
 
开发者ID:StoryMaker,项目名称:SecureShareLib,代码行数:24,代码来源:TransferStorageProvider.java


示例13: queryChildDocuments

import libcore.io.IoUtils; //导入依赖的package包/类
@Override
public Cursor queryChildDocuments(String docId, String[] projection, String sortOrder)
        throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));

    // Delegate to real provider
    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        cursor = mDm.query(new DownloadManager.Query().setOnlyIncludeVisibleInDownloadsUi(true)
                .setFilterByStatus(DownloadManager.STATUS_SUCCESSFUL));
        copyNotificationUri(result, cursor);
        while (cursor.moveToNext()) {
            includeTransferFromCursor(result, cursor);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
 
开发者ID:StoryMaker,项目名称:SecureShareLib,代码行数:22,代码来源:TransferStorageProvider.java


示例14: queryChildDocumentsForManage

import libcore.io.IoUtils; //导入依赖的package包/类
@Override
public Cursor queryChildDocumentsForManage(
        String parentDocumentId, String[] projection, String sortOrder)
        throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));

    // Delegate to real provider
    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        cursor = mDm.query(
                new DownloadManager.Query().setOnlyIncludeVisibleInDownloadsUi(true));
        copyNotificationUri(result, cursor);
        while (cursor.moveToNext()) {
            includeTransferFromCursor(result, cursor);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
 
开发者ID:StoryMaker,项目名称:SecureShareLib,代码行数:23,代码来源:TransferStorageProvider.java


示例15: clearBackupState

import libcore.io.IoUtils; //导入依赖的package包/类
private int clearBackupState(boolean closeFile) {

        if (backupState == null) {
            return TRANSPORT_OK;
        }

        try {
            IoUtils.closeQuietly(backupState.getInputFileDescriptor());
            backupState.setInputFileDescriptor(null);

            ZipOutputStream outputStream = backupState.getOutputStream();

            if (outputStream != null) {
                outputStream.closeEntry();
            }

            if (backupState.getPackageIndex() == configuration.getPackageCount() || closeFile) {
                if (outputStream != null) {
                    outputStream.finish();
                    outputStream.close();
                }

                IoUtils.closeQuietly(backupState.getOutputFileDescriptor());
                backupState = null;
            }

        } catch (IOException ex) {
            Log.e(TAG, "Error cancelling full backup: ", ex);
            return TRANSPORT_ERROR;
        }

        return TRANSPORT_OK;
    }
 
开发者ID:stevesoltys,项目名称:backup,代码行数:34,代码来源:ContentProviderBackupComponent.java


示例16: containsPackageFile

import libcore.io.IoUtils; //导入依赖的package包/类
private boolean containsPackageFile(String fileName) throws IOException, InvalidKeyException,
        InvalidAlgorithmParameterException {
    ParcelFileDescriptor inputFileDescriptor = buildInputFileDescriptor();
    ZipInputStream inputStream = buildInputStream(inputFileDescriptor);

    Optional<ZipEntry> zipEntry = seekToEntry(inputStream, fileName);
    IoUtils.closeQuietly(inputFileDescriptor);
    IoUtils.closeQuietly(inputStream);
    return zipEntry.isPresent();
}
 
开发者ID:stevesoltys,项目名称:backup,代码行数:11,代码来源:ContentProviderRestoreComponent.java


示例17: transferIncrementalRestoreData

import libcore.io.IoUtils; //导入依赖的package包/类
private int transferIncrementalRestoreData(String packageName, ParcelFileDescriptor outputFileDescriptor)
        throws IOException, InvalidAlgorithmParameterException, InvalidKeyException {

    ParcelFileDescriptor inputFileDescriptor = buildInputFileDescriptor();
    ZipInputStream inputStream = buildInputStream(inputFileDescriptor);
    BackupDataOutput backupDataOutput = new BackupDataOutput(outputFileDescriptor.getFileDescriptor());

    Optional<ZipEntry> zipEntryOptional = seekToEntry(inputStream,
            configuration.getIncrementalBackupDirectory() + packageName);
    while (zipEntryOptional.isPresent()) {
        String fileName = new File(zipEntryOptional.get().getName()).getName();
        String blobKey = new String(Base64.decode(fileName, Base64.DEFAULT));

        byte[] backupData = Streams.readFullyNoClose(inputStream);
        backupDataOutput.writeEntityHeader(blobKey, backupData.length);
        backupDataOutput.writeEntityData(backupData, backupData.length);
        inputStream.closeEntry();

        zipEntryOptional = seekToEntry(inputStream, configuration.getIncrementalBackupDirectory() + packageName);
    }

    IoUtils.closeQuietly(inputFileDescriptor);
    IoUtils.closeQuietly(outputFileDescriptor);
    return TRANSPORT_OK;
}
 
开发者ID:stevesoltys,项目名称:backup,代码行数:26,代码来源:ContentProviderRestoreComponent.java


示例18: getNextFullRestoreDataChunk

import libcore.io.IoUtils; //导入依赖的package包/类
@Override
public int getNextFullRestoreDataChunk(ParcelFileDescriptor outputFileDescriptor) {
    Preconditions.checkState(restoreState.getRestoreType() == TYPE_FULL_STREAM,
            "Asked for full restore data for non-stream package");

    ParcelFileDescriptor inputFileDescriptor = restoreState.getInputFileDescriptor();

    if (inputFileDescriptor == null) {
        String name = restoreState.getPackages()[restoreState.getPackageIndex()].packageName;

        try {
            inputFileDescriptor = buildInputFileDescriptor();
            restoreState.setInputFileDescriptor(inputFileDescriptor);

            ZipInputStream inputStream = buildInputStream(inputFileDescriptor);
            restoreState.setInputStream(inputStream);

            if (!seekToEntry(inputStream, configuration.getFullBackupDirectory() + name).isPresent()) {
                IoUtils.closeQuietly(inputFileDescriptor);
                IoUtils.closeQuietly(outputFileDescriptor);
                return TRANSPORT_PACKAGE_REJECTED;
            }

        } catch (IOException ex) {
            Log.e(TAG, "Unable to read archive for " + name, ex);

            IoUtils.closeQuietly(inputFileDescriptor);
            IoUtils.closeQuietly(outputFileDescriptor);
            return TRANSPORT_PACKAGE_REJECTED;
        }
    }

    return transferFullRestoreData(outputFileDescriptor);
}
 
开发者ID:stevesoltys,项目名称:backup,代码行数:35,代码来源:ContentProviderRestoreComponent.java


示例19: transferFullRestoreData

import libcore.io.IoUtils; //导入依赖的package包/类
private int transferFullRestoreData(ParcelFileDescriptor outputFileDescriptor) {
    ZipInputStream inputStream = restoreState.getInputStream();
    OutputStream outputStream = new FileOutputStream(outputFileDescriptor.getFileDescriptor());

    byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
    int bytesRead = NO_MORE_DATA;

    try {
        bytesRead = inputStream.read(buffer);

        if (bytesRead <= 0) {
            bytesRead = NO_MORE_DATA;
        } else {
            outputStream.write(buffer, 0, bytesRead);
        }

    } catch (Exception e) {
        Log.e(TAG, "Exception while streaming restore data: ", e);
        return TRANSPORT_ERROR;

    } finally {
        if (bytesRead == NO_MORE_DATA) {

            if (restoreState.getInputFileDescriptor() != null) {
                IoUtils.closeQuietly(restoreState.getInputFileDescriptor());
            }

            restoreState.setInputFileDescriptor(null);
            restoreState.setInputStream(null);
        }

        IoUtils.closeQuietly(outputFileDescriptor);
    }

    return bytesRead;
}
 
开发者ID:stevesoltys,项目名称:backup,代码行数:37,代码来源:ContentProviderRestoreComponent.java


示例20: resetFullRestoreState

import libcore.io.IoUtils; //导入依赖的package包/类
private void resetFullRestoreState() {
    Preconditions.checkNotNull(restoreState);
    Preconditions.checkState(restoreState.getRestoreType() == TYPE_FULL_STREAM);

    IoUtils.closeQuietly(restoreState.getInputFileDescriptor());
    restoreState = null;
}
 
开发者ID:stevesoltys,项目名称:backup,代码行数:8,代码来源:ContentProviderRestoreComponent.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IdentityManager类代码示例发布时间:2022-05-22
下一篇:
Java FluentCaseInsensitiveStringsMap类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap