Example usage for java.util.zip ZipFile OPEN_DELETE

List of usage examples for java.util.zip ZipFile OPEN_DELETE

Introduction

In this page you can find the example usage for java.util.zip ZipFile OPEN_DELETE.

Prototype

int OPEN_DELETE

To view the source code for java.util.zip ZipFile OPEN_DELETE.

Click Source Link

Document

Mode flag to open a zip file and mark it for deletion.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipFile zipFile = new ZipFile(new File("testfile.zip"), ZipFile.OPEN_DELETE);

    Enumeration zipEntries = zipFile.entries();

    while (zipEntries.hasMoreElements()) {
        System.out.println(((ZipEntry) zipEntries.nextElement()).getName());
    }/*  w ww . j a v  a 2 s. c  om*/
}

From source file:com.ichi2.libanki.sync.RemoteMediaServer.java

/**
 * args: files//from w  w  w .  j a v  a  2  s  . c o m
 * <br>
 * This method returns a ZipFile with the OPEN_DELETE flag, ensuring that the file on disk will
 * be automatically deleted when the stream is closed.
 */
public ZipFile downloadFiles(List<String> top) throws UnknownHttpResponseException {
    try {
        HttpResponse resp;
        resp = super.req("downloadFiles",
                super.getInputStream(Utils.jsonToString(new JSONObject().put("files", new JSONArray(top)))));
        String zipPath = mCol.getPath().replaceFirst("collection\\.anki2$", "tmpSyncFromServer.zip");
        // retrieve contents and save to file on disk:
        super.writeToFile(resp.getEntity().getContent(), zipPath);
        return new ZipFile(new File(zipPath), ZipFile.OPEN_READ | ZipFile.OPEN_DELETE);
    } catch (JSONException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        Timber.e(e, "Failed to download requested media files");
        throw new RuntimeException(e);
    }
}