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

The following examples show how to use com.hippo.unifile.UniFile#delete() . 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: SpiderDen.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
private boolean removeFromDownloadDir(int index) {
    UniFile dir = getDownloadDir();
    if (dir == null) {
        return false;
    }

    boolean result = false;
    for (int i = 0, n = GalleryProvider2.SUPPORT_IMAGE_EXTENSIONS.length; i < n; i++) {
        String filename = generateImageFilename(index, GalleryProvider2.SUPPORT_IMAGE_EXTENSIONS[i]);
        UniFile file = dir.subFile(filename);
        if (file != null) {
            result |= file.delete();
        }
    }
    return result;
}
 
Example 2
Source File: CleanRedundancyPreference.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
private boolean clearFile(UniFile file) {
    String name = file.getName();
    if (name == null) {
        return false;
    }
    int index = name.indexOf('-');
    if (index >= 0) {
        name = name.substring(0, index);
    }
    String gid = name;
    if (mManager.containDownloadInfo(gid)) {
        return false;
    }
    file.delete();
    return true;
}
 
Example 3
Source File: SpiderDen.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
private boolean removeFromDownloadDir(int index) {
    UniFile dir = getDownloadDir();
    if (dir == null) {
        return false;
    }

    boolean result = false;
    for (int i = 0, n = GalleryProvider2.SUPPORT_IMAGE_EXTENSIONS.length; i < n; i++) {
        String filename = generateImageFilename(index, GalleryProvider2.SUPPORT_IMAGE_EXTENSIONS[i]);
        UniFile file = dir.subFile(filename);
        if (file != null) {
            result |= file.delete();
        }
    }
    return result;
}
 
Example 4
Source File: CleanRedundancyPreference.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
private boolean clearFile(UniFile file) {
    String name = file.getName();
    if (name == null) {
        return false;
    }
    int index = name.indexOf('-');
    if (index >= 0) {
        name = name.substring(0, index);
    }
    long gid = NumberUtils.parseLongSafely(name, -1L);
    if (-1L == gid) {
        return false;
    }
    if (mManager.containDownloadInfo(gid)) {
        return false;
    }
    file.delete();
    return true;
}
 
Example 5
Source File: CommonOperations.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
public static void removeNoMediaFile(UniFile file) {
    if (null == file) {
        return;
    }

    UniFile noMedia = file.subFile(".nomedia");
    if (null != noMedia && noMedia.isFile()) {
        noMedia.delete();
    }
}
 
Example 6
Source File: GalleryActivity2.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
@Override
public void reloadCurrentImage() {
    GalleryHolder holder = getPagerHolder(0);
    if (holder == null) {
        return;
    }

    // Unload
    holder.galleryPage.unload();

    // Remove in cache
    NMBApplication.getConaco(GalleryActivity2.this).getBeerBelly().remove(mImage);

    // Remove all in save location
    UniFile dir = Settings.getImageSaveLocation();
    if (dir != null) {
        String name = mSite.getReadableName(GalleryActivity2.this) + "-" + mId;
        for (String extension : IMAGE_EXTENSIONS) {
            UniFile file = dir.findFile(name + '.' + extension);
            if (file != null) {
                file.delete();
            }
        }
    }

    // Load
    bindPagerHolder(holder, 0);
}
 
Example 7
Source File: CommonOperations.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public static void removeNoMediaFile(UniFile file) {
    if (null == file) {
        return;
    }

    UniFile noMedia = file.subFile(".nomedia");
    if (null != noMedia && noMedia.isFile()) {
        noMedia.delete();
    }
}
 
Example 8
Source File: GalleryActivity2.java    From Nimingban with Apache License 2.0 4 votes vote down vote up
@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;
    }
}