Java Code Examples for com.hippo.unifile.UniFile#openOutputStream()
The following examples show how to use
com.hippo.unifile.UniFile#openOutputStream() .
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: SpiderQueen.java From MHViewer with Apache License 2.0 | 6 votes |
public boolean save(int index, @NonNull UniFile file) { int state = getPageState(index); if (STATE_FINISHED != state) { return false; } InputStreamPipe pipe = mSpiderDen.openInputStreamPipe(index); if (null == pipe) { return false; } OutputStream os = null; try { os = file.openOutputStream(); pipe.obtain(); IOUtils.copy(pipe.open(), os); return true; } catch (IOException e) { return false; } finally { pipe.close(); pipe.release(); IOUtils.closeQuietly(os); } }
Example 2
Source File: DirGalleryProvider.java From MHViewer with Apache License 2.0 | 6 votes |
@Override public boolean save(int index, @NonNull UniFile file) { UniFile[] fileList = mFileList.get(); if (null == fileList || index < 0 || index >= fileList.length) { return false; } InputStream is = null; OutputStream os = null; try { is = fileList[index].openInputStream(); os = file.openOutputStream(); IOUtils.copy(is, os); return true; } catch (IOException e) { return false; } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); } }
Example 3
Source File: SpiderQueen.java From EhViewer with Apache License 2.0 | 6 votes |
public boolean save(int index, @NonNull UniFile file) { int state = getPageState(index); if (STATE_FINISHED != state) { return false; } InputStreamPipe pipe = mSpiderDen.openInputStreamPipe(index); if (null == pipe) { return false; } OutputStream os = null; try { os = file.openOutputStream(); pipe.obtain(); IOUtils.copy(pipe.open(), os); return true; } catch (IOException e) { return false; } finally { pipe.close(); pipe.release(); IOUtils.closeQuietly(os); } }
Example 4
Source File: DirGalleryProvider.java From EhViewer with Apache License 2.0 | 6 votes |
@Override public boolean save(int index, @NonNull UniFile file) { UniFile[] fileList = mFileList.get(); if (null == fileList || index < 0 || index >= fileList.length) { return false; } InputStream is = null; OutputStream os = null; try { is = fileList[index].openInputStream(); os = file.openOutputStream(); IOUtils.copy(is, os); return true; } catch (IOException e) { return false; } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); } }
Example 5
Source File: SpiderQueen.java From MHViewer with Apache License 2.0 | 5 votes |
@Nullable public UniFile save(int index, @NonNull UniFile dir, @NonNull String filename) { int state = getPageState(index); if (STATE_FINISHED != state) { return null; } InputStreamPipe pipe = mSpiderDen.openInputStreamPipe(index); if (null == pipe) { return null; } OutputStream os = null; try { pipe.obtain(); // Get dst file BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(pipe.open(), null, options); pipe.close(); String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(options.outMimeType); UniFile dst = dir.subFile(null != extension ? filename + "." + extension : filename); if (null == dst) { return null; } // Copy os = dst.openOutputStream(); IOUtils.copy(pipe.open(), os); return dst; } catch (IOException e) { return null; } finally { pipe.close(); pipe.release(); IOUtils.closeQuietly(os); } }
Example 6
Source File: DirGalleryProvider.java From MHViewer with Apache License 2.0 | 5 votes |
@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 7
Source File: SpiderQueen.java From EhViewer with Apache License 2.0 | 5 votes |
@Nullable public UniFile save(int index, @NonNull UniFile dir, @NonNull String filename) { int state = getPageState(index); if (STATE_FINISHED != state) { return null; } InputStreamPipe pipe = mSpiderDen.openInputStreamPipe(index); if (null == pipe) { return null; } OutputStream os = null; try { pipe.obtain(); // Get dst file BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(pipe.open(), null, options); pipe.close(); String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(options.outMimeType); UniFile dst = dir.subFile(null != extension ? filename + "." + extension : filename); if (null == dst) { return null; } // Copy os = dst.openOutputStream(); IOUtils.copy(pipe.open(), os); return dst; } catch (IOException e) { return null; } finally { pipe.close(); pipe.release(); IOUtils.closeQuietly(os); } }
Example 8
Source File: DirGalleryProvider.java From EhViewer with Apache License 2.0 | 5 votes |
@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 9
Source File: SpiderDen.java From MHViewer with Apache License 2.0 | 4 votes |
private boolean copyFromCacheToDownloadDir(int index) { if (sCache == null) { return false; } UniFile dir = getDownloadDir(); if (dir == null) { return false; } // Find image file in cache String key = EhCacheKeyFactory.getImageKey(mGid, index); InputStreamPipe pipe = sCache.getInputStreamPipe(key); if (pipe == null) { return false; } OutputStream os = null; try { // Get extension String extension; BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; pipe.obtain(); BitmapFactory.decodeStream(pipe.open(), null, options); pipe.close(); extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(options.outMimeType); if (extension != null) { extension = '.' + extension; } else { return false; } // Fix extension extension = fixExtension(extension); // Copy from cache to download dir UniFile file = dir.createFile(generateImageFilename(index, extension)); if (file == null) { return false; } os = file.openOutputStream(); IOUtils.copy(pipe.open(), os); return true; } catch (IOException e) { return false; } finally { IOUtils.closeQuietly(os); pipe.close(); pipe.release(); } }
Example 10
Source File: GalleryActivity2.java From Nimingban with Apache License 2.0 | 4 votes |
@Override public boolean save(InputStream is, long length, String mediaType, ProgressNotify notify) { // Get extension and filename String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mediaType); if (!TextUtils.isEmpty(extension)) { mFilename = mName + '.' + extension; } else { mFilename = mName; } UniFile file = mDir.createFile(mFilename); if (file == null) { return false; } OutputStream os = null; try { os = file.openOutputStream(); final byte buffer[] = new byte[1024 * 4]; long receivedSize = 0; int bytesRead; while((bytesRead = is.read(buffer)) !=-1) { os.write(buffer, 0, bytesRead); receivedSize += bytesRead; if (length > 0) { notify.notifyProgress((long) bytesRead, receivedSize, length); } } os.flush(); IOUtils.closeQuietly(os); // Notify media scanner mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, file.getUri())); return true; } catch (IOException e) { IOUtils.closeQuietly(os); file.delete(); return false; } }
Example 11
Source File: SpiderDen.java From EhViewer with Apache License 2.0 | 4 votes |
private boolean copyFromCacheToDownloadDir(int index) { if (sCache == null) { return false; } UniFile dir = getDownloadDir(); if (dir == null) { return false; } // Find image file in cache String key = EhCacheKeyFactory.getImageKey(mGid, index); InputStreamPipe pipe = sCache.getInputStreamPipe(key); if (pipe == null) { return false; } OutputStream os = null; try { // Get extension String extension; BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; pipe.obtain(); BitmapFactory.decodeStream(pipe.open(), null, options); pipe.close(); extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(options.outMimeType); if (extension != null) { extension = '.' + extension; } else { return false; } // Fix extension extension = fixExtension(extension); // Copy from cache to download dir UniFile file = dir.createFile(generateImageFilename(index, extension)); if (file == null) { return false; } os = file.openOutputStream(); IOUtils.copy(pipe.open(), os); return true; } catch (IOException e) { return false; } finally { IOUtils.closeQuietly(os); pipe.close(); pipe.release(); } }