Java Code Examples for com.hippo.unifile.UniFile#openInputStream()

The following examples show how to use com.hippo.unifile.UniFile#openInputStream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommonOperations.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
public static void ensureNoMediaFile(UniFile file) {
    if (null == file) {
        return;
    }

    UniFile noMedia = file.createFile(".nomedia");
    if (null == noMedia) {
        return;
    }

    InputStream is = null;
    try {
        is = noMedia.openInputStream();
    } catch (IOException e) {
        // Ignore
    } finally {
        IOUtils.closeQuietly(is);
    }
}
 
Example 2
Source File: CommonOperations.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
public static void ensureNoMediaFile(UniFile file) {
    if (null == file) {
        return;
    }

    UniFile noMedia = file.createFile(".nomedia");
    if (null == noMedia) {
        return;
    }

    InputStream is = null;
    try {
        is = noMedia.openInputStream();
    } catch (IOException e) {
        // Ignore
    } finally {
        IOUtils.closeQuietly(is);
    }
}
 
Example 3
Source File: SpiderInfo.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
public static SpiderInfo read(@Nullable UniFile file) {
    if (file == null) {
        return null;
    }

    InputStream is = null;
    try {
        is = file.openInputStream();
        return read(is);
    } catch (IOException e) {
        return null;
    } finally {
        IOUtils.closeQuietly(is);
    }
}
 
Example 4
Source File: DirGalleryProvider.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public UniFile save(int index, @NonNull UniFile dir, @NonNull String filename) {
    UniFile[] fileList = mFileList.get();
    if (null == fileList || index < 0 || index >= fileList.length) {
        return null;
    }

    UniFile src = fileList[index];
    String extension = FileUtils.getExtensionFromFilename(src.getName());
    UniFile dst = dir.subFile(null != extension ? filename + "." + extension : filename);
    if (null == dst) {
        return null;
    }

    InputStream is = null;
    OutputStream os = null;
    try {
        is = src.openInputStream();
        os = dst.openOutputStream();
        IOUtils.copy(is, os);
        return dst;
    } catch (IOException e) {
        return null;
    } finally {
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(os);
    }
}
 
Example 5
Source File: RestoreDownloadPreference.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
private RestoreItem getRestoreItem(UniFile file) {
    if (null == file || !file.isDirectory()) {
        return null;
    }
    UniFile siFile = file.findFile(SpiderQueen.SPIDER_INFO_FILENAME);
    if (null == siFile) {
        return null;
    }

    InputStream is = null;
    try {
        is = siFile.openInputStream();
        SpiderInfo spiderInfo = SpiderInfo.read(is);
        if (spiderInfo == null) {
            return null;
        }
        String gid = spiderInfo.gid;
        if (mManager.containDownloadInfo(gid)) {
            return null;
        }
        String token = spiderInfo.token;
        RestoreItem restoreItem = new RestoreItem();
        restoreItem.gid = gid;
        restoreItem.token = token;
        restoreItem.dirname = file.getName();
        return restoreItem;
    } catch (IOException e) {
        return null;
    } finally {
        IOUtils.closeQuietly(is);
    }
}
 
Example 6
Source File: SpiderInfo.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public static SpiderInfo read(@Nullable UniFile file) {
    if (file == null) {
        return null;
    }

    InputStream is = null;
    try {
        is = file.openInputStream();
        return read(is);
    } catch (IOException e) {
        return null;
    } finally {
        IOUtils.closeQuietly(is);
    }
}
 
Example 7
Source File: DirGalleryProvider.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public UniFile save(int index, @NonNull UniFile dir, @NonNull String filename) {
    UniFile[] fileList = mFileList.get();
    if (null == fileList || index < 0 || index >= fileList.length) {
        return null;
    }

    UniFile src = fileList[index];
    String extension = FileUtils.getExtensionFromFilename(src.getName());
    UniFile dst = dir.subFile(null != extension ? filename + "." + extension : filename);
    if (null == dst) {
        return null;
    }

    InputStream is = null;
    OutputStream os = null;
    try {
        is = src.openInputStream();
        os = dst.openOutputStream();
        IOUtils.copy(is, os);
        return dst;
    } catch (IOException e) {
        return null;
    } finally {
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(os);
    }
}
 
Example 8
Source File: RestoreDownloadPreference.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
private RestoreItem getRestoreItem(UniFile file) {
    if (null == file || !file.isDirectory()) {
        return null;
    }
    UniFile siFile = file.findFile(SpiderQueen.SPIDER_INFO_FILENAME);
    if (null == siFile) {
        return null;
    }

    InputStream is = null;
    try {
        is = siFile.openInputStream();
        SpiderInfo spiderInfo = SpiderInfo.read(is);
        if (spiderInfo == null) {
            return null;
        }
        long gid = spiderInfo.gid;
        if (mManager.containDownloadInfo(gid)) {
            return null;
        }
        String token = spiderInfo.token;
        RestoreItem restoreItem = new RestoreItem();
        restoreItem.gid = gid;
        restoreItem.token = token;
        restoreItem.dirname = file.getName();
        return restoreItem;
    } catch (IOException e) {
        return null;
    } finally {
        IOUtils.closeQuietly(is);
    }
}