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


Java IoUtils.closeQuietly方法代码示例

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


在下文中一共展示了IoUtils.closeQuietly方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

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

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

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

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

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

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

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

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

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


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